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

Function TestTunnel_sendAgentUpdateWorkspaceReconnect

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

Source from the content-addressed store, hash-verified

670}
671
672func TestTunnel_sendAgentUpdateWorkspaceReconnect(t *testing.T) {
673 t.Parallel()
674
675 ctx := testutil.Context(t, testutil.WaitShort)
676
677 mClock := quartz.NewMock(t)
678
679 wID1 := uuid.UUID{1}
680 wID2 := uuid.UUID{2}
681 aID1 := uuid.UUID{3}
682 aID3 := uuid.UUID{4}
683
684 hsTime := time.Now().Add(-time.Minute).UTC()
685
686 client := newFakeClient(ctx, t)
687 conn := newFakeConn(tailnet.WorkspaceUpdate{}, hsTime)
688
689 tun, mgr := setupTunnel(t, ctx, client, mClock)
690 errCh := make(chan error, 1)
691 var resp *TunnelMessage
692 go func() {
693 r, err := mgr.unaryRPC(ctx, &ManagerMessage{
694 Msg: &ManagerMessage_Start{
695 Start: &StartRequest{
696 TunnelFileDescriptor: 2,
697 CoderUrl: "https://coder.example.com",
698 ApiToken: "fakeToken",
699 },
700 },
701 })
702 resp = r
703 errCh <- err
704 }()
705 testutil.RequireSend(ctx, t, client.ch, conn)
706 err := testutil.TryReceive(ctx, t, errCh)
707 require.NoError(t, err)
708 _, ok := resp.Msg.(*TunnelMessage_Start)
709 require.True(t, ok)
710
711 // Inform the tunnel of the initial state
712 err = tun.Update(tailnet.WorkspaceUpdate{
713 UpsertedWorkspaces: []*tailnet.Workspace{
714 {
715 ID: wID1, Name: "w1", Status: proto.Workspace_STARTING,
716 },
717 },
718 UpsertedAgents: []*tailnet.Agent{
719 {
720 ID: aID1,
721 Name: "agent1",
722 WorkspaceID: wID1,
723 Hosts: map[dnsname.FQDN][]netip.Addr{
724 "agent1.coder.": {netip.MustParseAddr("fd60:627a:a42b:0101::")},
725 },
726 },
727 },
728 })
729 require.NoError(t, err)

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