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

Function TestTunnel_sendAgentUpdateReconnect

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

Source from the content-addressed store, hash-verified

571}
572
573func TestTunnel_sendAgentUpdateReconnect(t *testing.T) {
574 t.Parallel()
575
576 ctx := testutil.Context(t, testutil.WaitShort)
577
578 mClock := quartz.NewMock(t)
579
580 wID1 := uuid.UUID{1}
581 aID1 := uuid.UUID{2}
582 aID2 := uuid.UUID{3}
583
584 hsTime := time.Now().Add(-time.Minute).UTC()
585
586 client := newFakeClient(ctx, t)
587 conn := newFakeConn(tailnet.WorkspaceUpdate{}, hsTime)
588
589 tun, mgr := setupTunnel(t, ctx, client, mClock)
590 errCh := make(chan error, 1)
591 var resp *TunnelMessage
592 go func() {
593 r, err := mgr.unaryRPC(ctx, &ManagerMessage{
594 Msg: &ManagerMessage_Start{
595 Start: &StartRequest{
596 TunnelFileDescriptor: 2,
597 CoderUrl: "https://coder.example.com",
598 ApiToken: "fakeToken",
599 },
600 },
601 })
602 resp = r
603 errCh <- err
604 }()
605 testutil.RequireSend(ctx, t, client.ch, conn)
606 err := testutil.TryReceive(ctx, t, errCh)
607 require.NoError(t, err)
608 _, ok := resp.Msg.(*TunnelMessage_Start)
609 require.True(t, ok)
610
611 // Inform the tunnel of the initial state
612 err = tun.Update(tailnet.WorkspaceUpdate{
613 UpsertedWorkspaces: []*tailnet.Workspace{
614 {
615 ID: wID1, Name: "w1", Status: proto.Workspace_STARTING,
616 },
617 },
618 UpsertedAgents: []*tailnet.Agent{
619 {
620 ID: aID1,
621 Name: "agent1",
622 WorkspaceID: wID1,
623 Hosts: map[dnsname.FQDN][]netip.Addr{
624 "agent1.coder.": {netip.MustParseAddr("fd60:627a:a42b:0101::")},
625 },
626 },
627 },
628 })
629 require.NoError(t, err)
630 req := testutil.TryReceive(ctx, t, mgr.requests)

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected