Skip to content

Commit 2ab1491

Browse files
committed
fix: race condition in exporter, bodyclose in WS tests, dupl nolint
- Copy exporter before mutating AsYAML to avoid racing on the shared registry singleton when parallel tests call Export() - Close WebSocket dial response body via t.Cleanup in test helper - Add nolint:dupl to printVerboseEntry (intentional mirror for different wire type)
1 parent a998ba9 commit 2ab1491

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

pkg/cli/logs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ func printTableEntry(req *requestlog.Entry) {
665665
}
666666

667667
// printVerboseEntry prints a single log entry in verbose format.
668+
//
669+
//nolint:dupl // Intentionally mirrors printVerboseAPIEntry for a different wire type.
668670
func printVerboseEntry(req *requestlog.Entry) {
669671
timestamp := req.Timestamp.Format("2006-01-02 15:04:05")
670672
protocol := req.Protocol

pkg/portability/exporter.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,18 @@ func Export(collection *config.MockCollection, opts *ExportOptions) (*ExportResu
7070
}
7171
}
7272

73-
// Wire caller options into the exporter when explicitly set.
74-
// NativeExporter and OpenAPIExporter both honour AsYAML.
73+
// Wire caller options into a local copy of the exporter so parallel
74+
// callers don't race on the shared registry singleton.
7575
if opts.AsYAML != nil {
7676
switch e := exporter.(type) {
7777
case *NativeExporter:
78-
e.AsYAML = *opts.AsYAML
78+
local := *e
79+
local.AsYAML = *opts.AsYAML
80+
exporter = &local
7981
case *OpenAPIExporter:
80-
e.AsYAML = *opts.AsYAML
82+
local := *e
83+
local.AsYAML = *opts.AsYAML
84+
exporter = &local
8185
}
8286
}
8387

pkg/websocket/handler_e2e_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import (
1818
func dialWS(t *testing.T, ts *httptest.Server, path string) (*gorillaWs.Conn, *http.Response, error) {
1919
t.Helper()
2020
wsURL := "ws" + strings.TrimPrefix(ts.URL, "http") + path
21-
return gorillaWs.DefaultDialer.Dial(wsURL, nil)
21+
conn, resp, err := gorillaWs.DefaultDialer.Dial(wsURL, nil)
22+
if resp != nil && resp.Body != nil {
23+
t.Cleanup(func() { _ = resp.Body.Close() })
24+
}
25+
return conn, resp, err
2226
}
2327

2428
// setupHandler creates a ConnectionManager, registers the given endpoints,

0 commit comments

Comments
 (0)