Closed djjuhasz closed 2 days ago
I also tried treating bagit.NewBagIt()
as a singleton, by moving the constructor and cleanup to the main test function:
func TestValidateBag(t *testing.T) {
t.Parallel()
b, err := bagit.NewBagIt()
assert.NilError(t, err)
t.Cleanup(func() {
err = b.Cleanup()
assert.NilError(t, err)
})
t.Run("Fails validation", func(t *testing.T) {
t.Parallel()
err = b.Validate("/tmp/691b8e7f-e6b7-41dd-bc47-868e2ff69333")
assert.Error(t, err, "invalid: Expected bagit.txt does not exist: /tmp/691b8e7f-e6b7-41dd-bc47-868e2ff69333/bagit.txt")
})
t.Run("Validates bag", func(t *testing.T) {
t.Parallel()
err = b.Validate("internal/testdata/valid-bag")
assert.NilError(t, err)
})
}
The tests passed in this case:
❯ go test ./...
? github.com/artefactual-labs/bagit-gython/internal/dist [no test files]
? github.com/artefactual-labs/bagit-gython/internal/dist/data [no test files]
? github.com/artefactual-labs/bagit-gython/internal/dist/generate [no test files]
? github.com/artefactual-labs/bagit-gython/internal/runner [no test files]
ok github.com/artefactual-labs/bagit-gython 1.819s
When
(*bagit.Bag).Validate()
is run in two separate threads at the same time (e.g. via parallel tests) validation fails with a fatal Python error.Test file
Results
Additional information
If I remove one or more of the
t.Parallel()
calls from the test file, then the tests pass without error