Skip to content

Commit

Permalink
Fix tests that failed when run concurrently
Browse files Browse the repository at this point in the history
go test ./... would often fail because some tests in the main tern
package and the migrate package used the same database.
  • Loading branch information
jackc committed Feb 24, 2023
1 parent ca22c45 commit 554a3d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,17 @@ library can help.

To run the tests tern requires two test databases to run migrations against.

1. Create a new database for main tern program tests.
1. Create a new database for main tern program tests (e.g. `tern_test`).
2. Open testdata/tern.conf.example
3. Enter the connection information.
4. Save as testdata/tern.conf.
5. Create another database for the migrate library tests.
6. Run tests with the connection string for the migrate library tests in the MIGRATE_TEST_CONN_STRING environment variable
4. Run tests with the connection string for the main tern program tests in the TERN_TEST_CONN_STRING environment variable.
5. Save as testdata/tern.conf.
6. Create another database for the migrate library tests (e.g. `tern_migrate_test`).
7. Run tests with the connection string for the migrate library tests in the MIGRATE_TEST_CONN_STRING environment variable

MIGRATE_TEST_CONN_STRING="host=/private/tmp database=tern_migrate_test" go test ./...
```
TERN_TEST_CONN_STRING="host=/private/tmp database=tern_test" MIGRATE_TEST_CONN_STRING="host=/private/tmp database=tern_migrate_test" go test ./...
```

## Prior Ruby Gem Version

Expand Down
2 changes: 1 addition & 1 deletion tern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ version: 0 of 2`
func TestConnStringCLIArg(t *testing.T) {
// Ensure database is in clean state
tern(t, "migrate", "-m", "testdata", "-c", "testdata/tern.conf", "-d", "0")
connString := os.Getenv("MIGRATE_TEST_CONN_STRING")
connString := os.Getenv("TERN_TEST_CONN_STRING")

output := tern(t, "status",
"-m", "testdata",
Expand Down
2 changes: 1 addition & 1 deletion testdata/tern-conn-string.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[database]
conn_string = {{env "MIGRATE_TEST_CONN_STRING"}}
conn_string = {{env "TERN_TEST_CONN_STRING"}}

0 comments on commit 554a3d1

Please sign in to comment.