Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test): Integration tests for advanced backup/restore scenarios #8643

Merged
merged 12 commits into from
Feb 17, 2023

Conversation

SiddeshUbale
Copy link
Contributor

This PR contains Integration tests for:

1] Illegal namespace test (more than 127 namespaces).

Backup restore with a dgraph setup that has more than 127 namespaces

@CLAassistant
Copy link

CLAassistant commented Feb 1, 2023

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added area/graphql Issues related to GraphQL support on Dgraph. area/testing Testing related issues labels Feb 1, 2023
@coveralls
Copy link

coveralls commented Feb 1, 2023

Coverage Status

Coverage: 67.267% (+0.2%) from 67.078% when pulling d06322b on siddesh/127-namespace into 0f82499 on main.

systest/backup/advanced-scenarios/127-Namespace/acl-secret Outdated Show resolved Hide resolved
systest/backup/common/utils.go Outdated Show resolved Hide resolved
systest/backup/common/utils.go Outdated Show resolved Hide resolved
systest/backup/common/utils.go Show resolved Hide resolved
graphql/e2e/common/common.go Outdated Show resolved Hide resolved
systest/backup/common/utils.go Outdated Show resolved Hide resolved
systest/backup/common/utils.go Outdated Show resolved Hide resolved
systest/backup/common/utils.go Outdated Show resolved Hide resolved
systest/backup/common/utils.go Outdated Show resolved Hide resolved
graphql/e2e/common/common.go Outdated Show resolved Hide resolved
graphql/e2e/common/common.go Outdated Show resolved Hide resolved
systest/backup/common/utils.go Outdated Show resolved Hide resolved
systest/backup/common/utils.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mangalaman93 mangalaman93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better, just two more comments:

  1. can we use shared volume instead of .gitkeep files
  2. can we refactor code from other backup test and use the functions that you have added?

)

func TestDeletedNamespaceID(t *testing.T) {
defer utilsCommon.DirCleanup(t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we only doing cleanup? Where do we create the dir that we are cleaning up here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backupTemp folder gets created when the code takes a backup(backupdest is /data/backups/backupTemp).

Now the test is using shared volume and I have removed the DirCleanup() call from the test.

@SiddeshUbale SiddeshUbale force-pushed the siddesh/127-namespace branch 2 times, most recently from d8a3adc to 9db7a5c Compare February 9, 2023 09:25
mangalaman93
mangalaman93 previously approved these changes Feb 9, 2023
func CreateNamespace(t *testing.T, headers http.Header) uint64 {
type CreateNamespaceParams struct {
CustomGraphAdminURLs string
NamespaceQuant int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NamespaceQuant -> just Count

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Comment on lines 31 to 59
_ = e2eCommon.CreateNamespace(t, headerAlpha1, e2eCommon.CreateNamespaceParams{CustomGraphAdminURLs: "", NamespaceQuant: 20})
utilsCommon.AddSchema(t, headerAlpha1, "alpha1")
e2eCommon.AssertGetGQLSchema(t, testutil.ContainerAddr("alpha1", 8080), headerAlpha1)
utilsCommon.AddData(t, 1, 10, jwtTokenAlpha1, "alpha1")
utilsCommon.CheckDataExists(t, 10, jwtTokenAlpha1, "alpha1")
_ = e2eCommon.CreateNamespace(t, headerAlpha1, e2eCommon.CreateNamespaceParams{CustomGraphAdminURLs: "", NamespaceQuant: 20})
utilsCommon.AddData(t, 11, 20, jwtTokenAlpha1, "alpha1")
utilsCommon.CheckDataExists(t, 20, jwtTokenAlpha1, "alpha1")
_ = e2eCommon.CreateNamespace(t, headerAlpha1, e2eCommon.CreateNamespaceParams{CustomGraphAdminURLs: "", NamespaceQuant: 20})
utilsCommon.AddData(t, 21, 30, jwtTokenAlpha1, "alpha1")
utilsCommon.CheckDataExists(t, 30, jwtTokenAlpha1, "alpha1")
_ = e2eCommon.CreateNamespace(t, headerAlpha1, e2eCommon.CreateNamespaceParams{CustomGraphAdminURLs: "", NamespaceQuant: 20})
utilsCommon.AddData(t, 31, 40, jwtTokenAlpha1, "alpha1")
utilsCommon.CheckDataExists(t, 40, jwtTokenAlpha1, "alpha1")
_ = e2eCommon.CreateNamespace(t, headerAlpha1, e2eCommon.CreateNamespaceParams{CustomGraphAdminURLs: "", NamespaceQuant: 20})
utilsCommon.AddData(t, 41, 50, jwtTokenAlpha1, "alpha1")
utilsCommon.CheckDataExists(t, 50, jwtTokenAlpha1, "alpha1")
_ = e2eCommon.CreateNamespace(t, headerAlpha1, e2eCommon.CreateNamespaceParams{CustomGraphAdminURLs: "", NamespaceQuant: 20})
utilsCommon.AddData(t, 51, 60, jwtTokenAlpha1, "alpha1")
utilsCommon.CheckDataExists(t, 60, jwtTokenAlpha1, "alpha1")
_ = e2eCommon.CreateNamespace(t, headerAlpha1, e2eCommon.CreateNamespaceParams{CustomGraphAdminURLs: "", NamespaceQuant: 30})
utilsCommon.AddData(t, 61, 70, jwtTokenAlpha1, "alpha1")
utilsCommon.CheckDataExists(t, 70, jwtTokenAlpha1, "alpha1")
utilsCommon.TakeBackup(t, jwtTokenAlpha1, backupDst, "alpha1")
utilsCommon.RunRestore(t, jwtTokenAlpha2, restoreLocation, "alpha2")
dg := testutil.DgClientWithLogin(t, "groot", "password", x.GalaxyNamespace)
testutil.WaitForRestore(t, dg, testutil.ContainerAddr("alpha2", 8080))
e2eCommon.AssertGetGQLSchema(t, testutil.ContainerAddr("alpha2", 8080), headerAlpha2)
utilsCommon.CheckDataExists(t, 70, jwtTokenAlpha2, "alpha2")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need so many steps, what would more useful would be distributing data across different namespaces as well.

I'd structure it like this:

  • Step 1, Create 50 namespaces, add data to namespace 0, take backup and restore and check if data is present. (in the restored backend)
  • Step 2. Create another 50 namespaced, add data to namespace 51, take backup and restore and check if the data is present in 0 and 51
  • Step 3 Create another 50 namespaces, add data to namespace 130,, take backup and restore and check if data is present in 0, 51 and 130.

With this we check iteratively adding data to new namespaces preserves data in older namespaces across restores. We also check the namespace increment is monotonic, that is after first restore we get the namespace 51 created.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved
Now the test has the following flow:-

Create 1-50 Namespaces
Add data to Namespace 0
Backup on Alpha1
Restore on Alpha2
Log into Namespace 0 on Alpha2
CheckDataExist
 
Create 51-100 Namespaces
Add data to 51 Namespace
Backup on Alpha1
Restore on Alpha 2
Log into Namespace 0 on Alpha2
CheckDataExist
Log into Namespace51 on Alpha2
CheckDataExist


Create 101-130 Namespaces
Add data to Namespace 130
Backup on Alpha1
Restore on Alpha 2
Log into Namespace 0 on Alpha2
CheckDataExist
Log into Namespace51 on Alpha2
CheckDataExist
Log into Namespace130 on Alpha2
CheckDataExist

headerAlpha1Np0.Set("Content-Type", "application/json")

jwtTokenAlpha2Np0 := testutil.GrootHttpLoginNamespace("http://"+testutil.ContainerAddr("alpha2", 8080)+"/admin", 0).AccessJwt
headerAlpha2Np0.Set(accessJwtHeader, jwtTokenAlpha2Np0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a lot of this code can be wrapped inside a function and can be re-used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@@ -70,6 +70,9 @@ var (
"indicating that the GraphQL layer didn't get the updated schema even after 10" +
" retries. The most probable cause is the new GraphQL schema is same as the old" +
" GraphQL schema."

customAdminURL string
namespaceCount = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can define this inside the test/function itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@@ -329,7 +332,12 @@ func containsRetryableCreateNamespaceError(resp *GraphQLResponse) bool {
return false
}

func CreateNamespace(t *testing.T, headers http.Header) uint64 {
type CreateNamespaceParams struct {
CustomGraphAdminURLs string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be just GraphAdminURLs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved


func CreateNamespace(t *testing.T, headers http.Header, cnp ...CreateNamespaceParams) uint64 {
var customAdminURL string
var namespaceCount = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be

const namespaceCount = 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@@ -360,7 +379,7 @@ func CreateNamespace(t *testing.T, headers http.Header) uint64 {
return resp.AddNamespace.NamespaceId
}

func DeleteNamespace(t *testing.T, id uint64, header http.Header) {
func DeleteNamespace(t *testing.T, id uint64, header http.Header, whichAlpha ...string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change this function instead.

Copy link
Contributor Author

@SiddeshUbale SiddeshUbale Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

The same fix is applied to CreateNamespace()

Count int
}

func CreateNamespace(t *testing.T, headers http.Header, cnp ...CreateNamespaceParams) uint64 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to have two functions here CreateNamespace and CreateNamespaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Copy link
Contributor

@mangalaman93 mangalaman93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few minor comments, otherwise looks good

@@ -344,7 +353,8 @@ func CreateNamespace(t *testing.T, headers http.Header) uint64 {
// keep retrying as long as we get a retryable error
var gqlResponse *GraphQLResponse
for {
gqlResponse = createNamespace.ExecuteAsPost(t, GraphqlAdminURL)
// gqlResponse = createNamespace.ExecuteAsPost(t, GraphqlAdminURL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

source: $GOPATH/bin
target: /gobin
read_only: true
- data-volume:/data/backups/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you leave a space after colon just like we do everywhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reconfirmed online. Shared volumes are written like this.

@@ -91,6 +101,179 @@ func CopyToLocalFs(t *testing.T) {
require.NoError(t, testutil.DockerCp(srcPath, copyBackupDir))
}

func AddSchema(t *testing.T, header http.Header, whichAlpha string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided against changing the name as we discussed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

mangalaman93
mangalaman93 previously approved these changes Feb 16, 2023
1] Resolved review comments
2] Updated CreateNamespace() to accept whichAlpha string value on which it runs mutation
3] Added CreateNamespaces() to iterate CreateNamespace() function to create multiple namespaces.
4] Updated DeleteNamespace() to accept whichAlpha string value on which it runs mutation
5] Updated the CreateNamespace() & DeleteNamespace() function calls from multi_tenancy_test.go & 127-Namespace/backup_test.go
@mangalaman93 mangalaman93 merged commit a8558ab into main Feb 17, 2023
@mangalaman93 mangalaman93 deleted the siddesh/127-namespace branch February 17, 2023 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/graphql Issues related to GraphQL support on Dgraph. area/testing Testing related issues
Development

Successfully merging this pull request may close these issues.

None yet

5 participants