Skip to content

Commit f3e1135

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 2cc271f commit f3e1135

File tree

16 files changed

+318
-0
lines changed

16 files changed

+318
-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(5_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: 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+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 (
17+
FOR v_entity1 IN v_node1.`children`[*]
18+
RETURN { obj: v_entity1, root: v_node1 }
19+
)
20+
)[**]
21+
LET v_root1 = v_child1.`root`
22+
RETURN {
23+
"key": v_child1.`obj`.`key`,
24+
"parent": (IS_NULL(v_root1) ? null : {
25+
"key": v_root1.`key`
26+
})
27+
}
28+
)
29+
})
30+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"RelationAndFieldTraversal": {
3+
"errors": [
4+
{
5+
"message": "AQL: query would use more memory than allowed [node #17: TraversalNode] [node #18: CalculationNode] [node #19: FilterNode] [node #20: CalculationNode] [node #34: SubqueryEndNode] [node #31: SubqueryStartNode] [node #13: FilterNode] [node #23: CalculationNode] [node #24: EnumerateListNode] [node #25: CalculationNode] [node #32: SubqueryEndNode] [node #28: CalculationNode] [node #29: ReturnNode] (while executing)",
6+
"locations": [
7+
{
8+
"line": 2,
9+
"column": 5
10+
}
11+
],
12+
"path": ["Super"]
13+
}
14+
],
15+
"data": {
16+
"Super": null
17+
}
18+
},
19+
"RelationAndFieldTraversalWithParent": {
20+
"errors": [
21+
{
22+
"message": "AQL: query would use more memory than allowed [node #17: TraversalNode] [node #18: CalculationNode] [node #19: FilterNode] [node #43: SubqueryStartNode] [node #22: FilterNode] [node #23: CalculationNode] [node #24: EnumerateListNode] [node #25: CalculationNode] [node #44: SubqueryEndNode] [node #42: SubqueryEndNode] [node #39: SubqueryStartNode] [node #13: FilterNode] [node #30: CalculationNode] [node #31: EnumerateListNode] [node #33: CalculationNode] [node #40: SubqueryEndNode] [node #36: CalculationNode] [node #37: ReturnNode] (while executing)",
23+
"locations": [
24+
{
25+
"line": 10,
26+
"column": 5
27+
}
28+
],
29+
"path": ["Super"]
30+
}
31+
],
32+
"data": {
33+
"Super": null
34+
}
35+
}
36+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
query RelationAndFieldTraversal {
2+
Super(key: "super1") {
3+
rootChildren {
4+
key
5+
}
6+
}
7+
}
8+
9+
query RelationAndFieldTraversalWithParent {
10+
Super(key: "super1") {
11+
rootChildren {
12+
key
13+
parent {
14+
key
15+
}
16+
}
17+
}
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
"roots": (
12+
FOR v_root1
13+
IN OUTBOUND v_super1 @@supers_roots
14+
FILTER v_root1 != null
15+
RETURN {
16+
"key": v_root1.`key`
17+
}
18+
)
19+
})
20+
}

0 commit comments

Comments
 (0)