Skip to content

Commit

Permalink
Fix race conditions in unit tests and enable race check in tests (neo…
Browse files Browse the repository at this point in the history
  • Loading branch information
robsdedude authored Oct 4, 2024
1 parent 8d40e8b commit 2341390
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
8 changes: 5 additions & 3 deletions neo4j/internal/bolt/bolt3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,12 @@ func TestBolt3(outer *testing.T) {
}
inner.Parallel()
for _, test := range testCases {
testCopy := test
inner.Run(fmt.Sprintf("%s for %s", test.description, test.Method), func(t *testing.T) {
bolt, cleanup := connectToServer(t, func(srv *bolt3server) {
srv.accept(3)
if !test.ExpectError {
if test.Method == "run" {
if !testCopy.ExpectError {
if testCopy.Method == "run" {
srv.waitForRun()
} else {
srv.waitForTxBegin()
Expand Down Expand Up @@ -872,10 +873,11 @@ func TestBolt3(outer *testing.T) {
}

for _, callback := range callbacks {
callbackCopy := callback
inner.Run(callback.scenario, func(t *testing.T) {
bolt, cleanup := connectToServer(inner, func(srv *bolt3server) {
srv.accept(3)
callback.server(t, srv)
callbackCopy.server(t, srv)
})
defer cleanup()
defer bolt.Close(ctx)
Expand Down
8 changes: 5 additions & 3 deletions neo4j/internal/bolt/bolt4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,12 @@ func TestBolt4(outer *testing.T) {
}
inner.Parallel()
for _, test := range testCases {
testCopy := test
inner.Run(fmt.Sprintf("%s for %s", test.description, test.Method), func(t *testing.T) {
bolt, cleanup := connectToServer(t, func(srv *bolt4server) {
srv.acceptWithMinor(4, 4)
if !test.ExpectError {
if test.Method == "run" {
if !testCopy.ExpectError {
if testCopy.Method == "run" {
srv.waitForRun(nil)
} else {
srv.waitForTxBegin()
Expand Down Expand Up @@ -1418,10 +1419,11 @@ func TestBolt4(outer *testing.T) {
}

for _, callback := range callbacks {
callbackCopy := callback
inner.Run(callback.scenario, func(t *testing.T) {
bolt, cleanup := connectToServer(inner, func(srv *bolt4server) {
srv.accept(4)
callback.server(t, srv)
callbackCopy.server(t, srv)
})
defer cleanup()
defer bolt.Close(ctx)
Expand Down
8 changes: 5 additions & 3 deletions neo4j/internal/bolt/bolt5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,12 @@ func TestBolt5(outer *testing.T) {
}
inner.Parallel()
for _, test := range testCases {
testCopy := test
inner.Run(fmt.Sprintf("%s for %s", test.description, test.Method), func(t *testing.T) {
bolt, cleanup := connectToServer(t, func(srv *bolt5server) {
srv.acceptWithMinor(5, 1)
if !test.ExpectError {
if test.Method == "run" {
if !testCopy.ExpectError {
if testCopy.Method == "run" {
srv.waitForRun(nil)
} else {
srv.waitForTxBegin(nil)
Expand Down Expand Up @@ -1633,10 +1634,11 @@ func TestBolt5(outer *testing.T) {
}

for _, callback := range callbacks {
callbackCopy := callback
inner.Run(callback.scenario, func(t *testing.T) {
bolt, cleanup := connectToServer(inner, func(srv *bolt5server) {
srv.accept(5)
callback.server(t, srv)
callbackCopy.server(t, srv)
})
defer cleanup()
defer bolt.Close(ctx)
Expand Down
2 changes: 1 addition & 1 deletion testkit/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def run(args):

if __name__ == "__main__":
package = os.path.join(".", "neo4j", "test-integration", "...")
cmd = ["go", "test", "-buildvcs=false"]
cmd = ["go", "test", "-race", "-buildvcs=false"]
if os.environ.get("TEST_IN_TEAMCITY", False):
cmd = cmd + ["-v", "-json"]
run(cmd + [package])
2 changes: 1 addition & 1 deletion testkit/unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def run(args):
for extra_args in (
(), ("-tags", "internal_time_mock")
):
cmd = ["go", "test", *extra_args]
cmd = ["go", "test", "-race", *extra_args]
if os.environ.get("TEST_IN_TEAMCITY", False):
cmd = cmd + ["-v", "-json"]

Expand Down

0 comments on commit 2341390

Please sign in to comment.