Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mangalaman93 committed Feb 27, 2020
1 parent e16832e commit 674b79e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 21 deletions.
8 changes: 5 additions & 3 deletions dgraph/cmd/alpha/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,14 @@ func runWithRetries(method, contentType, url string, body string) (
}

switch {
case retries > 20:
return qr, respBody, err
case strings.Contains(err.Error(), "already being modified"):
time.Sleep(time.Second)
case strings.Contains(err.Error(), "is not indexed") ||
strings.Contains(err.Error(), "doesn't have reverse edge") ||
strings.Contains(err.Error(), "Need @count directive in schema") ||
strings.Contains(err.Error(), "already being modified"):
strings.Contains(err.Error(), "Need @count directive in schema"):
time.Sleep(time.Millisecond * 100)
continue
case strings.Contains(err.Error(), "Token is expired"):
grootAccessJwt, grootRefreshJwt, err = testutil.HttpLogin(&testutil.LoginParams{
Endpoint: addr + "/admin",
Expand Down
7 changes: 3 additions & 4 deletions systest/mutations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,10 @@ func ListToScalar(t *testing.T, c *dgo.Dgraph) {
ctx := context.Background()

require.NoError(t, c.Alter(ctx, &api.Operation{Schema: `pred: [string] @index(exact) .`}))
_, err := testutil.RetryQuery(ctx, c, `{q(func: eq(pred, "")){uid}}`)
require.NoError(t, err)

err := c.Alter(ctx, &api.Operation{Schema: `pred: string @index(exact) .`})
err = c.Alter(ctx, &api.Operation{Schema: `pred: string @index(exact) .`})
require.Error(t, err)
require.Contains(t, err.Error(), `Type can't be changed from list to scalar for attr: [pred] without dropping it first.`)

Expand Down Expand Up @@ -1379,7 +1381,6 @@ func HasDeletedEdge(t *testing.T, c *dgo.Dgraph) {
you(func: has(end)) { count(uid) }
}`)
check(t, err)
t.Logf("resp: %s\n", resp.GetJson())
m := make(map[string][]U)
err = json.Unmarshal(resp.GetJson(), &m)
check(t, err)
Expand All @@ -1405,7 +1406,6 @@ func HasDeletedEdge(t *testing.T, c *dgo.Dgraph) {
deleteMu.DelNquads = []byte(fmt.Sprintf(`
<%s> <end> * .
`, ids[len(ids)-1]))
t.Logf("deleteMu: %+v\n", deleteMu)
_, err = txn.Mutate(ctx, deleteMu)
check(t, err)

Expand Down Expand Up @@ -1478,7 +1478,6 @@ func HasReverseEdge(t *testing.T, c *dgo.Dgraph) {
}`)
check(t, err)

t.Logf("resp: %s\n", resp.GetJson())
m := make(map[string][]F)
err = json.Unmarshal(resp.GetJson(), &m)
check(t, err)
Expand Down
3 changes: 1 addition & 2 deletions systest/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ func TestPlugins(t *testing.T) {
check(t, txn.Commit(ctx))

for _, test := range cases {
txn := cluster.client.NewTxn()
reply, err := txn.Query(ctx, test.query)
reply, err := testutil.RetryQuery(ctx, cluster.client, test.query)
check(t, err)
testutil.CompareJSON(t, test.wantResult, string(reply.GetJson()))
}
Expand Down
38 changes: 27 additions & 11 deletions systest/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,8 @@ func MultipleBlockEval(t *testing.T, c *dgo.Dgraph) {
}
}`

txn = c.NewTxn()
for _, tc := range tests {
resp, err := txn.Query(ctx, fmt.Sprintf(queryFmt, tc.in))
resp, err := testutil.RetryQuery(ctx, c, fmt.Sprintf(queryFmt, tc.in))
require.NoError(t, err)
testutil.CompareJSON(t, tc.out, string(resp.Json))
}
Expand Down Expand Up @@ -306,9 +305,8 @@ func UnmatchedVarEval(t *testing.T, c *dgo.Dgraph) {
},
}

txn = c.NewTxn()
for _, tc := range tests {
resp, err := txn.Query(ctx, tc.in)
resp, err := testutil.RetryQuery(ctx, c, tc.in)
require.NoError(t, err)
testutil.CompareJSON(t, tc.out, string(resp.Json))
}
Expand All @@ -329,6 +327,10 @@ func SchemaQueryTest(t *testing.T, c *dgo.Dgraph) {
require.NoError(t, err)
require.NoError(t, txn.Commit(ctx))

// wait for schema to get updated
_, err = testutil.RetryQuery(ctx, c, `{q(func: eq(name, "")){uid}}`)
require.NoError(t, err)

txn = c.NewTxn()
resp, err := txn.Query(ctx, `schema {}`)
require.NoError(t, err)
Expand Down Expand Up @@ -438,6 +440,10 @@ func SchemaQueryTestPredicate2(t *testing.T, c *dgo.Dgraph) {
require.NoError(t, err)
require.NoError(t, txn.Commit(ctx))

// wait for schema to get updated
_, err = testutil.RetryQuery(ctx, c, `{q(func: eq(name, "")){uid}}`)
require.NoError(t, err)

txn = c.NewTxn()
resp, err := txn.Query(ctx, `schema(pred: [name]) {}`)
require.NoError(t, err)
Expand Down Expand Up @@ -700,7 +706,7 @@ func FuzzyMatch(t *testing.T, c *dgo.Dgraph) {
},
}
for _, tc := range tests {
resp, err := c.NewTxn().Query(ctx, tc.in)
resp, err := testutil.RetryQuery(ctx, c, tc.in)
if tc.failure != "" {
require.Error(t, err)
require.Contains(t, err.Error(), tc.failure)
Expand Down Expand Up @@ -739,6 +745,10 @@ func QueryHashIndex(t *testing.T, c *dgo.Dgraph) {
require.NoError(t, err)
require.NoError(t, txn.Commit(ctx))

// wait for indexing to complete
_, err = testutil.RetryQuery(ctx, c, `{q(func: eq(name, "")){uid}}`)
require.NoError(t, err)

tests := []struct {
in, out string
}{
Expand Down Expand Up @@ -818,7 +828,7 @@ func QueryHashIndex(t *testing.T, c *dgo.Dgraph) {
}

for _, tc := range tests {
resp, err := c.NewTxn().Query(ctx, tc.in)
resp, err := testutil.RetryQuery(ctx, c, tc.in)
require.NoError(t, err)
testutil.CompareJSON(t, tc.out, string(resp.Json))
}
Expand All @@ -832,9 +842,11 @@ func RegexpToggleTrigramIndex(t *testing.T, c *dgo.Dgraph) {
name: string @index(term) @lang .
`,
}))
_, err := testutil.RetryQuery(ctx, c, `{q(func: anyofterms(name, "")){uid}}`)
require.NoError(t, err)

txn := c.NewTxn()
_, err := txn.Mutate(ctx, &api.Mutation{
_, err = txn.Mutate(ctx, &api.Mutation{
SetNquads: []byte(`
_:x1 <name> "The luck is in the details" .
_:x1 <name> "The art is in the details"@en .
Expand Down Expand Up @@ -867,7 +879,7 @@ func RegexpToggleTrigramIndex(t *testing.T, c *dgo.Dgraph) {

t.Log("testing without trigram index")
for _, tc := range tests {
resp, err := c.NewTxn().Query(ctx, tc.in)
resp, err := testutil.RetryQuery(ctx, c, tc.in)
require.NoError(t, err)
testutil.CompareJSON(t, tc.out, string(resp.Json))
}
Expand All @@ -877,10 +889,12 @@ func RegexpToggleTrigramIndex(t *testing.T, c *dgo.Dgraph) {
name: string @index(trigram) @lang .
`,
}))
_, err = testutil.RetryQuery(ctx, c, `{q(func: regexp(name, /name/)){uid}}`)
require.NoError(t, err)

t.Log("testing with trigram index")
for _, tc := range tests {
resp, err := c.NewTxn().Query(ctx, tc.in)
resp, err := testutil.RetryQuery(ctx, c, tc.in)
require.NoError(t, err)
testutil.CompareJSON(t, tc.out, string(resp.Json))
}
Expand All @@ -890,9 +904,11 @@ func RegexpToggleTrigramIndex(t *testing.T, c *dgo.Dgraph) {
name: string @index(term) @lang .
`,
}))
_, err = testutil.RetryQuery(ctx, c, `{q(func: anyofterms(name, "")){uid}}`)
require.NoError(t, err)

t.Log("testing without trigram index at root")
_, err = c.NewTxn().Query(ctx, `{q(func:regexp(name, /art/)) {name}}`)
_, err = testutil.RetryQuery(ctx, c, `{q(func:regexp(name, /art/)) {name}}`)
require.Error(t, err)
require.Contains(t, err.Error(), "Attribute name does not have trigram index for regex matching.")
}
Expand Down Expand Up @@ -936,7 +952,7 @@ func GroupByUidWorks(t *testing.T, c *dgo.Dgraph) {
},
}
for _, tc := range tests {
resp, err := c.NewTxn().Query(ctx, tc.in)
resp, err := testutil.RetryQuery(ctx, c, tc.in)
require.NoError(t, err)
testutil.CompareJSON(t, tc.out, string(resp.Json))
}
Expand Down
10 changes: 9 additions & 1 deletion testutil/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,20 @@ func RetryQueryWithTxn(ctx context.Context, txn *dgo.Txn, q string) (*api.Respon
}

func retryQuery(ctx context.Context, f func() (*api.Response, error)) (*api.Response, error) {
retries := 0
maxRetries := 200
for {
retries++
resp, err := f()
if retries > maxRetries {
return resp, err
}

if err != nil && (strings.Contains(err.Error(), "Please retry") ||
strings.Contains(err.Error(), "is not indexed") ||
strings.Contains(err.Error(), "doesn't have reverse edge") ||
strings.Contains(err.Error(), "Need @count directive in schema")) {
strings.Contains(err.Error(), "Need @count directive in schema") ||
strings.Contains(err.Error(), "does not have trigram index")) {

time.Sleep(10 * time.Millisecond)
continue
Expand Down

0 comments on commit 674b79e

Please sign in to comment.