(t *testing.T)
| 730 | } |
| 731 | |
| 732 | func TestWatchAgentContainers(t *testing.T) { |
| 733 | t.Parallel() |
| 734 | |
| 735 | t.Run("CoderdWebSocketCanHandleClientClosing", func(t *testing.T) { |
| 736 | t.Parallel() |
| 737 | |
| 738 | // This test ensures that the agent containers `/watch` websocket can gracefully |
| 739 | // handle the client websocket closing. This test was created in |
| 740 | // response to this issue: https://github.com/coder/coder/issues/19449 |
| 741 | |
| 742 | var ( |
| 743 | ctx = testutil.Context(t, testutil.WaitShort) |
| 744 | logger = slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug).Named("coderd") |
| 745 | mClock = quartz.NewMock(t) |
| 746 | |
| 747 | mCtrl = gomock.NewController(t) |
| 748 | mDB = dbmock.NewMockStore(mCtrl) |
| 749 | mCoordinator = tailnettest.NewMockCoordinator(mCtrl) |
| 750 | mAgentConn = agentconnmock.NewMockAgentConn(mCtrl) |
| 751 | |
| 752 | fAgentProvider = fakeAgentProvider{ |
| 753 | agentConn: func(ctx context.Context, agentID uuid.UUID) (_ workspacesdk.AgentConn, release func(), _ error) { |
| 754 | return mAgentConn, func() {}, nil |
| 755 | }, |
| 756 | } |
| 757 | |
| 758 | workspaceID = uuid.New() |
| 759 | agentID = uuid.New() |
| 760 | resourceID = uuid.New() |
| 761 | |
| 762 | containersCh = make(chan codersdk.WorkspaceAgentListContainersResponse) |
| 763 | |
| 764 | r = chi.NewMux() |
| 765 | |
| 766 | api = API{ |
| 767 | ctx: ctx, |
| 768 | Options: &Options{ |
| 769 | AgentInactiveDisconnectTimeout: testutil.WaitShort, |
| 770 | Database: mDB, |
| 771 | Logger: logger, |
| 772 | Clock: mClock, |
| 773 | DeploymentValues: &codersdk.DeploymentValues{}, |
| 774 | TailnetCoordinator: tailnettest.NewFakeCoordinator(), |
| 775 | }, |
| 776 | } |
| 777 | ) |
| 778 | |
| 779 | trap := mClock.Trap().NewTicker("HeartbeatClose") |
| 780 | defer trap.Close() |
| 781 | |
| 782 | var tailnetCoordinator tailnet.Coordinator = mCoordinator |
| 783 | api.TailnetCoordinator.Store(&tailnetCoordinator) |
| 784 | api.agentProvider = fAgentProvider |
| 785 | |
| 786 | // Setup: Allow `ExtractWorkspaceAgentParams` to complete. |
| 787 | mDB.EXPECT().GetWorkspaceAgentAndWorkspaceByID(gomock.Any(), agentID).Return(database.GetWorkspaceAgentAndWorkspaceByIDRow{ |
| 788 | WorkspaceAgent: database.WorkspaceAgent{ |
| 789 | ID: agentID, |
nothing calls this directly
no test coverage detected