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

Function TestGetWorkspaceConn_DialTimeout

coderd/x/chatd/chatd_internal_test.go:5186–5255  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5184}
5185
5186func TestGetWorkspaceConn_DialTimeout(t *testing.T) {
5187 // When dialWithLazyValidation blocks beyond the dial
5188 // timeout, getWorkspaceConn should return
5189 // errChatDialTimeout instead of hanging indefinitely.
5190 t.Parallel()
5191
5192 ctrl := gomock.NewController(t)
5193 db := dbmock.NewMockStore(ctrl)
5194
5195 workspaceID := uuid.New()
5196 agentID := uuid.New()
5197 chat := database.Chat{
5198 ID: uuid.New(),
5199 WorkspaceID: uuid.NullUUID{
5200 UUID: workspaceID,
5201 Valid: true,
5202 },
5203 AgentID: uuid.NullUUID{
5204 UUID: agentID,
5205 Valid: true,
5206 },
5207 }
5208
5209 // Agent appears connected so the status check passes.
5210 connectedAgent := database.WorkspaceAgent{
5211 ID: agentID,
5212 FirstConnectedAt: sql.NullTime{
5213 Time: time.Now().Add(-1 * time.Minute),
5214 Valid: true,
5215 },
5216 LastConnectedAt: sql.NullTime{
5217 Time: time.Now(),
5218 Valid: true,
5219 },
5220 }
5221
5222 db.EXPECT().GetWorkspaceAgentByID(gomock.Any(), agentID).
5223 Return(connectedAgent, nil).
5224 Times(2)
5225 db.EXPECT().GetWorkspaceAgentsInLatestBuildByWorkspaceID(gomock.Any(), workspaceID).
5226 Return([]database.WorkspaceAgent{connectedAgent}, nil).
5227 Times(1)
5228
5229 server := &Server{
5230 db: db,
5231 clock: quartz.NewReal(),
5232 agentInactiveDisconnectTimeout: 30 * time.Second,
5233 dialTimeout: 10 * time.Millisecond,
5234 }
5235 // Dial blocks forever (simulates unreachable agent).
5236 server.agentConnFn = func(ctx context.Context, _ uuid.UUID) (workspacesdk.AgentConn, func(), error) {
5237 <-ctx.Done()
5238 return nil, nil, ctx.Err()
5239 }
5240
5241 chatStateMu := &sync.Mutex{}
5242 currentChat := chat
5243 workspaceCtx := turnWorkspaceContext{

Callers

nothing calls this directly

Calls 11

EXPECTMethod · 0.95
closeMethod · 0.95
getWorkspaceConnMethod · 0.95
NewMockStoreFunction · 0.92
ContextFunction · 0.92
ErrMethod · 0.80
NewMethod · 0.65
AddMethod · 0.65
GetWorkspaceAgentByIDMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected