Skip to content

Commit 74db36e

Browse files
fix flaky kill process tests: removed sending response
Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
1 parent a0aa88c commit 74db36e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

acceptance/internal/prepare_server.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func startLocalServer(t *testing.T,
221221

222222
if shouldKillCaller(stub, killCounters, killCountersMu) {
223223
killCaller(t, stub.Pattern, req.Headers)
224-
return testserver.Response{StatusCode: http.StatusOK}
224+
return nil
225225
}
226226

227227
return stub.Response
@@ -266,7 +266,14 @@ func killCaller(t *testing.T, pattern string, headers http.Header) {
266266
return
267267
}
268268

269-
t.Logf("KillCaller: killed PID %d (pattern: %s)", pid, pattern)
269+
// Wait for process to actually exit before returning.
270+
// This prevents the HTTP handler from sending a response while
271+
// the process is still running, avoiding race conditions.
272+
if waitForProcessExit(pid, 2*time.Second) {
273+
t.Logf("KillCaller: killed PID %d (pattern: %s)", pid, pattern)
274+
} else {
275+
t.Logf("KillCaller: killed PID %d but timed out waiting for exit (pattern: %s)", pid, pattern)
276+
}
270277
}
271278

272279
func startProxyServer(t *testing.T,

libs/testserver/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func (s *Server) Handle(method, path string, handler HandlerFunc) {
294294
}
295295
} else {
296296
respAny := handler(request)
297-
if respAny == nil && request.Context.Err() != nil {
297+
if respAny == nil {
298298
return
299299
}
300300
resp = normalizeResponse(s.t, respAny)

0 commit comments

Comments
 (0)