MCPcopy Create free account
hub / github.com/coder/coder / TestTunnel_sendAgentUpdate

Function TestTunnel_sendAgentUpdate

vpn/tunnel_internal_test.go:403–571  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

401}
402
403func TestTunnel_sendAgentUpdate(t *testing.T) {
404 t.Parallel()
405
406 ctx := testutil.Context(t, testutil.WaitShort)
407
408 mClock := quartz.NewMock(t)
409
410 wID1 := uuid.UUID{1}
411 aID1 := uuid.UUID{2}
412 aID2 := uuid.UUID{3}
413 hsTime := time.Now().Add(-time.Minute).UTC()
414
415 client := newFakeClient(ctx, t)
416 conn := newFakeConn(tailnet.WorkspaceUpdate{}, hsTime)
417
418 tun, mgr := setupTunnel(t, ctx, client, mClock)
419 errCh := make(chan error, 1)
420 var resp *TunnelMessage
421 go func() {
422 r, err := mgr.unaryRPC(ctx, &ManagerMessage{
423 Msg: &ManagerMessage_Start{
424 Start: &StartRequest{
425 TunnelFileDescriptor: 2,
426 CoderUrl: "https://coder.example.com",
427 ApiToken: "fakeToken",
428 },
429 },
430 })
431 resp = r
432 errCh <- err
433 }()
434 testutil.RequireSend(ctx, t, client.ch, conn)
435 err := testutil.TryReceive(ctx, t, errCh)
436 require.NoError(t, err)
437 _, ok := resp.Msg.(*TunnelMessage_Start)
438 require.True(t, ok)
439
440 // Inform the tunnel of the initial state
441 err = tun.Update(tailnet.WorkspaceUpdate{
442 UpsertedWorkspaces: []*tailnet.Workspace{
443 {
444 ID: wID1, Name: "w1", Status: proto.Workspace_STARTING,
445 },
446 },
447 UpsertedAgents: []*tailnet.Agent{
448 {
449 ID: aID1,
450 Name: "agent1",
451 WorkspaceID: wID1,
452 Hosts: map[dnsname.FQDN][]netip.Addr{
453 "agent1.coder.": {netip.MustParseAddr("fd60:627a:a42b:0101::")},
454 },
455 },
456 },
457 })
458 require.NoError(t, err)
459 req := testutil.TryReceive(ctx, t, mgr.requests)
460 require.Nil(t, req.msg.Rpc)

Callers

nothing calls this directly

Calls 14

ContextFunction · 0.92
RequireSendFunction · 0.92
TryReceiveFunction · 0.92
EventuallyFunction · 0.92
newFakeConnFunction · 0.85
setupTunnelFunction · 0.85
unaryRPCMethod · 0.80
CompareMethod · 0.80
newFakeClientFunction · 0.70
AddMethod · 0.65
UpdateMethod · 0.65
GetPeerUpdateMethod · 0.45

Tested by

no test coverage detected