Skip to content

Commit cadac98

Browse files
authored
Merge pull request #27 from ncode/juliano/integration-tests
test: add integration tests with real Consul instance
2 parents 8ddf12a + 649b0cf commit cadac98

File tree

5 files changed

+471
-5
lines changed

5 files changed

+471
-5
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,21 @@ jobs:
2020
verbose: true
2121
env:
2222
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
23+
24+
integration:
25+
runs-on: ubuntu-latest
26+
services:
27+
consul:
28+
image: hashicorp/consul:latest
29+
ports:
30+
- 8500:8500
31+
options: --health-cmd="consul members" --health-interval=2s --health-timeout=5s --health-retries=10
32+
steps:
33+
- uses: actions/[email protected]
34+
- uses: actions/[email protected]
35+
with:
36+
go-version: '1.25'
37+
- name: Run integration tests
38+
run: go env -w GOTOOLCHAIN=go1.25.0+auto && go test -v -tags=integration -race ./...
39+
env:
40+
CONSUL_HTTP_ADDR: http://localhost:8500

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.PHONY: build test test-race test-coverage test-integration integration-up integration-down clean
2+
3+
build:
4+
go build -v ./...
5+
6+
test:
7+
go test -v ./...
8+
9+
test-race:
10+
go test -v -race ./...
11+
12+
test-coverage:
13+
go test -coverpkg=./... ./... -race -coverprofile=coverage.out -covermode=atomic
14+
go tool cover -html=coverage.out -o coverage.html
15+
16+
test-integration: integration-up
17+
CONSUL_HTTP_ADDR=http://localhost:8500 go test -v -tags=integration -race ./... ; \
18+
status=$$? ; \
19+
$(MAKE) integration-down ; \
20+
exit $$status
21+
22+
integration-up:
23+
docker compose -f configs/integration/docker-compose.yaml up -d --wait
24+
25+
integration-down:
26+
docker compose -f configs/integration/docker-compose.yaml down -v
27+
28+
clean:
29+
rm -f coverage.out coverage.html
30+
go clean -testcache
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
consul:
3+
image: hashicorp/consul:latest
4+
container_name: consul-integration
5+
command: "agent -dev -bind=0.0.0.0 -client=0.0.0.0"
6+
ports:
7+
- "8500:8500"
8+
healthcheck:
9+
test: ["CMD", "consul", "members"]
10+
interval: 2s
11+
timeout: 5s
12+
retries: 10

internal/ballot/ballot.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -767,10 +767,10 @@ func (b *Ballot) releaseSession() error {
767767
return nil
768768
}
769769
sessionID := *sessionIDPtr
770-
_, err := b.client.Session().Destroy(sessionID, nil)
771-
if err != nil {
772-
return err
773-
}
770+
// Always clear the local session state, even if Destroy fails.
771+
// The session may have already been invalidated by Consul (e.g., due to
772+
// health check failure), but we should still clear our local state.
774773
b.sessionID.Store((*string)(nil))
775-
return nil
774+
_, err := b.client.Session().Destroy(sessionID, nil)
775+
return err
776776
}

0 commit comments

Comments
 (0)