The fix can make this test run unconditionally.
This moves code from 5c619882bc for
testability but doesn't fix it yet. The #1282 problem remains (when I
wrote its wake-up mechanism, I forgot there were N DERP readers
funneling into 1 UDP reader, and the code just isn't correct at all
for that case).
Also factor out some test helper code from BenchmarkReceiveFrom.
The refactoring in magicsock.go for testability should have no
behavior change.
t.Logf("--test-issue-1282 was not specified; so doing single-threaded test (instead of NumCPU=%d) to work around https://github.com/tailscale/tailscale/issues/1282",senders)
senders=1
}
sends-=(sends%senders)
varwgsync.WaitGroup
deferwg.Wait()
t.Logf("doing %v sends over %d senders",sends,senders)
ctx:=context.Background()
fori:=0;i<senders;i++{
wg.Add(1)
regionID:=i+1
gofunc(){
deferwg.Done()
ch:=make(chanbool,1)
fori:=0;i<sends/senders;i++{
if!conn.sendDerpReadResult(ctx,derpReadResult{
regionID:regionID,
n:123,
src:key.Public(nodeKey),
copyBuf:func(dst[]byte)int{
ch<-true
return123
},
}){
t.Error("unexpected false")
return
}
<-ch
}
}()
}
buf:=make([]byte,1500)
fori:=0;i<sends;i++{
n,ep,err:=conn.ReceiveIPv4(buf)
iferr!=nil{
t.Fatal(err)
}
_=n
_=ep
}
}
// addTestEndpoint sets conn's network map to a single peer expected
// to receive packets from sendConn (or DERP), and returns that peer's