diff --git a/systest/ldbc/integration_helper_test.go b/systest/ldbc/integration_helper_test.go new file mode 100644 index 00000000000..fa0580c2efc --- /dev/null +++ b/systest/ldbc/integration_helper_test.go @@ -0,0 +1,45 @@ +//go:build integration + +/* + * Copyright 2023 Dgraph Labs, Inc. and Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "github.com/dgraph-io/dgraph/testutil" +) + +func (lsuite *TOMldbcTestSuite) bulkLoader() error { + noschemaFile := filepath.Join(testutil.TestDataDirectory, "ldbcTypes.schema") + rdfFile := testutil.TestDataDirectory + require.NoError(t, testutil.MakeDirEmpty([]string{"out/0"})) + start := time.Now() + return testutil.BulkLoad(testutil.BulkOpts{ + Zero: testutil.SockAddrZero, + Shards: 1, + RdfFile: rdfFile, + SchemaFile: noschemaFile, + }) + fmt.Printf("Took %s to bulkupload LDBC dataset\n", time.Since(start)) +} + +func (lsuite *TOMldbcTestSuite) StartAlphas() error { + return testutil.StartAlphas("./alpha.yml") +} + +func (lsuite *TOMldbcTestSuite) StopAlphasForCoverage() { + testutil.StopAlphasForCoverage("./alpha.yml") +} diff --git a/systest/ldbc/integration_test.go b/systest/ldbc/integration_test.go new file mode 100644 index 00000000000..266b45f8393 --- /dev/null +++ b/systest/ldbc/integration_test.go @@ -0,0 +1,49 @@ +//go:build integration + +/* + * Copyright 2023 Dgraph Labs, Inc. and Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "testing" + + "github.com/stretchr/testify/suite" + + "github.com/dgraph-io/dgraph/dgraphtest" + "github.com/dgraph-io/dgraph/testutil" +) + +type TOMldbcTestSuite struct { + suite.Suite + dc dgraphtest.Cluster +} + +func (lsuite *TOMldbcTestSuite) SetupTest() { + lsuite.dc = dgraphtest.NewComposeCluster() +} + +func (lsuite *TOMldbcTestSuite) TearDownTest() { + testutil.DetectRaceInAlphas(testutil.DockerPrefix) +} + +func (lsuite *TOMldbcTestSuite) Upgrade() { + // Not implemented for integration tests +} + +func TestTOMldbcTestSuite(t *testing.T) { + suite.Run(t, new(TOMldbcTestSuite)) +} diff --git a/systest/ldbc/ldbc_test.go b/systest/ldbc/ldbc_test.go index 01167db78b4..23dfffb0a0c 100644 --- a/systest/ldbc/ldbc_test.go +++ b/systest/ldbc/ldbc_test.go @@ -1,19 +1,16 @@ -//go:build integration +//go:build integration || upgrade package main import ( "context" - "fmt" "os" - "path/filepath" - "testing" "time" "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" - "github.com/dgraph-io/dgraph/testutil" + "github.com/dgraph-io/dgraph/dgraphtest" ) type TestCases struct { @@ -27,11 +24,9 @@ var ( EXPECTED_COVERAGE_ENV = "--test.coverprofile=coverage.out" ) -func TestQueries(t *testing.T) { - dg, err := testutil.DgraphClient(testutil.ContainerAddr("alpha1", 9080)) - if err != nil { - t.Fatalf("Error while getting a dgraph client: %v", err) - } +func (lsuite *TOMldbcTestSuite) TestQueries() { + t := lsuite.T() + yfile, _ := os.ReadFile("test_cases.yaml") tc := make(map[string]TestCases) @@ -53,58 +48,30 @@ func TestQueries(t *testing.T) { if desc == "IC06" || desc == "IC10" { continue } - t.Run(desc, func(t *testing.T) { + lsuite.Run(desc, func() { + t := lsuite.T() + require.NoError(t, lsuite.bulkLoader()) + + require.NoError(t, lsuite.StartAlpha()) + + // Upgrade + lsuite.Upgrade() + + dg, cleanup, err := lsuite.dc.Client() + defer cleanup() + require.NoError(t, err) + resp, err := dg.NewTxn().Query(ctx, tt.Query) require.NoError(t, err) - testutil.CompareJSON(t, tt.Resp, string(resp.Json)) + dgraphtest.CompareJSON(tt.Resp, string(resp.Json)) }) if ctx.Err() == context.DeadlineExceeded { t.Fatal("aborting test due to query timeout") } } cancel() -} - -func TestMain(m *testing.M) { - noschemaFile := filepath.Join(testutil.TestDataDirectory, "ldbcTypes.schema") - rdfFile := testutil.TestDataDirectory - if err := testutil.MakeDirEmpty([]string{"out/0"}); err != nil { - os.Exit(1) - } - start := time.Now() - fmt.Println("Bulkupload started") - if err := testutil.BulkLoad(testutil.BulkOpts{ - Zero: testutil.SockAddrZero, - Shards: 1, - RdfFile: rdfFile, - SchemaFile: noschemaFile, - }); err != nil { - fmt.Println(err) - cleanupAndExit(1) - } - - fmt.Printf("Took %s to bulkupload LDBC dataset\n", time.Since(start)) - - if err := testutil.StartAlphas("./alpha.yml"); err != nil { - fmt.Printf("Error while bringin up alphas. Error: %v\n", err) - cleanupAndExit(1) - } - - exitCode := m.Run() - cleanupAndExit(exitCode) -} - -func cleanupAndExit(exitCode int) { if cc := os.Getenv(COVERAGE_FLAG); cc == EXPECTED_COVERAGE_ENV { - testutil.StopAlphasForCoverage("./alpha.yml") - os.Exit(exitCode) - } - - if testutil.StopAlphasAndDetectRace([]string{"alpha1"}) { - // if there is race fail the test - exitCode = 1 + lsuite.StopAlphasForCoverage() } - _ = os.RemoveAll("out") - os.Exit(exitCode) } diff --git a/systest/ldbc/upgrade_helper_test.go b/systest/ldbc/upgrade_helper_test.go new file mode 100644 index 00000000000..34b9082d09a --- /dev/null +++ b/systest/ldbc/upgrade_helper_test.go @@ -0,0 +1,48 @@ +//go:build upgrade + +/* + * Copyright 2023 Dgraph Labs, Inc. and Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "os" + "path/filepath" + + "github.com/dgraph-io/dgraph/dgraphtest" +) + +func (lsuite *TOMldbcTestSuite) bulkLoader() error { + dataDir := os.Getenv("TEST_DATA_DIRECTORY") + rdfFile := dataDir + schemaFile := filepath.Join(dataDir, "ldbcTypes.schema") + return lsuite.lc.BulkLoad(dgraphtest.BulkOpts{ + DataFiles: []string{rdfFile}, + SchemaFiles: []string{schemaFile}, + }) +} + +func (lsuite *TOMldbcTestSuite) StartAlpha() error { + c := lsuite.lc + if err := c.Start(); err != nil { + return err + } + return c.HealthCheck(false) +} + +func (lsuite *TOMldbcTestSuite) StopAlphasForCoverage() { + lsuite.lc.StopAlpha(0) +} diff --git a/systest/ldbc/upgrade_test.go b/systest/ldbc/upgrade_test.go new file mode 100644 index 00000000000..d48d635ce0e --- /dev/null +++ b/systest/ldbc/upgrade_test.go @@ -0,0 +1,82 @@ +//go:build upgrade + +/* + * Copyright 2023 Dgraph Labs, Inc. and Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + "testing" + + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "github.com/dgraph-io/dgraph/dgraphtest" + "github.com/dgraph-io/dgraph/x" +) + +type TOMldbcTestSuite struct { + suite.Suite + dc dgraphtest.Cluster + lc *dgraphtest.LocalCluster + uc dgraphtest.UpgradeCombo +} + +func (lsuite *TOMldbcTestSuite) SetupSubTest() { + t := lsuite.T() + lsuite.lc.Cleanup(t.Failed()) + + conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1).WithReplicas(1). + WithVersion(lsuite.uc.Before).WithBulkLoadOutDir(t.TempDir()). + WithPostingListDir("/posting").WithDetectRace() + c, err := dgraphtest.NewLocalCluster(conf) + x.Panic(err) + + // start zero + if err := c.StartZero(0); err != nil { + c.Cleanup(true) + panic(err) + } + + if err := c.HealthCheck(true); err != nil { + c.Cleanup(true) + panic(err) + } + + lsuite.dc = c + lsuite.lc = c +} + +func (lsuite *TOMldbcTestSuite) TearDownTest() { + lsuite.lc.Cleanup(lsuite.T().Failed()) +} + +func (lsuite *TOMldbcTestSuite) Upgrade() { + require.NoError(lsuite.T(), lsuite.lc.Upgrade(lsuite.uc.After, lsuite.uc.Strategy)) +} + +func TestTOMldbcTestSuite(t *testing.T) { + for _, uc := range dgraphtest.AllUpgradeCombos() { + log.Printf("running upgrade tests for confg: %+v", uc) + var lsuite TOMldbcTestSuite + lsuite.uc = uc + suite.Run(t, &lsuite) + if t.Failed() { + panic("TestTOMldbcTestSuite tests failed") + } + } +}