-
Notifications
You must be signed in to change notification settings - Fork 8
test: assert the client returns a valid execution plan, not which plan the engine picked #609
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
Open
Naseem77
wants to merge
10
commits into
main
Choose a base branch
from
naseem77-align-plan-assertions-with-engine
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
72af5bf
test: use a slower query so the slowlog actually records it
Naseem77 1bbe3fa
test: use a slower query so the cluster slowlog actually records it
Naseem77 a845e40
test: use a slower query so the single client slowlog actually record…
Naseem77 8b79492
test: assert the client returns a valid execution plan, not which pla…
Naseem77 0169bd2
test: drop an unasserted exists(pattern) call from the edge constrain…
Naseem77 5604c59
Merge branch 'main' into naseem77-align-plan-assertions-with-engine
Naseem77 a9b33d2
Merge branch 'main' into naseem77-align-plan-assertions-with-engine
gkorland 369749d
test: assert exact shared execution plans
Naseem77 b8898ce
Merge branch 'main' into naseem77-align-plan-assertions-with-engine
Naseem77 ecaf311
ci: remove redundant docker-compose install
Naseem77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /** | ||
| * Assertions for the raw execution-plan arrays returned by the client. | ||
| * | ||
| * Prefer expectPlanShape wherever both engines produce the same operation | ||
| * tree. Keep expectExecutionPlan for documented engine-specific plans. | ||
| */ | ||
|
|
||
| import { expect } from "@jest/globals"; | ||
|
|
||
| const INDENT = " "; | ||
| const ENGINE_ROOT_OPERATIONS = new Set(["Results", "Commit"]); | ||
| const PROFILE_STATS = /\s*\|\s*Records produced: \d+,\s*Execution time: \d+\.\d+ ms\s*$/; | ||
|
|
||
| export function indentOf(line: string): number { | ||
| return (line.length - line.trimStart().length) / INDENT.length; | ||
| } | ||
|
|
||
| export function operationName(line: string): string { | ||
| return line.split("|")[0].trim(); | ||
| } | ||
|
|
||
| function operationLine(line: string): string { | ||
| return line.replace(PROFILE_STATS, "").trim(); | ||
| } | ||
|
|
||
| /** Asserts the reply is a well formed execution plan. */ | ||
| export function expectExecutionPlan(plan: string[], minOperations = 1): void { | ||
| expect(Array.isArray(plan)).toBe(true); | ||
| expect(plan.length).toBeGreaterThanOrEqual(minOperations); | ||
|
|
||
| plan.forEach((line, index) => { | ||
| expect(typeof line).toBe("string"); | ||
|
|
||
| // every line names an operation, optionally followed by its arguments | ||
| expect(operationName(line)).not.toBe(""); | ||
|
|
||
| // indentation is what conveys nesting, so it has to be whole levels, and | ||
| // an operation can only ever be one level deeper than the one above it | ||
| const indent = indentOf(line); | ||
| expect(Number.isInteger(indent)).toBe(true); | ||
| expect(indent).toBe(index === 0 ? 0 : Math.min(indent, indentOf(plan[index - 1]) + 1)); | ||
|
Naseem77 marked this conversation as resolved.
|
||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Asserts operation names and nesting exactly, and arguments on expected lines | ||
| * that include them after a `|`. Engine-only driver roots are ignored. | ||
| */ | ||
| export function expectPlanShape(plan: string[], expected: readonly string[]): void { | ||
| expectExecutionPlan(plan); | ||
| expect(expected.length).toBeGreaterThan(0); | ||
|
|
||
| const expectedRoot = operationName(expected[0]); | ||
| const skipRoot = | ||
| ENGINE_ROOT_OPERATIONS.has(operationName(plan[0])) && | ||
| operationName(plan[0]) !== expectedRoot; | ||
| const rootOffset = skipRoot ? 1 : 0; | ||
| const actual = plan.slice(rootOffset); | ||
|
|
||
| expect(actual).toHaveLength(expected.length); | ||
|
|
||
| expected.forEach((expectedLine, index) => { | ||
| const actualLine = actual[index]; | ||
| const expectedIndent = indentOf(expectedLine); | ||
| const actualIndent = indentOf(actualLine) - rootOffset; | ||
|
|
||
| expect(Number.isInteger(expectedIndent)).toBe(true); | ||
| expect(actualIndent).toBe(expectedIndent); | ||
|
|
||
| const expectedOperation = operationLine(expectedLine); | ||
| const actualOperation = expectedOperation.includes("|") | ||
| ? operationLine(actualLine) | ||
| : operationName(actualLine); | ||
| expect(actualOperation).toBe(expectedOperation); | ||
| }); | ||
| } | ||
|
|
||
| /** Asserts the reply is a well formed profile, statistics included. */ | ||
| export function expectProfile( | ||
| plan: string[], | ||
| minOperations = 1, | ||
| recordsProduced?: number | ||
| ): void { | ||
| expectExecutionPlan(plan, minOperations); | ||
|
|
||
| const counts = plan.map((line) => { | ||
| const records = line.match(/Records produced: (\d+)/); | ||
| const time = line.match(/Execution time: (\d+\.\d+) ms/); | ||
|
|
||
|
Naseem77 marked this conversation as resolved.
|
||
| // every operation is profiled, whichever operations they turn out to be | ||
| expect(records).not.toBeNull(); | ||
| expect(time).not.toBeNull(); | ||
|
|
||
| return parseInt(records![1], 10); | ||
| }); | ||
|
|
||
| if (recordsProduced !== undefined) { | ||
| // how many rows the query yields is a property of the query, not of the | ||
| // engine, so the client must report it whichever engine answered | ||
| expect(Math.max(...counts)).toBe(recordsProduced); | ||
| } | ||
| } | ||
|
|
||
| /** Asserts an exact profile plan while retaining all profile-stat checks. */ | ||
| export function expectProfileShape( | ||
| plan: string[], | ||
| expected: readonly string[], | ||
| recordsProduced?: number | ||
| ): void { | ||
| expectPlanShape(plan, expected); | ||
| expectProfile(plan, expected.length, recordsProduced); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.