diff --git a/internal/worker/upstream_buffer_test.go b/internal/worker/upstream_buffer_test.go index 7348d939..ac4df6d8 100644 --- a/internal/worker/upstream_buffer_test.go +++ b/internal/worker/upstream_buffer_test.go @@ -5,7 +5,7 @@ package worker import ( "context" "errors" - "os" + "fmt" "testing" "github.com/benbjohnson/clock" @@ -17,8 +17,6 @@ import ( "git.blender.org/flamenco/pkg/api" ) -const testBufferDBFilename = ":memory:" - type UpstreamBufferDBMocks struct { client *mocks.MockFlamencoClient clock *clock.Mock @@ -30,9 +28,6 @@ func mockUpstreamBufferDB(t *testing.T, mockCtrl *gomock.Controller) (*UpstreamB clock: clock.NewMock(), } - // Always start tests with a fresh database. - os.Remove(testBufferDBFilename) - ub, err := NewUpstreamBuffer(mocks.client, mocks.clock) if err != nil { t.Fatalf("unable to create upstream buffer: %v", err) @@ -41,6 +36,13 @@ func mockUpstreamBufferDB(t *testing.T, mockCtrl *gomock.Controller) (*UpstreamB return ub, &mocks } +// sqliteTestDBName returns a DSN for SQLite that separates tests from each +// other, but lets all connections made within the same test to connect to the +// same in-memory instance. +func sqliteTestDBName(t *testing.T) string { + return fmt.Sprintf("file:%s?mode=memory&cache=shared", t.Name()) +} + func TestUpstreamBufferCloseUnopened(t *testing.T) { mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() @@ -57,7 +59,7 @@ func TestUpstreamBufferManagerUnavailable(t *testing.T) { ctx := context.Background() ub, mocks := mockUpstreamBufferDB(t, mockCtrl) - assert.NoError(t, ub.OpenDB(ctx, testBufferDBFilename)) + assert.NoError(t, ub.OpenDB(ctx, sqliteTestDBName(t))) // Send a task update without Manager available. taskID := "3960dec4-978e-40ab-bede-bfa6428c6ebc"