Skip to content

Commit

Permalink
fix(upgrade): fix failing upgrade tests (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaji-kharse authored and mangalaman93 committed Jul 23, 2024
1 parent 7406a0e commit b745471
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 29 deletions.
9 changes: 9 additions & 0 deletions dgraphtest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,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
Expand Down
30 changes: 30 additions & 0 deletions dgraphtest/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strings"

"github.com/pkg/errors"
"golang.org/x/mod/modfile"
)

func (c *LocalCluster) dgraphImage() string {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -229,3 +234,28 @@ func IsHigherVersion(higher, lower string) (bool, error) {

return true, nil
}

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
}
31 changes: 17 additions & 14 deletions dgraphtest/local_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"io"
"log"
"math/rand"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -140,13 +139,15 @@ 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)
zo.aliasName = fmt.Sprintf(zeroAliasNameFmt, zo.id)
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)
Expand Down Expand Up @@ -336,27 +337,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)
}

log.Printf("[INFO] cleaning up the cluster for retrying!")
c.Cleanup(true)
c.conf.prefix = fmt.Sprintf("dgraphtest-%d", rand.NewSource(time.Now().UnixNano()).Int63()%1000000)

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 {
Expand Down
2 changes: 1 addition & 1 deletion ee/acl/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ require (
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.21.0
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
golang.org/x/mod v0.16.0
golang.org/x/net v0.22.0
golang.org/x/sync v0.6.0
golang.org/x/sys v0.18.0
Expand Down Expand Up @@ -142,7 +143,6 @@ require (
github.com/xdg/stringprep v1.0.3 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/api v0.122.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
Expand Down
2 changes: 1 addition & 1 deletion query/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,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) }()

Expand Down
22 changes: 11 additions & 11 deletions query/rdf_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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> <name> "Michonne" .
<0x1> <friend> <0x17> .
Expand Down Expand Up @@ -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")
}

Expand All @@ -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")
}

Expand All @@ -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")
}

Expand All @@ -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")
}
Expand All @@ -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> <name> "Michonne" .
<0x17> <name> "Rick Grimes" .
Expand All @@ -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> <name> "Michonne" .
<0x17> <name> "Rick Grimes" .
Expand All @@ -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")
}
Expand All @@ -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> <name> "Michonne" .
<0x17> <name> "Rick Grimes" .
Expand Down Expand Up @@ -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")
}
Expand All @@ -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> <name> "Michonne" .
<0x1> <gender> "female" .
Expand Down
2 changes: 1 addition & 1 deletion systest/multi-tenancy/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,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)
Expand Down

0 comments on commit b745471

Please sign in to comment.