Skip to content

Commit

Permalink
Persistent queries upgrade test
Browse files Browse the repository at this point in the history
  • Loading branch information
jbhamra1 committed Sep 6, 2023
1 parent 88d5ebc commit 26030b0
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dgraphtest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func AllUpgradeCombos(v20 bool) []UpgradeCombo {
}...)

mainCombos = append(mainCombos, []UpgradeCombo{
{"v20.11.2-rc1-16-g4d041a3a", localVersion, BackupRestore},
{"v20.11.2-rc1-16-g4d041a3a", "v23.0.1", BackupRestore},
}...)
}

Expand Down
39 changes: 39 additions & 0 deletions dgraphtest/local_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,3 +1082,42 @@ func (c *LocalCluster) GeneratePlugins(raceEnabled bool) error {

return nil
}

func (c *LocalCluster) RunUpgradeTool(from, to string) error {
isAncestor, err := IsHigherVersion("4400610b249713bbf2af5448155dd5819546d1a0", from)
if err != nil {
return errors.Wrapf(err, "error identifying ancestor relationship")
}
if !isAncestor {
return nil
}

grpcPubPort, err := publicPort(c.dcli, c.alphas[0], alphaGrpcPort)
if err != nil {
return errors.Wrapf(err, "error finding alpha grpc public port")
}
grpcUrl := "localhost:"+grpcPubPort

Check failure on line 1099 in dgraphtest/local_cluster.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)

httpPubPort, err := publicPort(c.dcli, c.alphas[0], alphaHttpPort)
if err != nil {
return errors.Wrapf(err, "error finding alpha http public port")
}
httpUrl := "http://localhost:"+httpPubPort

cmd := exec.Command("/Users/jassi/gitrepo/bin/darwin_arm64/dgraph", "upgrade", "--from", from, "--to", to, "--alpha", grpcUrl, "--alpha-http", httpUrl, "--deleteOld")

Check failure on line 1107 in dgraphtest/local_cluster.go

View workflow job for this annotation

GitHub Actions / lint

line is 167 characters (lll)
if c.conf.acl {
cmd = exec.Command("/Users/jassi/gitrepo/bin/darwin_arm64/dgraph", "upgrade", "--from", from, "--to", to, "--user", DefaultUser, "--password", DefaultPassword, "--alpha", grpcUrl, "--alpha-http", httpUrl, "--deleteOld")

Check failure on line 1109 in dgraphtest/local_cluster.go

View workflow job for this annotation

GitHub Actions / lint

line is 221 characters (lll)
}

if out, err := cmd.CombinedOutput(); err != nil {
if _, ok := err.(*exec.ExitError); ok {
log.Print("[INFO] upgrade tool succeeded")
return nil
}

return errors.Wrapf(err, "error running upgrade tool: %v", string(out))
}

log.Print("[INFO] upgrade tool succeeded")
return nil
}
72 changes: 72 additions & 0 deletions ee/acl/persistent_queries_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//go:build (!oss && integration) || upgrade

/*
* Copyright 2023 Dgraph Labs, Inc. and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package acl

import (
"crypto/sha256"
"encoding/hex"

"github.com/stretchr/testify/require"

"github.com/dgraph-io/dgraph/dgraphtest"
"github.com/dgraph-io/dgraph/x"
)

func (asuite *AclTestSuite) TestPersistentQuery() {
t := asuite.T()

// Galaxy Login
hcli, err := asuite.dc.HTTPClient()
require.NoError(t, err)
err = hcli.LoginIntoNamespace(dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace)
require.NotNil(t, hcli.AccessJwt, "galaxy token is nil")
require.NoErrorf(t, err, "login as groot into namespace %d failed", x.GalaxyNamespace)

sch := `type Product {
productID: ID!
name: String @search(by: [term])
}`
require.NoError(t, hcli.UpdateGQLSchema(sch))

query := "query {queryProduct{productID}}"
b := sha256.Sum256([]byte(query))
hash := hex.EncodeToString(b[:])

var data1, data2 []byte
data1, err = hcli.PostPersistentQuery(query, hash)
require.NoError(t, err)

// Upgrade
asuite.Upgrade()

// run upgrade tool for 20.11.x
require.NoError(t, asuite.lc.RunUpgradeTool(asuite.uc.Before, asuite.uc.After))

// Galaxy Login
hcli, err = asuite.dc.HTTPClient()
require.NoError(t, err)
err = hcli.LoginIntoNamespace(dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace)
require.NotNil(t, hcli.AccessJwt, "galaxy token is nil")
require.NoErrorf(t, err, "login as groot into namespace %d failed", x.GalaxyNamespace)

data2, err = hcli.PostPersistentQuery("", hash)
require.NoError(t, err)

require.NoError(t, dgraphtest.CompareJSON(string(data1), string(data2)))
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ require (
golang.org/x/text v0.12.0
golang.org/x/tools v0.9.3
google.golang.org/grpc v1.56.2
google.golang.org/protobuf v1.31.0
gopkg.in/square/go-jose.v2 v2.3.1
gopkg.in/yaml.v2 v2.4.0
)
Expand Down Expand Up @@ -143,6 +142,7 @@ require (
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.31.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

0 comments on commit 26030b0

Please sign in to comment.