Skip to content

Commit

Permalink
Ensure race conditions handled
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Jan 4, 2024
1 parent 5f02710 commit b023ebc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: '>=1.21.0'
- name: Run race tests
run: make test-race
- name: Run integration tests
run: make test-integration
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
ENVTEST_K8S_VERSION = 1.27.1

.PHONY: test
test: test-unit

.PHONY: test-all
test-all: test-race test-integration

.PHONY: test-unit
test-unit:
go test -mod=readonly ./pkg/...

.PHONY: test-race
test-race:
go test -mod=readonly -race ./pkg/...

.PHONY: test-integration
test-integration: envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./tests/integration -v

Expand Down
8 changes: 7 additions & 1 deletion pkg/endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (e *endpointGroup) getBestHost(ctx context.Context, portName string) (strin
for len(e.endpoints) == 0 {
e.mtx.RUnlock()
select {
case <-e.bcast:
case <-e.awaitEndpoints():
case <-ctx.Done():
return "", ctx.Err()
}
Expand All @@ -65,6 +65,12 @@ func (e *endpointGroup) getBestHost(ctx context.Context, portName string) (strin
return fmt.Sprintf("%s:%v", bestIP, port), nil
}

func (e *endpointGroup) awaitEndpoints() chan struct{} {
e.bmtx.RLock()
defer e.bmtx.RUnlock()
return e.bcast
}

func (e *endpointGroup) getAllHosts(portName string) []string {
e.mtx.RLock()
defer e.mtx.RUnlock()
Expand Down

0 comments on commit b023ebc

Please sign in to comment.