Skip to content

Commit 0bb2ef1

Browse files
committed
apply coderabbitai suggestion
Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
1 parent c86d5d6 commit 0bb2ef1

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

test/e2e/server_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,21 +266,29 @@ func newHTTPSession(mcpServerListen string, mcpServerDebug bool, argocdURL strin
266266
}
267267

268268
func waitForMCPServer(mcpServerListen string) error {
269-
// wait until the MCP server is ready to accept connections
269+
// wait until the MCP server is ready to accept connections with a timeout of 30 seconds
270+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
271+
defer cancel()
270272
for {
271-
req, err := http.NewRequestWithContext(context.Background(), "GET", fmt.Sprintf("http://%s/health", mcpServerListen), nil)
273+
select {
274+
case <-ctx.Done():
275+
return fmt.Errorf("timeout waiting for MCP server to start")
276+
default:
277+
}
278+
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("http://%s/health", mcpServerListen), nil)
272279
if err != nil {
273280
return fmt.Errorf("failed to create request: %w", err)
274281
}
275282
resp, err := http.DefaultClient.Do(req)
276283
if err != nil {
284+
time.Sleep(100 * time.Millisecond)
277285
continue
278286
}
279-
defer resp.Body.Close()
287+
resp.Body.Close()
280288
if resp.StatusCode == http.StatusOK {
281289
break
282290
}
283-
time.Sleep(1 * time.Second)
291+
time.Sleep(100 * time.Millisecond)
284292
}
285293
return nil
286294
}

0 commit comments

Comments
 (0)