Skip to content

Commit

Permalink
fix(upgrade): fix failing upgrade tests (#76)
Browse files Browse the repository at this point in the history
Co-authored-by: Aman Mangal <aman@dgraph.io>
  • Loading branch information
shivaji-kharse and mangalaman93 authored Jan 11, 2024
1 parent b419266 commit c4e0203
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 18 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 @@ -145,6 +146,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 @@ -198,3 +203,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
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ require (
go.opencensus.io v0.24.0
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.14.0
golang.org/x/mod v0.13.0
golang.org/x/net v0.16.0
golang.org/x/sync v0.4.0
golang.org/x/sys v0.13.0
golang.org/x/term v0.13.0
golang.org/x/text v0.13.0
golang.org/x/tools v0.14.0
google.golang.org/grpc v1.56.2
google.golang.org/protobuf v1.31.0
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/square/go-jose.v2 v2.3.1
gopkg.in/yaml.v2 v2.4.0
)
Expand Down Expand Up @@ -145,7 +146,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-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/api v0.122.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
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()
}
39 changes: 26 additions & 13 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,15 +254,6 @@ type SchoolInfo {
county
}
type User {
name
password
gender
friend
alive
user_profile
}
type Node {
node
name
Expand Down Expand Up @@ -345,19 +337,40 @@ tweet-c : string @index(fulltext) .
tweet-d : string @index(trigram) .
name2 : string @index(term) .
age2 : int @index(int) .
user_profile : vfloat @index(hnsw(metric:"euclidian")) .
`

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

0 comments on commit c4e0203

Please sign in to comment.