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-dgraph authored and mangalaman93 committed Mar 14, 2024
1 parent 8251855 commit 2d64827
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 40 deletions.
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 @@ -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
}
28 changes: 15 additions & 13 deletions dgraphtest/local_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,26 +334,28 @@ 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)

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 @@ -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() {
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ require (
go.opencensus.io v0.24.0
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.17.0
golang.org/x/mod v0.13.0
golang.org/x/net v0.17.0
golang.org/x/sync v0.3.0
golang.org/x/sync v0.4.0
golang.org/x/sys v0.15.0
golang.org/x/term v0.15.0
golang.org/x/text v0.14.0
golang.org/x/tools v0.9.3
golang.org/x/tools v0.14.0
google.golang.org/grpc v1.56.3
google.golang.org/protobuf v1.33.0
gopkg.in/square/go-jose.v2 v2.3.1
gopkg.in/yaml.v2 v2.4.0
)
Expand Down Expand Up @@ -140,13 +142,12 @@ 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.12.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // 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
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc/examples v0.0.0-20230821201920-d51b3f41716d // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/DataDog/dd-trace-go.v1 v1.22.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,9 @@ golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 h1:QE6XYQK6naiK1EPAe1g/ILLxN5RBoH5xkJk3CqlMI/Y=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
Expand All @@ -776,8 +777,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -846,8 +847,8 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -994,8 +995,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM=
golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 1 addition & 1 deletion query/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ func TestMain(m *testing.M) {

dc = c
client = dg.Dgraph
populateCluster()
populateCluster(dc)
m.Run()
}
37 changes: 26 additions & 11 deletions query/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -253,14 +254,6 @@ type SchoolInfo {
county
}
type User {
name
password
gender
friend
alive
}
type Node {
node
name
Expand Down Expand Up @@ -346,16 +339,38 @@ 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
// to expect. We need to move the max assigned UID in zero to higher value than
// all the UIDs we are using during the tests.
x.Panic(dc.AssignUids(client.Dgraph, 65536))

setSchema(testSchema)
err := addTriplesToCluster(`
higher, err := dgraphtest.IsHigherVersion(dc.GetVersion(), "160a0faa5fc6233fdc5a4caa4a7a3d1591f460d0")
x.Panic(err)
var ts string
if higher {
ts = testSchema + `type User {
name
password
gender
friend
alive
user_profile
}
user_profile : vfloat @index(hnsw(metric:"euclidian")) .`
} else {
ts = testSchema + `type User {
name
password
gender
friend
alive
}`
}
setSchema(ts)
err = addTriplesToCluster(`
<1> <name> "Michonne" .
<2> <name> "King Lear" .
<3> <name> "Margaret" .
Expand Down
2 changes: 1 addition & 1 deletion query/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
2 changes: 1 addition & 1 deletion query/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestMain(m *testing.M) {

client = dg
dc = c
populateCluster()
populateCluster(dc)
}

query := func(c dgraphtest.Cluster) int {
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 @@ -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)
Expand Down

0 comments on commit 2d64827

Please sign in to comment.