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