MCPcopy Index your code
hub / github.com/coder/coder / TestClientService_ServeClient_V2

Function TestClientService_ServeClient_V2

tailnet/service_test.go:25–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestClientService_ServeClient_V2(t *testing.T) {
26 t.Parallel()
27 fCoord := tailnettest.NewFakeCoordinator()
28 var coord tailnet.Coordinator = fCoord
29 coordPtr := atomic.Pointer[tailnet.Coordinator]{}
30 coordPtr.Store(&coord)
31 logger := testutil.Logger(t)
32 derpMap := &tailcfg.DERPMap{Regions: map[int]*tailcfg.DERPRegion{999: {RegionCode: "test"}}}
33
34 telemetryEvents := make(chan []*proto.TelemetryEvent, 64)
35 uut, err := tailnet.NewClientService(tailnet.ClientServiceOptions{
36 Logger: logger,
37 CoordPtr: &coordPtr,
38 DERPMapUpdateFrequency: time.Millisecond,
39 DERPMapFn: func() *tailcfg.DERPMap { return derpMap },
40 NetworkTelemetryHandler: func(batch []*proto.TelemetryEvent) {
41 telemetryEvents <- batch
42 },
43 ResumeTokenProvider: tailnet.NewInsecureTestResumeTokenProvider(),
44 })
45 require.NoError(t, err)
46
47 ctx := testutil.Context(t, testutil.WaitShort)
48 c, s := net.Pipe()
49 defer c.Close()
50 defer s.Close()
51 clientID := uuid.MustParse("10000001-0000-0000-0000-000000000000")
52 agentID := uuid.MustParse("20000001-0000-0000-0000-000000000000")
53 errCh := make(chan error, 1)
54 go func() {
55 err := uut.ServeClient(ctx, "2.0", s, tailnet.StreamID{
56 Name: "client",
57 ID: clientID,
58 Auth: tailnet.ClientCoordinateeAuth{
59 AgentID: agentID,
60 },
61 })
62 t.Logf("ServeClient returned; err=%v", err)
63 errCh <- err
64 }()
65
66 client, err := tailnet.NewDRPCClient(c, logger)
67 require.NoError(t, err)
68
69 // Coordinate
70 stream, err := client.Coordinate(ctx)
71 require.NoError(t, err)
72 defer stream.Close()
73
74 err = stream.Send(&proto.CoordinateRequest{
75 UpdateSelf: &proto.CoordinateRequest_UpdateSelf{Node: &proto.Node{PreferredDerp: 11}},
76 })
77 require.NoError(t, err)
78
79 call := testutil.TryReceive(ctx, t, fCoord.CoordinateCalls)
80 require.NotNil(t, call)
81 require.Equal(t, call.ID, clientID)
82 require.Equal(t, call.Name, "client")

Callers

nothing calls this directly

Calls 15

ServeClientMethod · 0.95
NewFakeCoordinatorFunction · 0.92
LoggerFunction · 0.92
NewClientServiceFunction · 0.92
ContextFunction · 0.92
NewDRPCClientFunction · 0.92
TryReceiveFunction · 0.92
GetUpdateSelfMethod · 0.80
GetPeerUpdatesMethod · 0.80
GetRegionCodeMethod · 0.80
GetRegionsMethod · 0.80

Tested by

no test coverage detected