Skip to content

Commit 24f8116

Browse files
fix(upgrade): fix failing upgrade tests (#9042)
Co-authored-by: ShivajiKharse <[email protected]>
1 parent 7406a0e commit 24f8116

File tree

8 files changed

+71
-29
lines changed

8 files changed

+71
-29
lines changed

dgraphtest/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ func NewClusterConfig() ClusterConfig {
147147
}
148148
}
149149

150+
func newClusterConfigFrom(cc ClusterConfig) ClusterConfig {
151+
prefix := fmt.Sprintf("dgraphtest-%d", rand.NewSource(time.Now().UnixNano()).Int63()%1000000)
152+
defaultBackupVol := fmt.Sprintf("%v_backup", prefix)
153+
defaultExportVol := fmt.Sprintf("%v_export", prefix)
154+
cc.prefix = prefix
155+
cc.volumes = map[string]string{DefaultBackupDir: defaultBackupVol, DefaultExportDir: defaultExportVol}
156+
return cc
157+
}
158+
150159
// WithNAlphas sets the number of alphas in the cluster
151160
func (cc ClusterConfig) WithNumAlphas(n int) ClusterConfig {
152161
cc.numAlphas = n

dgraphtest/image.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"strings"
2727

2828
"github.com/pkg/errors"
29+
"golang.org/x/mod/modfile"
2930
)
3031

3132
func (c *LocalCluster) dgraphImage() string {
@@ -151,6 +152,10 @@ func getHash(ref string) (string, error) {
151152
func buildDgraphBinary(dir, binaryDir, version string) error {
152153
log.Printf("[INFO] building dgraph binary for version [%v]", version)
153154

155+
if err := fixGoModIfNeeded(); err != nil {
156+
return err
157+
}
158+
154159
cmd := exec.Command("make", "dgraph")
155160
cmd.Dir = filepath.Join(dir, "dgraph")
156161
if out, err := cmd.CombinedOutput(); err != nil {
@@ -229,3 +234,28 @@ func IsHigherVersion(higher, lower string) (bool, error) {
229234

230235
return true, nil
231236
}
237+
238+
func fixGoModIfNeeded() error {
239+
repoModFilePath := filepath.Join(repoDir, "go.mod")
240+
repoModFile, err := modfile.Parse(repoModFilePath, nil, nil)
241+
if err != nil {
242+
return errors.Wrapf(err, "error parsing mod file in repoDir [%v]", repoDir)
243+
}
244+
245+
modFile, err := modfile.Parse("go.mod", nil, nil)
246+
if err != nil {
247+
return errors.Wrapf(err, "error while parsing go.mod file")
248+
}
249+
250+
if len(modFile.Replace) == len(repoModFile.Replace) {
251+
return nil
252+
}
253+
254+
repoModFile.Replace = modFile.Replace
255+
if data, err := repoModFile.Format(); err != nil {
256+
return errors.Wrapf(err, "error while formatting mod file")
257+
} else if err := os.WriteFile(repoModFilePath, data, 0644); err != nil {
258+
return errors.Wrapf(err, "error while writing to go.mod file")
259+
}
260+
return nil
261+
}

dgraphtest/local_cluster.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323
"io"
2424
"log"
25-
"math/rand"
2625
"net/http"
2726
"os"
2827
"os/exec"
@@ -140,13 +139,15 @@ func (c *LocalCluster) init() error {
140139
}
141140
}
142141

142+
c.zeros = c.zeros[:0]
143143
for i := 0; i < c.conf.numZeros; i++ {
144144
zo := &zero{id: i}
145145
zo.containerName = fmt.Sprintf(zeroNameFmt, c.conf.prefix, zo.id)
146146
zo.aliasName = fmt.Sprintf(zeroAliasNameFmt, zo.id)
147147
c.zeros = append(c.zeros, zo)
148148
}
149149

150+
c.alphas = c.alphas[:0]
150151
for i := 0; i < c.conf.numAlphas; i++ {
151152
aa := &alpha{id: i}
152153
aa.containerName = fmt.Sprintf(alphaNameFmt, c.conf.prefix, aa.id)
@@ -336,27 +337,29 @@ func (c *LocalCluster) Start() error {
336337
return c.HealthCheck(false)
337338
}
338339

339-
var err error
340-
// sometimes health check doesn't work due to unmapped ports. We dont know why this happens,
341-
// but checking it 4 times before failing the test.
342-
for i := 0; i < 4; i++ {
340+
// sometimes health check doesn't work due to unmapped ports. We dont
341+
// know why this happens, but checking it 3 times before failing the test.
342+
retry := 0
343+
for {
344+
retry++
343345

344-
if err = startAll(); err == nil {
346+
if err := startAll(); err == nil {
345347
return nil
348+
} else if retry == 3 {
349+
return err
350+
} else {
351+
log.Printf("[WARNING] saw the err, trying again: %v", err)
346352
}
347-
log.Printf("[WARNING] Saw the error :%v, trying again", err)
348-
if err1 := c.Stop(); err1 != nil {
349-
log.Printf("[WARNING] error while stopping :%v", err)
350-
}
353+
354+
log.Printf("[INFO] cleaning up the cluster for retrying!")
351355
c.Cleanup(true)
352-
c.conf.prefix = fmt.Sprintf("dgraphtest-%d", rand.NewSource(time.Now().UnixNano()).Int63()%1000000)
356+
357+
c.conf = newClusterConfigFrom(c.conf)
353358
if err := c.init(); err != nil {
354-
c.Cleanup(true)
359+
log.Printf("[ERROR] error while init, returning: %v", err)
355360
return err
356361
}
357362
}
358-
359-
return err
360363
}
361364

362365
func (c *LocalCluster) StartZero(id int) error {

ee/acl/upgrade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (asuite *AclTestSuite) Upgrade() {
5555

5656
func TestACLSuite(t *testing.T) {
5757
for _, uc := range dgraphtest.AllUpgradeCombos(true) {
58-
log.Printf("running upgrade tests for confg: %+v", uc)
58+
log.Printf("running upgrade tests for config: %+v", uc)
5959
aclSuite := AclTestSuite{uc: uc}
6060
suite.Run(t, &aclSuite)
6161
if t.Failed() {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ require (
6060
go.uber.org/zap v1.16.0
6161
golang.org/x/crypto v0.21.0
6262
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
63+
golang.org/x/mod v0.16.0
6364
golang.org/x/net v0.22.0
6465
golang.org/x/sync v0.6.0
6566
golang.org/x/sys v0.18.0
@@ -142,7 +143,6 @@ require (
142143
github.com/xdg/stringprep v1.0.3 // indirect
143144
go.uber.org/atomic v1.9.0 // indirect
144145
go.uber.org/multierr v1.10.0 // indirect
145-
golang.org/x/mod v0.16.0 // indirect
146146
golang.org/x/time v0.3.0 // indirect
147147
google.golang.org/api v0.122.0 // indirect
148148
google.golang.org/appengine v1.6.8 // indirect

query/common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func processQuery(ctx context.Context, t *testing.T, query string) (string, erro
7575
return string(jsonResponse), err
7676
}
7777

78-
func processQueryRDF(ctx context.Context, t *testing.T, query string) (string, error) {
78+
func processQueryRDF(ctx context.Context, query string) (string, error) {
7979
txn := client.NewTxn()
8080
defer func() { _ = txn.Discard(ctx) }()
8181

query/rdf_result_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestRDFResult(t *testing.T) {
3636
}
3737
}`
3838

39-
rdf, err := processQueryRDF(context.Background(), t, query)
39+
rdf, err := processQueryRDF(context.Background(), query)
4040
require.NoError(t, err)
4141
require.Equal(t, rdf, `<0x1> <name> "Michonne" .
4242
<0x1> <friend> <0x17> .
@@ -69,7 +69,7 @@ func TestRDFNormalize(t *testing.T) {
6969
}
7070
}
7171
}`
72-
_, err := processQueryRDF(context.Background(), t, query)
72+
_, err := processQueryRDF(context.Background(), query)
7373
require.Error(t, err, "normalize directive is not supported in the rdf output format")
7474
}
7575

@@ -80,7 +80,7 @@ func TestRDFGroupBy(t *testing.T) {
8080
count(uid)
8181
}
8282
}`
83-
_, err := processQueryRDF(context.Background(), t, query)
83+
_, err := processQueryRDF(context.Background(), query)
8484
require.Contains(t, err.Error(), "groupby is not supported in rdf output format")
8585
}
8686

@@ -91,7 +91,7 @@ func TestRDFUidCount(t *testing.T) {
9191
count(uid)
9292
}
9393
}`
94-
_, err := processQueryRDF(context.Background(), t, query)
94+
_, err := processQueryRDF(context.Background(), query)
9595
require.Contains(t, err.Error(), "uid count is not supported in the rdf output format")
9696
}
9797

@@ -108,7 +108,7 @@ func TestRDFIngoreReflex(t *testing.T) {
108108
}
109109
}
110110
}`
111-
_, err := processQueryRDF(context.Background(), t, query)
111+
_, err := processQueryRDF(context.Background(), query)
112112
require.Contains(t, err.Error(),
113113
"ignorereflex directive is not supported in the rdf output format")
114114
}
@@ -121,7 +121,7 @@ func TestRDFRecurse(t *testing.T) {
121121
friend
122122
}
123123
}`
124-
rdf, err := processQueryRDF(context.Background(), t, query)
124+
rdf, err := processQueryRDF(context.Background(), query)
125125
require.NoError(t, err)
126126
require.Equal(t, rdf, `<0x1> <name> "Michonne" .
127127
<0x17> <name> "Rick Grimes" .
@@ -137,7 +137,7 @@ func TestRDFIgnoreUid(t *testing.T) {
137137
name
138138
}
139139
}`
140-
rdf, err := processQueryRDF(context.Background(), t, query)
140+
rdf, err := processQueryRDF(context.Background(), query)
141141
require.NoError(t, err)
142142
require.Equal(t, rdf, `<0x1> <name> "Michonne" .
143143
<0x17> <name> "Rick Grimes" .
@@ -154,7 +154,7 @@ func TestRDFCheckPwd(t *testing.T) {
154154
}
155155
}
156156
`
157-
_, err := processQueryRDF(context.Background(), t, query)
157+
_, err := processQueryRDF(context.Background(), query)
158158
require.Contains(t, err.Error(),
159159
"chkpwd function is not supported in the rdf output format")
160160
}
@@ -172,7 +172,7 @@ func TestRDFPredicateCount(t *testing.T) {
172172
}
173173
`
174174

175-
rdf, err := processQueryRDF(context.Background(), t, query)
175+
rdf, err := processQueryRDF(context.Background(), query)
176176
require.NoError(t, err)
177177
require.Equal(t, `<0x1> <name> "Michonne" .
178178
<0x17> <name> "Rick Grimes" .
@@ -201,7 +201,7 @@ func TestRDFFacets(t *testing.T) {
201201
path @facets(weight)
202202
}
203203
}`
204-
_, err := processQueryRDF(context.Background(), t, query)
204+
_, err := processQueryRDF(context.Background(), query)
205205
require.Contains(t, err.Error(),
206206
"facets are not supported in the rdf output format")
207207
}
@@ -219,7 +219,7 @@ func TestDateRDF(t *testing.T) {
219219
}
220220
}
221221
`
222-
rdf, err := processQueryRDF(context.Background(), t, query)
222+
rdf, err := processQueryRDF(context.Background(), query)
223223
require.NoError(t, err)
224224
expected := `<0x1> <name> "Michonne" .
225225
<0x1> <gender> "female" .

systest/multi-tenancy/upgrade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (msuite *MultitenancyTestSuite) Upgrade() {
6262

6363
func TestMultitenancySuite(t *testing.T) {
6464
for _, uc := range dgraphtest.AllUpgradeCombos(false) {
65-
log.Printf("running upgrade tests for confg: %+v", uc)
65+
log.Printf("running upgrade tests for config: %+v", uc)
6666
var msuite MultitenancyTestSuite
6767
msuite.uc = uc
6868
suite.Run(t, &msuite)

0 commit comments

Comments
 (0)