Skip to content

Commit

Permalink
test: Convert explain dagscan tests to new explain setup (#1474)
Browse files Browse the repository at this point in the history
## Relevant issue(s)
- Part of #953
- Resolves #1473

## Description
Continue converting explain tests to the new explain setup before we can
integrate the entire setup to the new action based setup. #953 Has a lot
more detail on the entire plan.

- Fixes test names and some fixtures for the limit test.
- This PR converts all the default dagscan explain tests to the new
explain setup.
- Converts a wrong usage explain test case.
  • Loading branch information
shahzadlone authored May 10, 2023
1 parent 5df70af commit 053a08c
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 188 deletions.
168 changes: 83 additions & 85 deletions tests/integration/explain/default/dagscan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ package test_explain_default
import (
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
explainUtils "github.com/sourcenetwork/defradb/tests/integration/explain"
)

func TestExplainCommitsDagScan(t *testing.T) {
test := testUtils.RequestTestCase{
var dagScanPattern = dataMap{
"explain": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"dagScanNode": dataMap{},
},
},
},
}

func TestDefaultExplainCommitsDagScanQueryOp(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{

Description: "Explain commits query.",
Description: "Explain (default) commits query-op.",

Request: `query @explain {
commits (dockey: "bae-41598f0c-19bc-5da6-813b-e80f14a10df3", fieldId: "1") {
Expand Down Expand Up @@ -47,36 +57,33 @@ func TestExplainCommitsDagScan(t *testing.T) {
},
},

Results: []dataMap{
ExpectedPatterns: []dataMap{dagScanPattern},

ExpectedTargets: []explainUtils.PlanNodeTargetCase{
{
"explain": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"filter": nil,
"dagScanNode": dataMap{
"cid": nil,
"fieldId": "1",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/1",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/2",
},
},
},
TargetNodeName: "dagScanNode",
IncludeChildNodes: true, // Shouldn't have any as this is the last node in the chain.
ExpectedAttributes: dataMap{
"cid": nil,
"fieldId": "1",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/1",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/2",
},
},
},
},
},
}

executeTestCase(t, test)
runExplainTest(t, test)
}

func TestExplainCommitsDagScanWithoutField(t *testing.T) {
test := testUtils.RequestTestCase{
func TestDefaultExplainCommitsDagScanQueryOpWithoutField(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{

Description: "Explain commits query with only dockey (no field).",
Description: "Explain (default) commits query-op with only dockey (no field).",

Request: `query @explain {
commits (dockey: "bae-41598f0c-19bc-5da6-813b-e80f14a10df3") {
Expand Down Expand Up @@ -104,36 +111,33 @@ func TestExplainCommitsDagScanWithoutField(t *testing.T) {
},
},

Results: []dataMap{
ExpectedPatterns: []dataMap{dagScanPattern},

ExpectedTargets: []explainUtils.PlanNodeTargetCase{
{
"explain": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"filter": nil,
"dagScanNode": dataMap{
"cid": nil,
"fieldId": nil,
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df4",
},
},
},
TargetNodeName: "dagScanNode",
IncludeChildNodes: true, // Shouldn't have any as this is the last node in the chain.
ExpectedAttributes: dataMap{
"cid": nil,
"fieldId": nil,
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df4",
},
},
},
},
},
}

executeTestCase(t, test)
runExplainTest(t, test)
}

func TestExplainLatestCommitsDagScan(t *testing.T) {
test := testUtils.RequestTestCase{
func TestDefaultExplainLatestCommitsDagScanQueryOp(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{

Description: "Explain latestCommits query.",
Description: "Explain (default) latestCommits query-op.",

Request: `query @explain {
latestCommits(dockey: "bae-41598f0c-19bc-5da6-813b-e80f14a10df3", fieldId: "1") {
Expand Down Expand Up @@ -162,36 +166,33 @@ func TestExplainLatestCommitsDagScan(t *testing.T) {
},
},

Results: []dataMap{
ExpectedPatterns: []dataMap{dagScanPattern},

ExpectedTargets: []explainUtils.PlanNodeTargetCase{
{
"explain": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"filter": nil,
"dagScanNode": dataMap{
"cid": nil,
"fieldId": "1",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/1",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/2",
},
},
},
TargetNodeName: "dagScanNode",
IncludeChildNodes: true, // Shouldn't have any as this is the last node in the chain.
ExpectedAttributes: dataMap{
"cid": nil,
"fieldId": "1",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/1",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/2",
},
},
},
},
},
}

executeTestCase(t, test)
runExplainTest(t, test)
}

func TestExplainLatestCommitsDagScanWithoutField(t *testing.T) {
test := testUtils.RequestTestCase{
func TestDefaultExplainLatestCommitsDagScanQueryOpWithoutField(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{

Description: "Explain latestCommits query with only dockey (no field).",
Description: "Explain (default) latestCommits query-op with only dockey (no field).",

Request: `query @explain {
latestCommits(dockey: "bae-41598f0c-19bc-5da6-813b-e80f14a10df3") {
Expand Down Expand Up @@ -220,36 +221,33 @@ func TestExplainLatestCommitsDagScanWithoutField(t *testing.T) {
},
},

Results: []dataMap{
ExpectedPatterns: []dataMap{dagScanPattern},

ExpectedTargets: []explainUtils.PlanNodeTargetCase{
{
"explain": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"filter": nil,
"dagScanNode": dataMap{
"cid": nil,
"fieldId": "C",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/C",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/D",
},
},
},
TargetNodeName: "dagScanNode",
IncludeChildNodes: true, // Shouldn't have any as this is the last node in the chain.
ExpectedAttributes: dataMap{
"cid": nil,
"fieldId": "C",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/C",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/D",
},
},
},
},
},
}

executeTestCase(t, test)
runExplainTest(t, test)
}

func TestExplainLatestCommitsDagScanWithoutDocKey_Failure(t *testing.T) {
test := testUtils.RequestTestCase{
func TestDefaultExplainLatestCommitsDagScanWithoutDocKey_Failure(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{

Description: "Explain latestCommits query without DocKey.",
Description: "Explain (default) latestCommits query without DocKey.",

Request: `query @explain {
latestCommits(fieldId: "1") {
Expand All @@ -263,13 +261,13 @@ func TestExplainLatestCommitsDagScanWithoutDocKey_Failure(t *testing.T) {
ExpectedError: "Field \"latestCommits\" argument \"dockey\" of type \"ID!\" is required but not provided.",
}

executeTestCase(t, test)
runExplainTest(t, test)
}

func TestExplainLatestCommitsDagScanWithoutAnyArguments_Failure(t *testing.T) {
test := testUtils.RequestTestCase{
func TestDefaultExplainLatestCommitsDagScanWithoutAnyArguments_Failure(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{

Description: "Explain latestCommits query without any arguments.",
Description: "Explain (default) latestCommits query without any arguments.",

Request: `query @explain {
latestCommits {
Expand All @@ -283,5 +281,5 @@ func TestExplainLatestCommitsDagScanWithoutAnyArguments_Failure(t *testing.T) {
ExpectedError: "Field \"latestCommits\" argument \"dockey\" of type \"ID!\" is required but not provided.",
}

executeTestCase(t, test)
runExplainTest(t, test)
}
6 changes: 3 additions & 3 deletions tests/integration/explain/default/invalid_type_arg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ package test_explain_default
import (
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
explainUtils "github.com/sourcenetwork/defradb/tests/integration/explain"
)

func TestInvalidExplainRequestTypeReturnsError(t *testing.T) {
test := testUtils.RequestTestCase{
test := explainUtils.ExplainRequestTestCase{
Description: "Invalid type of explain request should error.",

Request: `query @explain(type: invalid) {
Expand All @@ -40,5 +40,5 @@ func TestInvalidExplainRequestTypeReturnsError(t *testing.T) {
ExpectedError: "Argument \"type\" has invalid value invalid.\nExpected type \"ExplainType\", found invalid.",
}

executeTestCase(t, test)
runExplainTest(t, test)
}
66 changes: 10 additions & 56 deletions tests/integration/explain/default/with_limit_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import (
explainUtils "github.com/sourcenetwork/defradb/tests/integration/explain"
)

func TestExplainQueryWithMultipleConflictingInnerLimits(t *testing.T) {
func TestDefaultExplainRequestWithOnlyLimitOnRelatedChildWithCount(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{
Description: "Explain Query With multiple conflicting inner limit nodes.",

Description: "Explain (default) request with limit on related child with count.",

Request: `query @explain {
Author {
Expand Down Expand Up @@ -128,34 +129,10 @@ func TestExplainQueryWithMultipleConflictingInnerLimits(t *testing.T) {
"selectNode": dataMap{
"parallelNode": []dataMap{
{
"typeIndexJoin": dataMap{
"root": dataMap{
"scanNode": dataMap{},
},
"subType": dataMap{
"selectTopNode": dataMap{
"limitNode": dataMap{
"selectNode": dataMap{
"scanNode": dataMap{},
},
},
},
},
},
"typeIndexJoin": limitTypeJoinPattern,
},
{
"typeIndexJoin": dataMap{
"root": dataMap{
"scanNode": dataMap{},
},
"subType": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"scanNode": dataMap{},
},
},
},
},
"typeIndexJoin": normalTypeJoinPattern,
},
},
},
Expand Down Expand Up @@ -192,9 +169,10 @@ func TestExplainQueryWithMultipleConflictingInnerLimits(t *testing.T) {
runExplainTest(t, test)
}

func TestExplainQueryWithMultipleConflictingInnerLimitsAndOuterLimit(t *testing.T) {
func TestDefaultExplainRequestWithLimitArgsOnParentAndRelatedChildWithCount(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{
Description: "Explain Query With multiple conflicting inner limit nodes and an outer limit.",

Description: "Explain (default) request with limit args on parent and related child with count.",

Request: `query @explain {
Author(limit: 3, offset: 1) {
Expand Down Expand Up @@ -305,34 +283,10 @@ func TestExplainQueryWithMultipleConflictingInnerLimitsAndOuterLimit(t *testing.
"selectNode": dataMap{
"parallelNode": []dataMap{
{
"typeIndexJoin": dataMap{
"root": dataMap{
"scanNode": dataMap{},
},
"subType": dataMap{
"selectTopNode": dataMap{
"limitNode": dataMap{
"selectNode": dataMap{
"scanNode": dataMap{},
},
},
},
},
},
"typeIndexJoin": limitTypeJoinPattern,
},
{
"typeIndexJoin": dataMap{
"root": dataMap{
"scanNode": dataMap{},
},
"subType": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"scanNode": dataMap{},
},
},
},
},
"typeIndexJoin": normalTypeJoinPattern,
},
},
},
Expand Down
Loading

0 comments on commit 053a08c

Please sign in to comment.