Skip to content

Commit f905c5b

Browse files
authored
updating unit test make cmd to add -race flag (#7024)
* updating unit test make cmd to add -race flag Signed-off-by: Adam D. Cornett <[email protected]> * fixing race condition in external go, ensure cmd has finished Signed-off-by: Adam D. Cornett <[email protected]> --------- Signed-off-by: Adam D. Cornett <[email protected]>
1 parent d7979db commit f905c5b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ test-docs: ## Test doc links
168168
.PHONY: test-unit
169169
TEST_PKGS = $(shell $(GO) list ./... | grep -v -E 'github.com/operator-framework/operator-sdk/test/')
170170
test-unit: ## Run unit tests
171-
$(GO) test -tags=$(GO_BUILD_TAGS) -coverprofile=coverage.out -covermode=count -short $(TEST_PKGS)
171+
CGO_ENABLED=1 $(GO) test -race -tags=$(GO_BUILD_TAGS) -coverprofile=coverage.out -covermode=atomic -short $(TEST_PKGS)
172172

173173
e2e_tests := test-e2e-go test-e2e-helm test-e2e-integration
174174
e2e_targets := test-e2e $(e2e_tests)

internal/validate/external.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,17 @@ func RunExternalValidators(ctx context.Context, entrypoints []string, bundleRoot
6464
dec := json.NewDecoder(stdout)
6565
dec.DisallowUnknownFields()
6666

67-
if err := dec.Decode(&manifestresults[i]); err != nil {
68-
fmt.Printf("decode failed: %v\n", err)
69-
return nil, err
70-
}
67+
decodeErr := dec.Decode(&manifestresults[i])
68+
// Always wait for the command to finish to ensure stderr is fully written
69+
// and all goroutines complete before returning.
7170
if err := cmd.Wait(); err != nil {
7271
return nil, err
7372
}
73+
// Return decode error after waiting for command to complete
74+
if decodeErr != nil {
75+
fmt.Printf("decode failed: %v\n", decodeErr)
76+
return nil, decodeErr
77+
}
7478
}
7579
return manifestresults, nil
7680
}

0 commit comments

Comments
 (0)