Skip to content

Commit

Permalink
importccl: Bazelify importccl test.
Browse files Browse the repository at this point in the history
Make importccl test hermetic by using correct directories
and avoiding test data regeneration.

Use 16 shards for the test to speed it up.

Release Notes: None
  • Loading branch information
Yevgeniy Miretskiy committed Oct 29, 2020
1 parent dd162fe commit 44cc0ed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
1 change: 1 addition & 0 deletions pkg/ccl/importccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ go_test(
],
data = glob(["testdata/**"]),
embed = [":importccl"],
shard_count = 16,
deps = [
"//pkg/base",
"//pkg/blobs",
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/importccl/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func BenchmarkImportWorkload(b *testing.B) {
skip.WithIssue(b, 41932, "broken due to adding keys out-of-order to an sstable")
skip.UnderShort(b, "skipping long benchmark")

dir, cleanup := testutils.TempDir(b)
dir, cleanup := testutils.TestTempDir(b)
defer cleanup()

g := tpcc.FromWarehouses(1)
Expand Down
31 changes: 5 additions & 26 deletions pkg/ccl/importccl/import_stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ func TestImportUserDefinedTypes(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
ctx := context.Background()
baseDir, cleanup := testutils.TempDir(t)
baseDir, cleanup := testutils.TestTempDir(t)
defer cleanup()
tc := testcluster.StartTestCluster(
t, 1, base.TestClusterArgs{ServerArgs: base.TestServerArgs{ExternalIODir: baseDir}})
Expand Down Expand Up @@ -1379,7 +1379,7 @@ func TestImportCSVStmt(t *testing.T) {
blockGC := make(chan struct{})

ctx := context.Background()
baseDir := filepath.Join("testdata", "csv")
baseDir := filepath.Join(testutils.TestSrcDir(), testDataPath, "csv")
tc := testcluster.StartTestCluster(t, nodes, base.TestClusterArgs{ServerArgs: base.TestServerArgs{
SQLMemoryPoolSize: 256 << 20,
ExternalIODir: baseDir,
Expand Down Expand Up @@ -1419,27 +1419,7 @@ func TestImportCSVStmt(t *testing.T) {
}

// Table schema used in IMPORT TABLE tests.
tablePath := filepath.Join(baseDir, "table")
if err := ioutil.WriteFile(tablePath, []byte(`
CREATE TABLE t (
a int8 primary key,
b string,
index (b),
index (a, b)
)
`), 0666); err != nil {
t.Fatal(err)
}
schema := []interface{}{"nodelocal://0/table"}

if err := ioutil.WriteFile(filepath.Join(baseDir, "empty.csv"), nil, 0666); err != nil {
t.Fatal(err)
}

if err := ioutil.WriteFile(filepath.Join(baseDir, "empty.schema"), nil, 0666); err != nil {
t.Fatal(err)
}

empty := []string{"'nodelocal://0/empty.csv'"}
emptySchema := []interface{}{"nodelocal://0/empty.schema"}

Expand Down Expand Up @@ -2244,6 +2224,8 @@ func TestExportImportRoundTrip(t *testing.T) {
}
}

var testDataPath = filepath.Join("cockroach", "pkg", "ccl", "importccl", "testdata")

// TODO(adityamaru): Tests still need to be added incrementally as
// relevant IMPORT INTO logic is added. Some of them include:
// -> FK and constraint violation
Expand All @@ -2262,7 +2244,7 @@ func TestImportIntoCSV(t *testing.T) {
rowsPerRaceFile := 16

ctx := context.Background()
baseDir := filepath.Join("testdata", "csv")
baseDir := filepath.Join(testutils.TestSrcDir(), testDataPath, "csv")
tc := testcluster.StartTestCluster(t, nodes, base.TestClusterArgs{ServerArgs: base.TestServerArgs{ExternalIODir: baseDir}})
defer tc.Stopper().Stop(ctx)
conn := tc.Conns[0]
Expand Down Expand Up @@ -2305,9 +2287,6 @@ func TestImportIntoCSV(t *testing.T) {
rowsPerFile = rowsPerRaceFile
}

if err := ioutil.WriteFile(filepath.Join(baseDir, "empty.csv"), nil, 0666); err != nil {
t.Fatal(err)
}
empty := []string{"'nodelocal://0/empty.csv'"}

// Support subtests by keeping track of the number of jobs that are executed.
Expand Down

0 comments on commit 44cc0ed

Please sign in to comment.