Skip to content

Commit 9c633df

Browse files
authored
fix race condition of TestConcurrent (#1490)
* fix race condition of TestConcurrent * run tests with the '-race' option
1 parent 5f74bcb commit 9c633df

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

Diff for: .github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
9797
- name: test
9898
run: |
99-
go test -v '-covermode=count' '-coverprofile=coverage.out'
99+
go test -v '-race' '-covermode=atomic' '-coverprofile=coverage.out'
100100
101101
- name: Send coverage
102102
uses: shogo82148/actions-goveralls@v1

Diff for: driver_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,6 @@ func TestConcurrent(t *testing.T) {
18721872
defer wg.Done()
18731873

18741874
tx, err := dbt.db.Begin()
1875-
atomic.AddInt32(&remaining, -1)
18761875

18771876
if err != nil {
18781877
if err.Error() != "Error 1040: Too many connections" {
@@ -1882,7 +1881,7 @@ func TestConcurrent(t *testing.T) {
18821881
}
18831882

18841883
// keep the connection busy until all connections are open
1885-
for remaining > 0 {
1884+
for atomic.AddInt32(&remaining, -1) > 0 {
18861885
if _, err = tx.Exec("DO 1"); err != nil {
18871886
fatalf("error on conn %d: %s", id, err.Error())
18881887
return

0 commit comments

Comments
 (0)