@ -173,130 +173,110 @@ func Test_endpoint_maybeProbeUDPLifetimeLocked(t *testing.T) {
wantMaybe bool
} {
{
"nil probeUDPLifetime" ,
higher,
& lower ,
func ( ) * probeUDPLifetime {
name : "nil probeUDPLifetime" ,
localDisco: higher,
remoteDisco : & lower ,
probeUDPLifetimeFn : func ( ) * probeUDPLifetime {
return nil
} ,
addr ,
func ( lifetime * probeUDPLifetime ) time . Duration {
return 0
} ,
false ,
bestAddr : addr ,
} ,
{
"local higher disco key" ,
higher ,
& lower ,
newProbeUDPLifetime ,
addr ,
func ( lifetime * probeUDPLifetime ) time . Duration {
return 0
} ,
false ,
name : "local higher disco key" ,
localDisco : higher ,
remoteDisco : & lower ,
probeUDPLifetimeFn : newProbeUDPLifetime ,
bestAddr : addr ,
} ,
{
"remote no disco key" ,
higher ,
nil ,
newProbeUDPLifetime ,
addr ,
func ( lifetime * probeUDPLifetime ) time . Duration {
return 0
} ,
false ,
name : "remote no disco key" ,
localDisco : higher ,
remoteDisco : nil ,
probeUDPLifetimeFn : newProbeUDPLifetime ,
bestAddr : addr ,
} ,
{
"invalid bestAddr" ,
lower ,
& higher ,
newProbeUDPLifetime ,
addrQuality { } ,
func ( lifetime * probeUDPLifetime ) time . Duration {
return 0
} ,
false ,
name : "invalid bestAddr" ,
localDisco : lower ,
remoteDisco : & higher ,
probeUDPLifetimeFn : newProbeUDPLifetime ,
bestAddr : addrQuality { } ,
} ,
{
"cycle started too recently" ,
lower ,
& higher ,
func ( ) * probeUDPLifetime {
l := newProbeUDPLifetime ( )
l . cycleActive = false
l . cycleStartedAt = time . Now ( )
return l
} ,
addr ,
func ( lifetime * probeUDPLifetime ) time . Duration {
return 0
name : "cycle started too recently" ,
localDisco : lower ,
remoteDisco : & higher ,
probeUDPLifetimeFn : func ( ) * probeUDPLifetime {
lt := newProbeUDPLifetime ( )
lt . cycleActive = false
lt . cycleStartedAt = time . Now ( )
return lt
} ,
false ,
bestAddr : addr ,
} ,
{
"maybe cliff 0 cycle not active" ,
lo wer,
& higher ,
func ( ) * probeUDPLifetime {
l := newProbeUDPLifetime ( )
l . cycleActive = false
l . cycleStartedAt = time . Now ( ) . Add ( - l . config . CycleCanStartEvery ) . Add ( - time . Second )
return l
} ,
addr,
func ( lifetime * probeUDPLifetime ) time . Duration {
name : "maybe cliff 0 cycle not active" ,
lo calDisco: lo wer,
remoteDisco : & higher ,
probeUDPLifetimeFn : func ( ) * probeUDPLifetime {
l t := newProbeUDPLifetime ( )
l t . cycleActive = false
l t . cycleStartedAt = time . Now ( ) . Add ( - l t . config . CycleCanStartEvery ) . Add ( - time . Second )
return l t
} ,
bestAddr: addr,
wantAfterInactivityForFn : func ( lifetime * probeUDPLifetime ) time . Duration {
return lifetime . config . Cliffs [ 0 ] - udpLifetimeProbeCliffSlack
} ,
true ,
wantMaybe : true ,
} ,
{
"maybe cliff 0" ,
lo wer,
& higher ,
func ( ) * probeUDPLifetime {
l := newProbeUDPLifetime ( )
l . cycleActive = true
l . currentCliff = 0
return l
} ,
addr,
func ( lifetime * probeUDPLifetime ) time . Duration {
name : "maybe cliff 0" ,
lo calDisco: lo wer,
remoteDisco : & higher ,
probeUDPLifetimeFn : func ( ) * probeUDPLifetime {
l t := newProbeUDPLifetime ( )
l t . cycleActive = true
l t . currentCliff = 0
return l t
} ,
bestAddr: addr,
wantAfterInactivityForFn : func ( lifetime * probeUDPLifetime ) time . Duration {
return lifetime . config . Cliffs [ 0 ] - udpLifetimeProbeCliffSlack
} ,
true ,
wantMaybe : true ,
} ,
{
"maybe cliff 1" ,
lo wer,
& higher ,
func ( ) * probeUDPLifetime {
l := newProbeUDPLifetime ( )
l . cycleActive = true
l . currentCliff = 1
return l
} ,
addr,
func ( lifetime * probeUDPLifetime ) time . Duration {
name : "maybe cliff 1" ,
lo calDisco: lo wer,
remoteDisco : & higher ,
probeUDPLifetimeFn : func ( ) * probeUDPLifetime {
l t := newProbeUDPLifetime ( )
l t . cycleActive = true
l t . currentCliff = 1
return l t
} ,
bestAddr: addr,
wantAfterInactivityForFn : func ( lifetime * probeUDPLifetime ) time . Duration {
return lifetime . config . Cliffs [ 1 ] - udpLifetimeProbeCliffSlack
} ,
true ,
wantMaybe : true ,
} ,
{
"maybe cliff 2" ,
lo wer,
& higher ,
func ( ) * probeUDPLifetime {
l := newProbeUDPLifetime ( )
l . cycleActive = true
l . currentCliff = 2
return l
} ,
addr,
func ( lifetime * probeUDPLifetime ) time . Duration {
name : "maybe cliff 2" ,
lo calDisco: lo wer,
remoteDisco : & higher ,
probeUDPLifetimeFn : func ( ) * probeUDPLifetime {
l t := newProbeUDPLifetime ( )
l t . cycleActive = true
l t . currentCliff = 2
return l t
} ,
bestAddr: addr,
wantAfterInactivityForFn : func ( lifetime * probeUDPLifetime ) time . Duration {
return lifetime . config . Cliffs [ 2 ] - udpLifetimeProbeCliffSlack
} ,
true ,
wantMaybe : true ,
} ,
}
for _ , tt := range tests {
@ -316,7 +296,10 @@ func Test_endpoint_maybeProbeUDPLifetimeLocked(t *testing.T) {
p := tt . probeUDPLifetimeFn ( )
de . probeUDPLifetime = p
gotAfterInactivityFor , gotMaybe := de . maybeProbeUDPLifetimeLocked ( )
wantAfterInactivityFor := tt . wantAfterInactivityForFn ( p )
var wantAfterInactivityFor time . Duration
if tt . wantAfterInactivityForFn != nil {
wantAfterInactivityFor = tt . wantAfterInactivityForFn ( p )
}
if gotAfterInactivityFor != wantAfterInactivityFor {
t . Errorf ( "maybeProbeUDPLifetimeLocked() gotAfterInactivityFor = %v, want %v" , gotAfterInactivityFor , wantAfterInactivityFor )
}