diff --git a/dgraphtest/config.go b/dgraphtest/config.go index d1c568c1f46..94ad94bcead 100644 --- a/dgraphtest/config.go +++ b/dgraphtest/config.go @@ -141,6 +141,15 @@ func NewClusterConfig() ClusterConfig { } } +func newClusterConfigFrom(cc ClusterConfig) ClusterConfig { + prefix := fmt.Sprintf("dgraphtest-%d", rand.NewSource(time.Now().UnixNano()).Int63()%1000000) + defaultBackupVol := fmt.Sprintf("%v_backup", prefix) + defaultExportVol := fmt.Sprintf("%v_export", prefix) + cc.prefix = prefix + cc.volumes = map[string]string{DefaultBackupDir: defaultBackupVol, DefaultExportDir: defaultExportVol} + return cc +} + // WithNAlphas sets the number of alphas in the cluster func (cc ClusterConfig) WithNumAlphas(n int) ClusterConfig { cc.numAlphas = n diff --git a/dgraphtest/image.go b/dgraphtest/image.go index 06261fe8404..4a2e0cd632f 100644 --- a/dgraphtest/image.go +++ b/dgraphtest/image.go @@ -26,6 +26,7 @@ import ( "strings" "github.com/pkg/errors" + "golang.org/x/mod/modfile" ) func (c *LocalCluster) dgraphImage() string { @@ -151,6 +152,10 @@ func getHash(ref string) (string, error) { func buildDgraphBinary(dir, binaryDir, version string) error { log.Printf("[INFO] building dgraph binary for version [%v]", version) + if err := fixGoModIfNeeded(); err != nil { + return err + } + cmd := exec.Command("make", "dgraph") cmd.Dir = filepath.Join(dir, "dgraph") if out, err := cmd.CombinedOutput(); err != nil { @@ -204,3 +209,28 @@ func copy(src, dst string) error { _, err = io.Copy(destination, source) return err } + +func fixGoModIfNeeded() error { + repoModFilePath := filepath.Join(repoDir, "go.mod") + repoModFile, err := modfile.Parse(repoModFilePath, nil, nil) + if err != nil { + return errors.Wrapf(err, "error parsing mod file in repoDir [%v]", repoDir) + } + + modFile, err := modfile.Parse("go.mod", nil, nil) + if err != nil { + return errors.Wrapf(err, "error while parsing go.mod file") + } + + if len(modFile.Replace) == len(repoModFile.Replace) { + return nil + } + + repoModFile.Replace = modFile.Replace + if data, err := repoModFile.Format(); err != nil { + return errors.Wrapf(err, "error while formatting mod file") + } else if err := os.WriteFile(repoModFilePath, data, 0644); err != nil { + return errors.Wrapf(err, "error while writing to go.mod file") + } + return nil +} diff --git a/dgraphtest/local_cluster.go b/dgraphtest/local_cluster.go index 3593c54b593..979c2b8c296 100644 --- a/dgraphtest/local_cluster.go +++ b/dgraphtest/local_cluster.go @@ -138,6 +138,7 @@ func (c *LocalCluster) init() error { } } + c.zeros = c.zeros[:0] for i := 0; i < c.conf.numZeros; i++ { zo := &zero{id: i} zo.containerName = fmt.Sprintf(zeroNameFmt, c.conf.prefix, zo.id) @@ -145,6 +146,7 @@ func (c *LocalCluster) init() error { c.zeros = append(c.zeros, zo) } + c.alphas = c.alphas[:0] for i := 0; i < c.conf.numAlphas; i++ { aa := &alpha{id: i} aa.containerName = fmt.Sprintf(alphaNameFmt, c.conf.prefix, aa.id) @@ -334,26 +336,29 @@ func (c *LocalCluster) Start() error { return c.HealthCheck(false) } - var err error - // sometimes health check doesn't work due to unmapped ports. We dont know why this happens, - // but checking it 4 times before failing the test. - for i := 0; i < 4; i++ { + // sometimes health check doesn't work due to unmapped ports. We dont + // know why this happens, but checking it 3 times before failing the test. + retry := 0 + for { + retry++ - if err = startAll(); err == nil { + if err := startAll(); err == nil { return nil + } else if retry == 3 { + return err + } else { + log.Printf("[WARNING] saw the err, trying again: %v", err) } - log.Printf("[WARNING] Saw the error :%v, trying again", err) - if err1 := c.Stop(); err1 != nil { - log.Printf("[WARNING] error while stopping :%v", err) - } - c.Cleanup(false) + + log.Printf("[INFO] cleaning up the cluster for retrying!") + c.Cleanup(true) + + c.conf = newClusterConfigFrom(c.conf) if err := c.init(); err != nil { - c.Cleanup(true) + log.Printf("[ERROR] error while init, returning: %v", err) return err } } - - return err } func (c *LocalCluster) StartZero(id int) error { diff --git a/ee/acl/upgrade_test.go b/ee/acl/upgrade_test.go index cdc2774ee3e..2142ebafd63 100644 --- a/ee/acl/upgrade_test.go +++ b/ee/acl/upgrade_test.go @@ -54,7 +54,7 @@ func (asuite *AclTestSuite) Upgrade() { func TestACLSuite(t *testing.T) { for _, uc := range dgraphtest.AllUpgradeCombos(true) { - log.Printf("running upgrade tests for confg: %+v", uc) + log.Printf("running upgrade tests for config: %+v", uc) aclSuite := AclTestSuite{uc: uc} suite.Run(t, &aclSuite) if t.Failed() { diff --git a/go.mod b/go.mod index 85ffd6cf703..531b4586e69 100644 --- a/go.mod +++ b/go.mod @@ -58,6 +58,7 @@ require ( go.opencensus.io v0.24.0 go.uber.org/zap v1.16.0 golang.org/x/crypto v0.19.0 + golang.org/x/mod v0.15.0 golang.org/x/net v0.21.0 golang.org/x/sync v0.6.0 golang.org/x/sys v0.17.0 @@ -142,7 +143,6 @@ require ( go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.10.0 // indirect golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect - golang.org/x/mod v0.15.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/api v0.122.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/query/cloud_test.go b/query/cloud_test.go index 9aea8b04e3e..fae5ff42e17 100644 --- a/query/cloud_test.go +++ b/query/cloud_test.go @@ -41,6 +41,6 @@ func TestMain(m *testing.M) { dc = c client = dg.Dgraph - populateCluster() + populateCluster(dc) m.Run() } diff --git a/query/common_test.go b/query/common_test.go index 78c6ce64ea5..9a511103699 100644 --- a/query/common_test.go +++ b/query/common_test.go @@ -29,6 +29,7 @@ import ( "github.com/stretchr/testify/require" "github.com/dgraph-io/dgo/v230/protos/api" + "github.com/dgraph-io/dgraph/dgraphtest" "github.com/dgraph-io/dgraph/x" ) @@ -74,7 +75,7 @@ func processQuery(ctx context.Context, t *testing.T, query string) (string, erro return string(jsonResponse), err } -func processQueryRDF(ctx context.Context, t *testing.T, query string) (string, error) { +func processQueryRDF(ctx context.Context, query string) (string, error) { txn := client.NewTxn() defer func() { _ = txn.Discard(ctx) }() @@ -346,7 +347,7 @@ name2 : string @index(term) . age2 : int @index(int) . ` -func populateCluster() { +func populateCluster(dc dgraphtest.Cluster) { x.Panic(client.Alter(context.Background(), &api.Operation{DropAll: true})) // In the query package, we test using hard coded UIDs so that we know what results diff --git a/query/integration_test.go b/query/integration_test.go index 901a1d11442..b05b2ae8bed 100644 --- a/query/integration_test.go +++ b/query/integration_test.go @@ -37,6 +37,6 @@ func TestMain(m *testing.M) { x.Panic(client.LoginIntoNamespace(context.Background(), dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace)) - populateCluster() + populateCluster(dc) m.Run() } diff --git a/query/rdf_result_test.go b/query/rdf_result_test.go index c9e6b9fc0c8..d7ac107c158 100644 --- a/query/rdf_result_test.go +++ b/query/rdf_result_test.go @@ -36,7 +36,7 @@ func TestRDFResult(t *testing.T) { } }` - rdf, err := processQueryRDF(context.Background(), t, query) + rdf, err := processQueryRDF(context.Background(), query) require.NoError(t, err) require.Equal(t, rdf, `<0x1> "Michonne" . <0x1> <0x17> . @@ -69,7 +69,7 @@ func TestRDFNormalize(t *testing.T) { } } }` - _, err := processQueryRDF(context.Background(), t, query) + _, err := processQueryRDF(context.Background(), query) require.Error(t, err, "normalize directive is not supported in the rdf output format") } @@ -80,7 +80,7 @@ func TestRDFGroupBy(t *testing.T) { count(uid) } }` - _, err := processQueryRDF(context.Background(), t, query) + _, err := processQueryRDF(context.Background(), query) require.Contains(t, err.Error(), "groupby is not supported in rdf output format") } @@ -91,7 +91,7 @@ func TestRDFUidCount(t *testing.T) { count(uid) } }` - _, err := processQueryRDF(context.Background(), t, query) + _, err := processQueryRDF(context.Background(), query) require.Contains(t, err.Error(), "uid count is not supported in the rdf output format") } @@ -108,7 +108,7 @@ func TestRDFIngoreReflex(t *testing.T) { } } }` - _, err := processQueryRDF(context.Background(), t, query) + _, err := processQueryRDF(context.Background(), query) require.Contains(t, err.Error(), "ignorereflex directive is not supported in the rdf output format") } @@ -121,7 +121,7 @@ func TestRDFRecurse(t *testing.T) { friend } }` - rdf, err := processQueryRDF(context.Background(), t, query) + rdf, err := processQueryRDF(context.Background(), query) require.NoError(t, err) require.Equal(t, rdf, `<0x1> "Michonne" . <0x17> "Rick Grimes" . @@ -137,7 +137,7 @@ func TestRDFIgnoreUid(t *testing.T) { name } }` - rdf, err := processQueryRDF(context.Background(), t, query) + rdf, err := processQueryRDF(context.Background(), query) require.NoError(t, err) require.Equal(t, rdf, `<0x1> "Michonne" . <0x17> "Rick Grimes" . @@ -154,7 +154,7 @@ func TestRDFCheckPwd(t *testing.T) { } } ` - _, err := processQueryRDF(context.Background(), t, query) + _, err := processQueryRDF(context.Background(), query) require.Contains(t, err.Error(), "chkpwd function is not supported in the rdf output format") } @@ -172,7 +172,7 @@ func TestRDFPredicateCount(t *testing.T) { } ` - rdf, err := processQueryRDF(context.Background(), t, query) + rdf, err := processQueryRDF(context.Background(), query) require.NoError(t, err) require.Equal(t, `<0x1> "Michonne" . <0x17> "Rick Grimes" . @@ -201,7 +201,7 @@ func TestRDFFacets(t *testing.T) { path @facets(weight) } }` - _, err := processQueryRDF(context.Background(), t, query) + _, err := processQueryRDF(context.Background(), query) require.Contains(t, err.Error(), "facets are not supported in the rdf output format") } @@ -219,7 +219,7 @@ func TestDateRDF(t *testing.T) { } } ` - rdf, err := processQueryRDF(context.Background(), t, query) + rdf, err := processQueryRDF(context.Background(), query) require.NoError(t, err) expected := `<0x1> "Michonne" . <0x1> "female" . diff --git a/query/upgrade_test.go b/query/upgrade_test.go index 51c3e7253f5..69dd62e4c44 100644 --- a/query/upgrade_test.go +++ b/query/upgrade_test.go @@ -39,7 +39,7 @@ func TestMain(m *testing.M) { client = dg dc = c - populateCluster() + populateCluster(dc) } query := func(c dgraphtest.Cluster) int { diff --git a/systest/multi-tenancy/upgrade_test.go b/systest/multi-tenancy/upgrade_test.go index e3f0e4fff46..57f28375624 100644 --- a/systest/multi-tenancy/upgrade_test.go +++ b/systest/multi-tenancy/upgrade_test.go @@ -61,7 +61,7 @@ func (msuite *MultitenancyTestSuite) Upgrade() { func TestMultitenancySuite(t *testing.T) { for _, uc := range dgraphtest.AllUpgradeCombos(false) { - log.Printf("running upgrade tests for confg: %+v", uc) + log.Printf("running upgrade tests for config: %+v", uc) var msuite MultitenancyTestSuite msuite.uc = uc suite.Run(t, &msuite)