Skip to content

Commit

Permalink
Test updates (Enable race detection and disable output interceptor) (#…
Browse files Browse the repository at this point in the history
…956)

* tests: Disable all output capture in ginkgo tests

This creates a lot of extra output during the test runs which is really
distracting, and makes the output virtually useless.

Apart from that is can cause the entire test run to freeze under
certain situations (which has happened a few times lately) due to the
issue described here.
https://github.com/onsi/ginkgo/blob/104752fa2e97f04b1300754e710c419a63d2d30c/internal/output_interceptor.go#L13

* tests: Add --race option to ginkgo run

This will cause the test suite to fail if any race condition is detected
during the execution of the tests.

Note: When the tests are run in parallel this does not output a
descriptive message for the failure. If it fails for seemingly random
reasons you should try running the test suite without parallel processes
enabled.

* dev: Add `--race` option to `make run` task

Enables the race detector on locally running instances
https://go.dev/doc/articles/race_detector. This will report useful
information in the logs about race related issues.

* fix: Authorino race condition

---------

Signed-off-by: Michael Nairn <[email protected]>
  • Loading branch information
mikenairn authored Oct 24, 2024
1 parent 28ba551 commit b6494ca
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ run: export OPERATOR_NAMESPACE := $(OPERATOR_NAMESPACE)
run: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown")
run: DIRTY=$(shell $(PROJECT_PATH)/utils/check-git-dirty.sh || echo "unknown")
run: generate fmt vet ## Run a controller from your host.
go run -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" ./main.go
go run -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" --race ./main.go

docker-build: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown")
docker-build: DIRTY=$(shell $(PROJECT_PATH)/utils/check-git-dirty.sh || echo "unknown")
Expand Down
10 changes: 10 additions & 0 deletions make/integration-tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ test-bare-k8s-integration: clean-cov generate fmt vet ginkgo ## Requires only ba
--fail-on-pending \
--keep-going \
--trace \
--race \
--output-interceptor-mode=none \
$(INTEGRATION_TESTS_EXTRA_ARGS) ./tests/bare_k8s/...

.PHONY: test-gatewayapi-env-integration
Expand All @@ -40,6 +42,8 @@ test-gatewayapi-env-integration: clean-cov generate fmt vet ginkgo ## Requires k
--fail-on-pending \
--keep-going \
--trace \
--race \
--output-interceptor-mode=none \
$(INTEGRATION_TESTS_EXTRA_ARGS) ./tests/gatewayapi/...

.PHONY: test-istio-env-integration
Expand All @@ -58,6 +62,8 @@ test-istio-env-integration: clean-cov generate fmt vet ginkgo ## Requires kubern
--fail-on-pending \
--keep-going \
--trace \
--race \
--output-interceptor-mode=none \
$(INTEGRATION_TESTS_EXTRA_ARGS) tests/istio/...

test-envoygateway-env-integration: clean-cov generate fmt vet ginkgo ## Requires kubernetes cluster with GatewayAPI and EnvoyGateway installed.
Expand All @@ -75,6 +81,8 @@ test-envoygateway-env-integration: clean-cov generate fmt vet ginkgo ## Requires
--fail-on-pending \
--keep-going \
--trace \
--race \
--output-interceptor-mode=none \
$(INTEGRATION_TESTS_EXTRA_ARGS) tests/envoygateway/...

.PHONY: test-integration
Expand All @@ -93,4 +101,6 @@ test-integration: clean-cov generate fmt vet ginkgo ## Requires kubernetes clust
--fail-on-pending \
--keep-going \
--trace \
--race \
--output-interceptor-mode=none \
$(INTEGRATION_TESTS_EXTRA_ARGS) $(INTEGRATION_TEST_PACKAGES)
13 changes: 12 additions & 1 deletion pkg/library/kuadrant/apimachinery_status_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,28 @@ func (o *AffectedPolicyMap) RemoveAffectedPolicy(p Policy) {

// IsPolicyAffected checks if the provided Policy is affected based on the tracking map maintained.
func (o *AffectedPolicyMap) IsPolicyAffected(p Policy) bool {
o.mu.Lock()
defer o.mu.Unlock()

return o.policies[p.GetUID()] != nil
}

// IsPolicyOverridden checks if the provided Policy is affected based on the tracking map maintained.
// It is overridden if there is policies affecting it
func (o *AffectedPolicyMap) IsPolicyOverridden(p Policy) bool {
return o.IsPolicyAffected(p) && len(o.policies[p.GetUID()]) > 0
pAffected := o.IsPolicyAffected(p)

o.mu.Lock()
defer o.mu.Unlock()

return pAffected && len(o.policies[p.GetUID()]) > 0
}

// PolicyAffectedBy returns the clients keys that a policy is Affected by
func (o *AffectedPolicyMap) PolicyAffectedBy(p Policy) []client.ObjectKey {
o.mu.Lock()
defer o.mu.Unlock()

return o.policies[p.GetUID()]
}

Expand Down

0 comments on commit b6494ca

Please sign in to comment.