Skip to content

Commit 660d1f5

Browse files
committed
tests(upgrade): add upgrade tests in query package
1 parent 833ecc9 commit 660d1f5

19 files changed

+4093
-17
lines changed

dgraphtest/cluster.go

+53
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ import (
2121
"encoding/json"
2222
"fmt"
2323
"strings"
24+
"testing"
2425
"time"
2526

27+
"github.com/go-git/go-git/v5"
28+
"github.com/go-git/go-git/v5/plumbing"
2629
"github.com/pkg/errors"
2730

2831
"github.com/dgraph-io/dgo/v210"
@@ -43,6 +46,7 @@ type Cluster interface {
4346
AdminPost(body []byte) ([]byte, error)
4447
AlphasHealth() ([]string, error)
4548
AssignUids(num uint64) error
49+
GetVersion() string
4650
}
4751

4852
func SetupSchema(c Cluster, dbSchema string) error {
@@ -239,3 +243,52 @@ loop:
239243
return nil
240244
}
241245
}
246+
247+
func ShouldSkipTest(t *testing.T, minVersion, clusterVersion string) error {
248+
if clusterVersion == localVersion {
249+
return nil
250+
}
251+
252+
isParentCommit, err := isParent(minVersion, clusterVersion)
253+
if err != nil {
254+
t.Fatal(err)
255+
}
256+
if isParentCommit {
257+
t.Skipf("test is valid for commits greater than [%v]", minVersion)
258+
}
259+
260+
return nil
261+
}
262+
263+
// isParent checks whether ancestor is the ancestor commit of the given descendant commit.
264+
func isParent(ancestor, descendant string) (bool, error) {
265+
repo, err := git.PlainOpen(repoDir)
266+
if err != nil {
267+
return false, errors.Wrap(err, "error opening git repo")
268+
}
269+
270+
ancestorHash, err := repo.ResolveRevision(plumbing.Revision(ancestor))
271+
if err != nil {
272+
return false, errors.Wrapf(err, "error while getting reference of [%v]", ancestor)
273+
}
274+
ancestorCommit, err := repo.CommitObject(*ancestorHash)
275+
if err != nil {
276+
return false, errors.Wrapf(err, "error finding commit object [%v]", ancestor)
277+
}
278+
279+
descendantHash, err := repo.ResolveRevision(plumbing.Revision(descendant))
280+
if err != nil {
281+
return false, err
282+
}
283+
descendantCommit, err := repo.CommitObject(*descendantHash)
284+
if err != nil {
285+
return false, errors.Wrapf(err, "error finding commit object [%v]", descendant)
286+
}
287+
288+
isParentCommit, err := descendantCommit.IsAncestor(ancestorCommit)
289+
if err != nil {
290+
return false, errors.Wrapf(err, "unable to compare commit [%v] to commit [%v]",
291+
descendant, ancestor)
292+
}
293+
return isParentCommit, nil
294+
}

dgraphtest/compose_cluster.go

+4
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ func (c *ComposeCluster) AlphasHealth() ([]string, error) {
4242
func (c *ComposeCluster) AssignUids(num uint64) error {
4343
return testutil.AssignUids(num)
4444
}
45+
46+
func (c *ComposeCluster) GetVersion() string {
47+
return localVersion
48+
}

dgraphtest/config.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import (
2222
"time"
2323
)
2424

25+
const (
26+
localVersion = "local"
27+
)
28+
2529
type ClusterConfig struct {
2630
prefix string
2731
numAlphas int
@@ -44,7 +48,7 @@ func NewClusterConfig() ClusterConfig {
4448
numZeros: 1,
4549
replicas: 1,
4650
verbosity: 2,
47-
version: "local",
51+
version: localVersion,
4852
volumes: map[string]string{DefaultBackupDir: defaultBackupVol},
4953
}
5054
}

dgraphtest/dcloud_cluster.go

+4
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,7 @@ func (c *DCloudCluster) AssignUids(num uint64) error {
164164

165165
return nil
166166
}
167+
168+
func (c *DCloudCluster) GetVersion() string {
169+
return localVersion
170+
}

dgraphtest/dgraph.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func publicPort(dcli *docker.Client, dc dnode, privatePort string) (string, erro
281281
}
282282

283283
func mountBinary(c *LocalCluster) (mount.Mount, error) {
284-
if c.conf.version == "local" {
284+
if c.conf.version == localVersion {
285285
return mount.Mount{
286286
Type: mount.TypeBind,
287287
Source: filepath.Join(os.Getenv("GOPATH"), "bin"),

dgraphtest/image.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (c *LocalCluster) setupBinary() error {
6363

6464
hash, err := repo.ResolveRevision(plumbing.Revision(c.conf.version))
6565
if err != nil {
66-
return err
66+
return errors.Wrap(err, "error while getting refrence hash")
6767
}
6868
if err := checkoutGitRepo(repo, hash); err != nil {
6969
return err
@@ -80,7 +80,7 @@ func checkoutGitRepo(repo *git.Repository, hash *plumbing.Hash) error {
8080
if err != nil {
8181
return errors.Wrap(err, "error while getting git repo work tree")
8282
}
83-
if err = worktree.Checkout(&git.CheckoutOptions{Hash: plumbing.NewHash(hash.String())}); err != nil {
83+
if err := worktree.Checkout(&git.CheckoutOptions{Hash: *hash}); err != nil {
8484
return errors.Wrap(err, fmt.Sprintf("error while checking out git repo with hash [%v]", hash.String()))
8585
}
8686
return nil

dgraphtest/local_cluster.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
)
4343

4444
var (
45-
requestTimeout = 60 * time.Second
45+
requestTimeout = 90 * time.Second
4646
stopTimeout = time.Minute
4747
)
4848

@@ -672,3 +672,7 @@ func (c *LocalCluster) AssignUids(num uint64) error {
672672
}
673673
return nil
674674
}
675+
676+
func (c *LocalCluster) GetVersion() string {
677+
return c.conf.version
678+
}

query/cloud_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@
1919
package query
2020

2121
import (
22-
"os"
2322
"testing"
2423

2524
"github.com/dgraph-io/dgraph/dgraphtest"
25+
"github.com/dgraph-io/dgraph/x"
2626
)
2727

2828
func TestMain(m *testing.M) {
2929
c, err := dgraphtest.NewDCloudCluster()
3030
x.Panic(err)
3131
defer c.Cleanup()
3232

33-
client = c.Client()
33+
client, err = c.Client()
34+
x.Panic(err)
35+
3436
dc = c
3537
populateCluster()
3638
m.Run()

query/common_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build integration || cloud
1+
//go:build integration || cloud || upgrade
22

33
/*
44
* Copyright 2017-2023 Dgraph Labs, Inc. and Contributors
@@ -352,7 +352,7 @@ func populateCluster() {
352352
panic(err)
353353
}
354354

355-
if err := dc.AssignUids(21000); err != nil {
355+
if err := dc.AssignUids(65536); err != nil {
356356
panic(err)
357357
}
358358
setSchema(testSchema)

query/mutation_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build integration || cloud
1+
//go:build integration || cloud || upgrade
22

33
/*
44
* Copyright 2016-2023 Dgraph Labs, Inc. and Contributors

0 commit comments

Comments
 (0)