fix: possible race on shared variables in test (#9470)

Fixes #9433

Signed-off-by: Furkan <furkan.turkal@trendyol.com>
This commit is contained in:
Furkan Türkal 2021-10-25 16:14:40 +03:00 committed by GitHub
parent d5bfbe3114
commit 0c07663b70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -663,6 +663,7 @@ func TestDB_SnapshotWithDelete(t *testing.T) {
numSamples := int64(10) numSamples := int64(10)
db := openTestDB(t, nil, nil) db := openTestDB(t, nil, nil)
defer func() { require.NoError(t, db.Close()) }()
ctx := context.Background() ctx := context.Background()
app := db.Appender(ctx) app := db.Appender(ctx)
@ -700,15 +701,14 @@ Outer:
require.NoError(t, os.RemoveAll(snap)) require.NoError(t, os.RemoveAll(snap))
}() }()
require.NoError(t, db.Snapshot(snap, true)) require.NoError(t, db.Snapshot(snap, true))
require.NoError(t, db.Close())
// reopen DB from snapshot // reopen DB from snapshot
db, err = Open(snap, nil, nil, nil, nil) newDB, err := Open(snap, nil, nil, nil, nil)
require.NoError(t, err) require.NoError(t, err)
defer func() { require.NoError(t, db.Close()) }() defer func() { require.NoError(t, newDB.Close()) }()
// Compare the result. // Compare the result.
q, err := db.Querier(context.TODO(), 0, numSamples) q, err := newDB.Querier(context.TODO(), 0, numSamples)
require.NoError(t, err) require.NoError(t, err)
defer func() { require.NoError(t, q.Close()) }() defer func() { require.NoError(t, q.Close()) }()