Skip to content

Commit 1c74caa

Browse files
committed
test: add tests for excessive memory usage in traversal and collect fields
The tests currently assert that the memory limit is exceeded. This is expected and will be fixed in an upcoming commit by a performance improvement.
1 parent 1f918d5 commit 1c74caa

File tree

13 files changed

+277
-0
lines changed

13 files changed

+277
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"authRoles": ["user"]
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"databases": {
3+
// performance is only relevant for arangodb
4+
// in-memory has other ordering behavior so we would need to use orderBy, which affects performance tests
5+
"in-memory": {
6+
"ignore": true
7+
}
8+
}
9+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
type Super @rootEntity {
2+
key: String @key
3+
roots: [Root] @relation
4+
rootChildren: [Child] @collect(path: "roots.children")
5+
rootGrandchildren: [Grandchild] @collect(path: "roots.children.children")
6+
rootExtensionGrandchildren: [ExtensionGrandchild]
7+
@collect(path: "roots.children.extension.children")
8+
}
9+
10+
type Root @rootEntity {
11+
key: String @key
12+
children: [Child]
13+
grandchildren: [Grandchild] @collect(path: "children.children")
14+
extensionGrandchildren: [ExtensionGrandchild] @collect(path: "children.extension.children")
15+
payload: String
16+
}
17+
18+
type Child @childEntity {
19+
key: String
20+
children: [Grandchild]
21+
extension: Extension
22+
parent: Root @parent
23+
root: Root @root
24+
}
25+
26+
type Extension @entityExtension {
27+
children: [ExtensionGrandchild]
28+
}
29+
30+
type Grandchild @childEntity {
31+
key: String
32+
parent: Child @parent
33+
root: Root @root
34+
}
35+
36+
type ExtensionGrandchild @childEntity {
37+
key: String
38+
root: Root @root
39+
parent: Child @parent
40+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"permissionProfiles": {
3+
"default": {
4+
"permissions": [
5+
{
6+
"roles": ["user"],
7+
"access": "readWrite"
8+
}
9+
]
10+
}
11+
}
12+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { InitTestDataContext } from '../init-test-data-context';
2+
import gql from 'graphql-tag';
3+
4+
export default async function init(context: InitTestDataContext) {
5+
await context.executeGraphql(
6+
gql`
7+
mutation Init($input: CreateSuperInput!) {
8+
createSuper(input: $input) {
9+
key
10+
}
11+
}
12+
`,
13+
{
14+
variables: {
15+
input: {
16+
key: 'super1',
17+
createRoots: [...Array(10).keys()].map((rootIndex) => ({
18+
key: `root${rootIndex}`,
19+
payload: generateRandomString(1_000_000),
20+
children: [...Array(10).keys()].map((childIndex) => ({
21+
key: `child${rootIndex}_${childIndex}`,
22+
})),
23+
})),
24+
},
25+
},
26+
authRoles: ['user'],
27+
},
28+
);
29+
}
30+
31+
function generateRandomString(length: number): string {
32+
return Array(Math.floor(length / 2))
33+
.fill(0)
34+
.map(() => Math.floor(Math.random() * 256))
35+
.map((b) => ('0' + b.toString(16)).slice(-2))
36+
.join('');
37+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
LET v_root1 = FIRST((
2+
FOR v_root2
3+
IN @@roots
4+
FILTER (v_root2.`key` == @var1)
5+
LIMIT @var2
6+
RETURN v_root2
7+
))
8+
RETURN {
9+
"Root": (IS_NULL(v_root1) ? null : {
10+
"payload": v_root1.`payload`,
11+
"key": v_root1.`key`
12+
})
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
LET v_super1 = FIRST((
2+
FOR v_super2
3+
IN @@supers
4+
FILTER (v_super2.`key` == @var1)
5+
LIMIT @var2
6+
RETURN v_super2
7+
))
8+
RETURN {
9+
"Super": (IS_NULL(v_super1) ? null : {
10+
"key": v_super1.`key`
11+
})
12+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"ExpectedToSucceed": {
3+
"data": {
4+
"Super": {
5+
"key": "super1"
6+
}
7+
}
8+
},
9+
"ExpectedToFail": {
10+
"errors": [
11+
{
12+
"message": "AQL: query would use more memory than allowed [node #12: IndexNode] [node #6: LimitNode] [node #14: SubqueryEndNode] [node #9: CalculationNode] [node #10: CalculationNode] [node #11: ReturnNode] (while executing)",
13+
"locations": [
14+
{
15+
"line": 8,
16+
"column": 5
17+
}
18+
],
19+
"path": [
20+
"Root"
21+
]
22+
}
23+
],
24+
"data": {
25+
"Root": null
26+
}
27+
}
28+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
query ExpectedToSucceed {
2+
Super(key: "super1") {
3+
key
4+
}
5+
}
6+
7+
query ExpectedToFail {
8+
Root(key: "root1") {
9+
payload
10+
key
11+
}
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
WITH @@roots
2+
LET v_super1 = FIRST((
3+
FOR v_super2
4+
IN @@supers
5+
FILTER (v_super2.`key` == @var1)
6+
LIMIT @var2
7+
RETURN v_super2
8+
))
9+
RETURN {
10+
"Super": (IS_NULL(v_super1) ? null : {
11+
"rootChildren": (
12+
FOR v_child1
13+
IN (
14+
FOR v_node1, v_edge1, v_path1 IN @var3..@var4 OUTBOUND v_super1 @@supers_roots
15+
FILTER v_node1 != null
16+
RETURN v_node1.`children`[*]
17+
)[**]
18+
RETURN {
19+
"key": v_child1.`key`
20+
}
21+
)
22+
})
23+
}

0 commit comments

Comments
 (0)