Skip to content

Commit

Permalink
recreate the context variable for parallel test
Browse files Browse the repository at this point in the history
Also, use require.NoError instead of require.Nil for ensuring
that error is nil. This prints better when err is not nil.
  • Loading branch information
mangalaman93 committed Mar 11, 2023
1 parent 47c6b68 commit 677c35b
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 67 deletions.
18 changes: 9 additions & 9 deletions dql/upsert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ upsert {
}
`
_, err := ParseMutation(query)
require.Nil(t, err)
require.NoError(t, err)
}

func TestUpsertEx1(t *testing.T) {
Expand All @@ -205,7 +205,7 @@ upsert {
}
`
_, err := ParseMutation(query)
require.Nil(t, err)
require.NoError(t, err)
}

func TestUpsertWithSpaces(t *testing.T) {
Expand Down Expand Up @@ -238,7 +238,7 @@ upsert
}
`
_, err := ParseMutation(query)
require.Nil(t, err)
require.NoError(t, err)
}

func TestUpsertWithBlankNode(t *testing.T) {
Expand All @@ -262,7 +262,7 @@ upsert {
}
`
_, err := ParseMutation(query)
require.Nil(t, err)
require.NoError(t, err)
}

func TestUpsertMutationThenQuery(t *testing.T) {
Expand All @@ -286,7 +286,7 @@ upsert {
}
`
_, err := ParseMutation(query)
require.Nil(t, err)
require.NoError(t, err)
}

func TestUpsertWithFilter(t *testing.T) {
Expand All @@ -311,7 +311,7 @@ upsert {
}
`
_, err := ParseMutation(query)
require.Nil(t, err)
require.NoError(t, err)
}

func TestConditionalUpsertWithNewlines(t *testing.T) {
Expand All @@ -338,7 +338,7 @@ upsert {
}
`
_, err := ParseMutation(query)
require.Nil(t, err)
require.NoError(t, err)
}

func TestConditionalUpsertFuncTree(t *testing.T) {
Expand Down Expand Up @@ -367,7 +367,7 @@ upsert {
}
`
_, err := ParseMutation(query)
require.Nil(t, err)
require.NoError(t, err)
}

func TestConditionalUpsertMultipleFuncArg(t *testing.T) {
Expand Down Expand Up @@ -396,7 +396,7 @@ upsert {
}
`
_, err := ParseMutation(query)
require.Nil(t, err)
require.NoError(t, err)
}

func TestConditionalUpsertErrMissingRightRound(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions edgraph/access_ee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestValidateToken(t *testing.T) {
for _, userdata := range userDataList {
tokenString := generateJWT(userdata.namespace, userdata.userId, userdata.groupIds, expiry)
ud, err := validateToken(tokenString)
require.Nil(t, err)
require.NoError(t, err)
if ud.namespace != userdata.namespace || ud.userId != userdata.userId ||
!sliceCompare(ud.groupIds, userdata.groupIds) {

Expand Down Expand Up @@ -103,7 +103,7 @@ func TestGetAccessJwt(t *testing.T) {
for _, userdata := range userDataList {
jwtstr, _ := getAccessJwt(userdata.userId, grpLst, userdata.namespace)
ud, err := validateToken(jwtstr)
require.Nil(t, err)
require.NoError(t, err)
if ud.namespace != userdata.namespace || ud.userId != userdata.userId || !sliceCompare(ud.groupIds, g) {
t.Errorf("Actual output {%v %v %v} is not equal to the output %v generated from"+
" getAccessJwt() token", userdata.namespace, userdata.userId, grpLst, ud)
Expand All @@ -121,7 +121,7 @@ func TestGetRefreshJwt(t *testing.T) {
for _, userdata := range userDataList {
jwtstr, _ := getRefreshJwt(userdata.userId, userdata.namespace)
ud, err := validateToken(jwtstr)
require.Nil(t, err)
require.NoError(t, err)
if ud.namespace != userdata.namespace || ud.userId != userdata.userId {
t.Errorf("Actual output {%v %v} is not equal to the output {%v %v} generated from"+
"getRefreshJwt() token", userdata.namespace, userdata.userId, ud.namespace, ud.userId)
Expand Down
6 changes: 3 additions & 3 deletions ee/acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func getGrootAndGuardiansUid(t *testing.T, dg *dgo.Dgraph) (string, string) {
return grootUserUid, guardiansGroupUid
}

const defaultTimeToSleep = 1 * time.Second
const defaultTimeToSleep = 500 * time.Millisecond

const timeout = 5 * time.Second

Expand Down Expand Up @@ -1892,7 +1892,7 @@ func TestNewACLPredicates(t *testing.T) {
tc := tc // capture range variable
t.Run(tc.description, func(t *testing.T) {
t.Parallel()
ctx, cancel = context.WithTimeout(context.Background(), 100*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
defer cancel()

resp, err := userClient.NewTxn().Query(ctx, tc.input)
Expand Down Expand Up @@ -3212,7 +3212,7 @@ func TestAllowUIDAccess(t *testing.T) {
`

resp, err := userClient.NewReadOnlyTxn().Query(ctx, uidQuery)
require.Nil(t, err)
require.NoError(t, err)
testutil.CompareJSON(t, `{"me":[{"name":"100th User", "uid": "0x64"}]}`, string(resp.GetJson()))
}

Expand Down
10 changes: 5 additions & 5 deletions graphql/e2e/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ func getColID(t *testing.T, tcase TestCase) string {
common.RequireNoGQLErrors(t, gqlResponse)

err := json.Unmarshal(gqlResponse.Data, &result)
require.Nil(t, err)
require.NoError(t, err)

if len(result.QueryColumn) > 0 {
return result.QueryColumn[0].ColID
Expand Down Expand Up @@ -1138,7 +1138,7 @@ func getProjectID(t *testing.T, tcase TestCase) string {
common.RequireNoGQLErrors(t, gqlResponse)

err := json.Unmarshal(gqlResponse.Data, &result)
require.Nil(t, err)
require.NoError(t, err)

if len(result.QueryProject) > 0 {
return result.QueryProject[0].ProjID
Expand Down Expand Up @@ -2204,7 +2204,7 @@ func TestAuthWithSecretDirective(t *testing.T) {
}

err := json.Unmarshal([]byte(gqlResponse.Data), &result)
require.Nil(t, err)
require.NoError(t, err)

opt := cmpopts.IgnoreFields(common.User{}, "Password")
if diff := cmp.Diff(newUser, result.CheckUserPassword, opt); diff != "" {
Expand Down Expand Up @@ -2237,7 +2237,7 @@ func TestAuthWithSecretDirective(t *testing.T) {
}

err = json.Unmarshal([]byte(gqlResponse.Data), &addLogResult)
require.Nil(t, err)
require.NoError(t, err)
// Id of the created log
logID := addLogResult.AddLog.Log[0].Id

Expand All @@ -2248,7 +2248,7 @@ func TestAuthWithSecretDirective(t *testing.T) {
}

err = json.Unmarshal([]byte(gqlResponse.Data), &resultLog)
require.Nil(t, err)
require.NoError(t, err)

require.Equal(t, resultLog.CheckLogPassword.Id, logID)

Expand Down
4 changes: 2 additions & 2 deletions graphql/e2e/common/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3593,7 +3593,7 @@ func checkUser(t *testing.T, userObj, expectedObj *user) {
}

err := json.Unmarshal([]byte(gqlResponse.Data), &result)
require.Nil(t, err)
require.NoError(t, err)

opt := cmpopts.IgnoreFields(user{}, "Password")
if diff := cmp.Diff(expectedObj, result.CheckUserPasword, opt); diff != "" {
Expand All @@ -3620,7 +3620,7 @@ func checkUserPasswordWithAlias(t *testing.T, userObj, expectedObj *user) {
}

err := json.Unmarshal([]byte(gqlResponse.Data), &result)
require.Nil(t, err)
require.NoError(t, err)

opt := cmpopts.IgnoreFields(user{}, "Password")
if diff := cmp.Diff(expectedObj, result.CheckUserPasword, opt); diff != "" {
Expand Down
24 changes: 12 additions & 12 deletions graphql/e2e/subscription/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestSubscription(t *testing.T) {
}
}`,
}, `{}`)
require.Nil(t, err)
require.NoError(t, err)
res, err := subscriptionClient.RecvMsg()
require.NoError(t, err)

Expand Down Expand Up @@ -232,7 +232,7 @@ func TestSubscriptionAuth(t *testing.T) {
}
}`,
}, payload)
require.Nil(t, err)
require.NoError(t, err)

res, err := subscriptionClient.RecvMsg()
require.NoError(t, err)
Expand Down Expand Up @@ -352,7 +352,7 @@ func TestSubscriptionWithAuthShouldExpireWithJWT(t *testing.T) {
}
}`,
}, payload)
require.Nil(t, err)
require.NoError(t, err)

res, err := subscriptionClient.RecvMsg()
require.NoError(t, err)
Expand Down Expand Up @@ -442,7 +442,7 @@ func TestSubscriptionAuthWithoutExpiry(t *testing.T) {
}
}`,
}, payload)
require.Nil(t, err)
require.NoError(t, err)

res, err := subscriptionClient.RecvMsg()
require.NoError(t, err)
Expand Down Expand Up @@ -504,7 +504,7 @@ func TestSubscriptionAuth_SameQueryAndClaimsButDifferentExpiry_ShouldExpireIndep
}
}`,
}, payload)
require.Nil(t, err)
require.NoError(t, err)

res, err := subscriptionClient.RecvMsg()
require.NoError(t, err)
Expand All @@ -528,7 +528,7 @@ func TestSubscriptionAuth_SameQueryAndClaimsButDifferentExpiry_ShouldExpireIndep
}
}`,
}, payload)
require.Nil(t, err)
require.NoError(t, err)

res, err = subscriptionClient1.RecvMsg()
require.NoError(t, err)
Expand Down Expand Up @@ -655,7 +655,7 @@ func TestSubscriptionAuth_SameQueryDifferentClaimsAndExpiry_ShouldExpireIndepend
}
}`,
}, payload)
require.Nil(t, err)
require.NoError(t, err)

res, err := subscriptionClient.RecvMsg()
require.NoError(t, err)
Expand Down Expand Up @@ -701,7 +701,7 @@ func TestSubscriptionAuth_SameQueryDifferentClaimsAndExpiry_ShouldExpireIndepend
}
}`,
}, payload)
require.Nil(t, err)
require.NoError(t, err)

res, err = subscriptionClient1.RecvMsg()
require.NoError(t, err)
Expand Down Expand Up @@ -849,7 +849,7 @@ func TestSubscriptionAuthHeaderCaseInsensitive(t *testing.T) {
}
}`,
}, payload)
require.Nil(t, err)
require.NoError(t, err)

res, err := subscriptionClient.RecvMsg()
require.NoError(t, err)
Expand Down Expand Up @@ -896,7 +896,7 @@ func TestSubscriptionAuth_MultiSubscriptionResponses(t *testing.T) {
}
}`,
}, payload)
require.Nil(t, err)
require.NoError(t, err)

res, err := subscriptionClient.RecvMsg()
require.NoError(t, err)
Expand Down Expand Up @@ -925,7 +925,7 @@ func TestSubscriptionAuth_MultiSubscriptionResponses(t *testing.T) {
}
}`,
}, payload)
require.Nil(t, err)
require.NoError(t, err)

res, err = subscriptionClient1.RecvMsg()
require.NoError(t, err)
Expand Down Expand Up @@ -1004,7 +1004,7 @@ func TestSubscriptionWithCustomDQL(t *testing.T) {
}
}`,
}, `{}`)
require.Nil(t, err)
require.NoError(t, err)
res, err := subscriptionClient.RecvMsg()
require.NoError(t, err)

Expand Down
10 changes: 5 additions & 5 deletions graphql/resolve/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func TestVerificationWithJWKUrl(t *testing.T) {
ctx := metadata.NewIncomingContext(context.Background(), md)

_, err = metainfo.ExtractCustomClaims(ctx)
require.Nil(t, err)
require.NoError(t, err)
}

func TestVerificationWithMultipleJWKUrls(t *testing.T) {
Expand Down Expand Up @@ -360,7 +360,7 @@ func TestVerificationWithMultipleJWKUrls(t *testing.T) {
require.True(t, strings.Contains(err.Error(),
"unable to parse jwt token:token is unverifiable: Keyfunc returned an error"))
} else {
require.Nil(t, err)
require.NoError(t, err)
}
})
}
Expand Down Expand Up @@ -452,7 +452,7 @@ func queryRewriting(t *testing.T, sch string, authMeta *testutil.AuthMeta, b []b
require.Equal(t, err.Error(), tcase.Error.Error())
require.Nil(t, dgQuery)
} else {
require.Nil(t, err)
require.NoError(t, err)
require.Equal(t, tcase.DGQuery, dgraph.AsString(dgQuery))
}
// Check for unused variables.
Expand Down Expand Up @@ -591,14 +591,14 @@ func mutationQueryRewriting(t *testing.T, sch string, authMeta *testutil.AuthMet

_, _, _ = rewriter.RewriteQueries(context.Background(), gqlMutation)
_, err = rewriter.Rewrite(ctx, gqlMutation, tt.idExistence)
require.Nil(t, err)
require.NoError(t, err)

// -- Act --
dgQuery, err := rewriter.FromMutationResult(
ctx, gqlMutation, tt.assigned, tt.result)

// -- Assert --
require.Nil(t, err)
require.NoError(t, err)
require.Equal(t, tt.dgQuery, dgraph.AsString(dgQuery))

// Check for unused variables.
Expand Down
4 changes: 2 additions & 2 deletions graphql/resolve/mutation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,14 @@ func TestMutationQueryRewriting(t *testing.T) {

_, _, _ = rewriter.RewriteQueries(context.Background(), gqlMutation)
_, err = rewriter.Rewrite(context.Background(), gqlMutation, tt.idExistence)
require.Nil(t, err)
require.NoError(t, err)

// -- Act --
dgQuery, err := rewriter.FromMutationResult(
context.Background(), gqlMutation, tt.assigned, tt.result)

// -- Assert --
require.Nil(t, err)
require.NoError(t, err)
require.Equal(t, tcase.DGQuery, dgraph.AsString(dgQuery))
})
}
Expand Down
2 changes: 1 addition & 1 deletion graphql/resolve/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestQueryRewriting(t *testing.T) {
gqlQuery := test.GetQuery(t, op)

dgQuery, err := testRewriter.Rewrite(context.Background(), gqlQuery)
require.Nil(t, err)
require.NoError(t, err)
require.Equal(t, tcase.DGQuery, dgraph.AsString(dgQuery))
})
}
Expand Down
2 changes: 1 addition & 1 deletion query/fastjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func subgraphWithSingleResultAndSingleValue(val *pb.TaskValue) *SubGraph {

func assertJSON(t *testing.T, expected string, sg *SubGraph) {
buf, err := ToJson(context.Background(), &Latency{}, []*SubGraph{sg}, nil)
require.Nil(t, err)
require.NoError(t, err)
require.Equal(t, expected, string(buf))
}

Expand Down
2 changes: 1 addition & 1 deletion query/outputnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func TestMarshalTimeJson(t *testing.T) {

for _, tc := range timesToMarshal {
out, err := marshalTimeJson(tc.in)
require.Nil(t, err)
require.NoError(t, err)
require.Equal(t, tc.out, string(out))
}
}
Loading

0 comments on commit 677c35b

Please sign in to comment.