mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix(test): mock gateway health check in status tests
Two gateway tests were flaky due to race conditions: - TestGatewayStatusReturnsRestartingDuringRestartGap - TestGatewayRestartReturnsErrorStatusWhenReplacementFailsToStart The handleGatewayStatus function calls getGatewayHealth which can override the test's expected status. By mocking gatewayHealthGet to return an error, the tests now reliably verify the expected status values. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -596,6 +596,11 @@ func TestGatewayStatusReturnsErrorAfterStartupWindowExpires(t *testing.T) {
|
||||
func TestGatewayStatusReturnsRestartingDuringRestartGap(t *testing.T) {
|
||||
resetGatewayTestState(t)
|
||||
|
||||
// Mock health check to return error, so it won't override our "restarting" status
|
||||
gatewayHealthGet = func(url string, timeout time.Duration) (*http.Response, error) {
|
||||
return nil, errors.New("mock health check error")
|
||||
}
|
||||
|
||||
configPath := filepath.Join(t.TempDir(), "config.json")
|
||||
h := NewHandler(configPath)
|
||||
mux := http.NewServeMux()
|
||||
@@ -738,6 +743,11 @@ func TestGatewayRestartKeepsOldProcessWhenItDoesNotExitInTime(t *testing.T) {
|
||||
func TestGatewayRestartReturnsErrorStatusWhenReplacementFailsToStart(t *testing.T) {
|
||||
resetGatewayTestState(t)
|
||||
|
||||
// Mock health check to return error, so it won't override our "error" status
|
||||
gatewayHealthGet = func(url string, timeout time.Duration) (*http.Response, error) {
|
||||
return nil, errors.New("mock health check error")
|
||||
}
|
||||
|
||||
configPath := filepath.Join(t.TempDir(), "config.json")
|
||||
cfg := config.DefaultConfig()
|
||||
cfg.Agents.Defaults.ModelName = cfg.ModelList[0].ModelName
|
||||
|
||||
Reference in New Issue
Block a user