Skip to content

Commit

Permalink
db: support concurrency in TestIngestValidation
Browse files Browse the repository at this point in the history
Currently, `TestIngestValidation` ingests a file from the local
filesystem. The ingested file uses a path that remains the same across
test runs. This limits the ability of the test to run in parallel.

Alter the test to use `t.TempDir()` to ensure that the path is unique
across test runs.

Fix #2640.
  • Loading branch information
nicktrav authored and RaduBerinde committed Jun 18, 2023
1 parent 1a7fe39 commit 6746f41
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ingest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"math"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -2220,6 +2221,7 @@ func TestIngestValidation(t *testing.T) {

ingestTableName = "ext"
)
ingestPath := filepath.Join(t.TempDir(), ingestTableName)

seed := uint64(time.Now().UnixNano())
rng := rand.New(rand.NewSource(seed))
Expand Down Expand Up @@ -2298,7 +2300,7 @@ func TestIngestValidation(t *testing.T) {
}
bh := l.Data[blockIdx]

osF, err := os.OpenFile(ingestTableName, os.O_RDWR, 0600)
osF, err := os.OpenFile(ingestPath, os.O_RDWR, 0600)
require.NoError(t, err)
defer func() { require.NoError(t, osF.Close()) }()

Expand All @@ -2320,9 +2322,9 @@ func TestIngestValidation(t *testing.T) {
// Create a disk-backed file outside of the DB FS that we can
// open as a regular os.File, if required.
tmpFS := vfs.Default
f, err := tmpFS.Create(ingestTableName)
f, err := tmpFS.Create(ingestPath)
require.NoError(t, err)
defer func() { _ = tmpFS.Remove(ingestTableName) }()
defer func() { _ = tmpFS.Remove(ingestPath) }()

w := sstable.NewWriter(objstorageprovider.NewFileWritable(f), sstable.WriterOptions{
BlockSize: blockSize, // Create many smaller blocks.
Expand All @@ -2335,13 +2337,13 @@ func TestIngestValidation(t *testing.T) {

// Possibly corrupt the file.
if tc.cLoc != corruptionLocationNone {
f, err = tmpFS.Open(ingestTableName)
f, err = tmpFS.Open(ingestPath)
require.NoError(t, err)
corrupt(f)
}

// Copy the file into the DB's FS.
_, err = vfs.Clone(tmpFS, fs, ingestTableName, ingestTableName)
_, err = vfs.Clone(tmpFS, fs, ingestPath, ingestTableName)
require.NoError(t, err)

// Ingest the external table.
Expand Down

0 comments on commit 6746f41

Please sign in to comment.