Skip to content

Commit

Permalink
test(upgrade): add upgrade tests for v20.11 for ee/acl (#8984)
Browse files Browse the repository at this point in the history
Closes: https://dgraph.atlassian.net/browse/DGRAPHCORE-335

---------

Co-authored-by: Aman Mangal <aman@dgraph.io>
  • Loading branch information
jbhamra1 and mangalaman93 authored Aug 31, 2023
1 parent ba72764 commit 4c9448a
Show file tree
Hide file tree
Showing 4 changed files with 451 additions and 427 deletions.
26 changes: 0 additions & 26 deletions dgraphtest/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,32 +88,6 @@ type LicenseResponse struct {
Extensions map[string]interface{} `json:"license,omitempty"`
}

func (hc *HTTPClient) Login(user, password string, ns uint64) error {
login := `mutation login($userId: String, $password: String, $namespace: Int, $refreshToken: String) {
login(userId: $userId, password: $password, namespace: $namespace, refreshToken: $refreshToken) {
response {
accessJWT
refreshJWT
}
}
}`
params := GraphQLParams{
Query: login,
Variables: map[string]interface{}{
"userId": user,
"password": password,
"namespace": ns,
"refreshToken": hc.RefreshToken,
},
}

hc.HttpToken = &HttpToken{
UserId: user,
Password: password,
}
return hc.doLogin(params, true)
}

func (hc *HTTPClient) LoginUsingToken(ns uint64) error {
q := `mutation login( $namespace: Int, $refreshToken:String) {
login(namespace: $namespace, refreshToken: $refreshToken) {
Expand Down
79 changes: 59 additions & 20 deletions dgraphtest/local_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,35 +479,74 @@ func (c *LocalCluster) containerHealthCheck(url string) error {
if !strings.Contains(resp, `"ee_features"`) {
continue
}
if !c.conf.acl {
return nil
}
if !c.conf.acl || !strings.Contains(resp, `"acl"`) {
if c.conf.acl && !strings.Contains(resp, `"acl"`) {
continue
}
if err := c.waitUntilLogin(); err != nil {
return err
}
if err := c.waitUntilGraphqlHealthCheck(); err != nil {
return err
}
return nil
}

client, cleanup, err := c.Client()
if err != nil {
return errors.Wrap(err, "error setting up a client")
return fmt.Errorf("health failed, cluster took too long to come up [%v]", url)
}

func (c *LocalCluster) waitUntilLogin() error {
if !c.conf.acl {
return nil
}

client, cleanup, err := c.Client()
if err != nil {
return errors.Wrap(err, "error setting up a client")
}
defer cleanup()

ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()
for i := 0; i < 10; i++ {
err := client.Login(ctx, DefaultUser, DefaultPassword)
if err == nil {
log.Printf("[INFO] login succeeded")
return nil
}
defer cleanup()
log.Printf("[WARNING] error trying to login: %v", err)
time.Sleep(waitDurBeforeRetry)
}
return errors.New("error during login")
}

ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()
for i := 0; i < 10; i++ {
if err = client.Login(ctx, DefaultUser, DefaultPassword); err == nil {
break
}
log.Printf("[WARNING] error trying to login: %v", err)
time.Sleep(waitDurBeforeRetry)
func (c *LocalCluster) waitUntilGraphqlHealthCheck() error {
hc, err := c.HTTPClient()
if err != nil {
return errors.Wrap(err, "error creating http client while graphql health check")
}
if c.conf.acl {
if err := hc.LoginIntoNamespace(DefaultUser, DefaultPassword, x.GalaxyNamespace); err != nil {
return errors.Wrap(err, "error during login while graphql health check")
}
if err != nil {
return errors.Wrap(err, "error during login")
}

for i := 0; i < 10; i++ {
// we do this because before v21, we used to propose the initial schema to the cluster.
// This results in schema being applied and indexes being built which could delay alpha
// starting to serve graphql schema.
err := hc.DeleteUser("nonexistent")
if err == nil {
log.Printf("[INFO] graphql health check succeeded")
return nil
} else if strings.Contains(err.Error(), "this indicates a resolver or validation bug") {
time.Sleep(waitDurBeforeRetry)
continue
} else {
return errors.Wrapf(err, "error during graphql health check")
}
return nil
}

return fmt.Errorf("health failed, cluster took too long to come up [%v]", url)
return errors.New("error during graphql health check")
}

var client *http.Client = &http.Client{
Expand Down
Loading

0 comments on commit 4c9448a

Please sign in to comment.