package coderd import ( "testing" "github.com/stretchr/testify/require" "tailscale.com/tailcfg" "github.com/coder/coder/v2/testutil" "github.com/coder/quartz" ) func TestPollingDERPClient_FirstRecvDoesNotWaitForTick(t *testing.T) { t.Parallel() ctx := testutil.Context(t, testutil.WaitShort) derpMap := &tailcfg.DERPMap{Regions: map[int]*tailcfg.DERPRegion{1: {RegionID: 1}}} // The mock clock never advances, so a poll loop that waits for the // first tick would block forever. client := newPollingDERPClient(func() *tailcfg.DERPMap { return derpMap }, testutil.Logger(t), quartz.NewMock(t)) defer client.Close() got := make(chan *tailcfg.DERPMap, 1) go func() { dm, err := client.Recv() if err != nil { t.Error("recv derp map:", err) return } got <- dm }() require.Equal(t, derpMap, testutil.RequireReceive(ctx, t, got)) }