Skip to content

Commit

Permalink
chore(tests): test for deleted namespace (#8693)
Browse files Browse the repository at this point in the history
this test ensures that we don't miss out on bumping the max
namespace ID after a restore if before backup the max namespace
had been deleted.
  • Loading branch information
SiddeshUbale authored Mar 1, 2023
1 parent 7609ee4 commit 968080c
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 0 deletions.
24 changes: 24 additions & 0 deletions graphql/e2e/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,30 @@ func CreateNamespace(t *testing.T, headers http.Header, whichAlpha string) uint6
return resp.AddNamespace.NamespaceId
}

func ListNamespaces(t *testing.T, jwtToken string, headers http.Header, whichAlpha string) []uint64 {
adminUrl := "http://" + testutil.ContainerAddr(whichAlpha, 8080) + "/admin"

listNamespaces := &GraphQLParams{
Query: `query{
state {
namespaces
}
}`,
Headers: headers,
}

gqlResponse := listNamespaces.ExecuteAsPost(t, adminUrl)
RequireNoGQLErrors(t, gqlResponse)

var resp struct {
State struct {
Namespaces []uint64 `json:"namespaces"`
} `json:"state"`
}
require.NoError(t, json.Unmarshal(gqlResponse.Data, &resp))
return resp.State.Namespaces
}

func DeleteNamespace(t *testing.T, id uint64, header http.Header, whichAlpha string) {
adminUrl := "http://" + testutil.ContainerAddr(whichAlpha, 8080) + "/admin"
deleteNamespace := &GraphQLParams{
Expand Down
55 changes: 55 additions & 0 deletions systest/backup/advanced-scenarios/deleted-namespace/backup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"testing"

e2eCommon "github.com/dgraph-io/dgraph/graphql/e2e/common"
utilsCommon "github.com/dgraph-io/dgraph/systest/backup/common"
"github.com/dgraph-io/dgraph/testutil"
"github.com/dgraph-io/dgraph/x"
"github.com/stretchr/testify/require"
)

const (
accessJwtHeader = "X-Dgraph-AccessToken"
restoreLocation = "/data/backups/"
backupDst = "/data/backups/"
)

func TestDeletedNamespaceID(t *testing.T) {
jwtTokenAlpha1Np0, headerAlpha1Np0 := utilsCommon.GetJwtTokenAndHeader(t, "alpha1", 0)
jwtTokenAlpha2Np0, headerAlpha2Np0 := utilsCommon.GetJwtTokenAndHeader(t, "alpha2", 0)
ns1 := e2eCommon.CreateNamespaces(t, headerAlpha1Np0, "alpha1", 4)
jwtTokenAlpha1Np1, headerAlpha1Np1 := utilsCommon.GetJwtTokenAndHeader(t, "alpha1", 1)
utilsCommon.AddItemSchema(t, headerAlpha1Np1, "alpha1")
utilsCommon.AddItem(t, 11, 20, jwtTokenAlpha1Np1, "alpha1")
jwtTokenAlpha1Np2, headerAlpha1Np2 := utilsCommon.GetJwtTokenAndHeader(t, "alpha1", 2)
utilsCommon.AddItemSchema(t, headerAlpha1Np2, "alpha1")
utilsCommon.AddItem(t, 21, 30, jwtTokenAlpha1Np2, "alpha1")
jwtTokenAlpha1Np3, headerAlpha1Np3 := utilsCommon.GetJwtTokenAndHeader(t, "alpha1", 3)
utilsCommon.AddItemSchema(t, headerAlpha1Np3, "alpha1")
utilsCommon.AddItem(t, 31, 40, jwtTokenAlpha1Np3, "alpha1")
jwtTokenAlpha1Np4, headerAlpha1Np4 := utilsCommon.GetJwtTokenAndHeader(t, "alpha1", 4)
utilsCommon.AddItemSchema(t, headerAlpha1Np4, "alpha1")
utilsCommon.AddItem(t, 41, 50, jwtTokenAlpha1Np4, "alpha1")
e2eCommon.DeleteNamespace(t, ns1[2], headerAlpha1Np0, "alpha1")
utilsCommon.TakeBackup(t, jwtTokenAlpha1Np0, backupDst, "alpha1")
utilsCommon.RunRestore(t, jwtTokenAlpha2Np0, restoreLocation, "alpha2")
dg1 := testutil.DgClientWithLogin(t, "groot", "password", x.GalaxyNamespace)
testutil.WaitForRestore(t, dg1, testutil.ContainerAddr("alpha2", 8080))
lastAddedNamespaceId := e2eCommon.CreateNamespace(t, headerAlpha2Np0, "alpha2")
require.Equal(t, lastAddedNamespaceId > ns1[3], true)
require.Greater(t, lastAddedNamespaceId, ns1[3])
jwtTokenAlpha2Np1, _ := utilsCommon.GetJwtTokenAndHeader(t, "alpha2", 1)
utilsCommon.CheckItemExists(t, 15, jwtTokenAlpha2Np1, "alpha2")
jwtTokenAlpha2Np2, _ := utilsCommon.GetJwtTokenAndHeader(t, "alpha2", 2)
utilsCommon.CheckItemExists(t, 35, jwtTokenAlpha2Np2, "alpha2")
jwtTokenAlpha2Np3, _ := utilsCommon.GetJwtTokenAndHeader(t, "alpha2", 4)
utilsCommon.CheckItemExists(t, 35, jwtTokenAlpha2Np3, "alpha2")
nsl := e2eCommon.ListNamespaces(t, jwtTokenAlpha2Np0, headerAlpha2Np0, "alpha2")
for _, ns := range nsl {
require.NotEqual(t, ns, ns1[2])
}
require.Contains(t, nsl, lastAddedNamespaceId)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Auto-generated with: [./compose -a 3 -z 1 -r 1 -w --port_offset=0 --expose_ports=false --alpha_volume=./data/backups:/data/backups/ --zero_volume=./data/backups:/data/backups/ --mem= --names=false -O ../systest/backup/multi-tenancy/docker-compose.yml --acl]
#
version: "3.5"
services:
alpha1:
image: dgraph/dgraph:local
working_dir: /data/alpha1
depends_on:
- zero1
labels:
cluster: test
ports:
- 8080
- 9080
volumes:
- type: bind
source: $GOPATH/bin
target: /gobin
read_only: true
- type: bind
source: ../../../acl/restore/acl-secret
target: /secret/hmac
read_only: true
- data-volume:/data/backups/
command: /gobin/dgraph ${COVERAGE_OUTPUT} alpha --my=alpha1:7080 --zero=zero1:5080
--logtostderr -v=2 --raft "idx=1; group=1;" --security "whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16;"
--acl "secret-file=/secret/hmac;"

zero1:
image: dgraph/dgraph:local
working_dir: /data/zero1
labels:
cluster: test
ports:
- 5080
- 6080
volumes:
- type: bind
source: $GOPATH/bin
target: /gobin
read_only: true
- data-volume:/data/backups/
command: /gobin/dgraph ${COVERAGE_OUTPUT} zero --raft "idx=1;" --my=zero1:5080 --logtostderr -v=2 --bindall

alpha2:
image: dgraph/dgraph:local
working_dir: /data/alpha2
depends_on:
- zero2
labels:
cluster: test
ports:
- 8080
- 9080
volumes:
- type: bind
source: $GOPATH/bin
target: /gobin
read_only: true
- type: bind
source: ../../../acl/restore/acl-secret
target: /secret/hmac
read_only: true
- data-volume:/data/backups/
command: /gobin/dgraph ${COVERAGE_OUTPUT} alpha --my=alpha2:7080 --zero=zero2:5080
--logtostderr -v=2 --raft "idx=1; group=1;" --security "whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16;"
--acl "secret-file=/secret/hmac;"

zero2:
image: dgraph/dgraph:local
working_dir: /data/zero2
labels:
cluster: test
ports:
- 5080
- 6080
volumes:
- type: bind
source: $GOPATH/bin
target: /gobin
read_only: true
- data-volume:/data/backups/
command: /gobin/dgraph ${COVERAGE_OUTPUT} zero --raft "idx=1;" --my=zero2:5080 --logtostderr -v=2 --bindall
volumes:
data-volume:

0 comments on commit 968080c

Please sign in to comment.