-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
tests.ts
202 lines (172 loc) · 6.03 KB
/
tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import testMatrix from './_matrix'
// @ts-ignore
import type { Prisma, PrismaClient, Tag } from './node_modules/@prisma/client'
declare let prisma: PrismaClient
// https://github.com/prisma/prisma/issues/8832
testMatrix.setupTestSuite(
({ provider }) => {
async function createTags(length: number): Promise<number[]> {
const ids = Array.from({ length }, (_, i) => i + 1)
const data = ids.map((id) => ({ id }))
await prisma.tag.createMany({
data,
})
return ids
}
async function getTagsFindManyIn(ids: number[]): Promise<Tag[]> {
const tags = await prisma.tag.findMany({
where: {
id: {
in: ids,
},
},
})
return tags
}
async function getTagsFindManyInclude(): Promise<Tag[]> {
const tags = await prisma.tag.findMany({
include: {
posts: true,
},
})
return tags
}
async function clean() {
const cleanPrismaPromises = [prisma.tagsOnPosts.deleteMany(), prisma.post.deleteMany(), prisma.tag.deleteMany()]
await prisma.$transaction(cleanPrismaPromises)
}
describe.skip('issue #8832', () => {
beforeEach(async () => {
await clean()
}, 10_000)
test('should succeed when "in" has 32766 ids', async () => {
const n = 32766
const ids = await createTags(n)
const tags = await getTagsFindManyIn(ids)
expect(tags.length).toBe(n)
})
test('should succeed when "include" involves 32766 records', async () => {
const n = 32766
await createTags(n)
const tags = await getTagsFindManyInclude()
expect(tags.length).toBe(n)
})
test('should succeed when "in" has 32767 ids', async () => {
const n = 32767
const ids = await createTags(n)
const tags = await getTagsFindManyIn(ids)
expect(tags.length).toBe(n)
})
test('should succeed when "include" involves 32767 records', async () => {
const n = 32767
await createTags(n)
const tags = await getTagsFindManyInclude()
expect(tags.length).toBe(n)
})
test('should succeed when "in" has 32768 ids', async () => {
const n = 32768
const ids = await createTags(n)
const tags = await getTagsFindManyIn(ids)
expect(tags.length).toBe(n)
})
test('should succeed when "include" involves 32768 records', async () => {
const n = 32768
await createTags(n)
const tags = await getTagsFindManyInclude()
expect(tags.length).toBe(n)
})
test('should succeed when "in" has 65536 ids', async () => {
const n = 65536
const ids = await createTags(n)
const tags = await getTagsFindManyIn(ids)
expect(tags.length).toBe(n)
})
test('should succeed when "include" involves 65536 records', async () => {
const n = 65536
await createTags(n)
const tags = await getTagsFindManyInclude()
expect(tags.length).toBe(n)
})
/**
* Highlight scenarios of the query chunking logic behavior depending on how the bind variables are counted
* in the query filters.
*/
describe('unhandled filters', () => {
test('should fail with `Assertion violation` when "in" is repeated at least twice and "n" is the default value of $QUERY_BATCH_SIZE', async () => {
expect.assertions(3)
const n = 32766
const ids = await createTags(n)
try {
await prisma.tag.findMany({
where: {
OR: [
{
id: { in: ids },
},
{
id: { in: ids },
},
],
},
})
} catch (e) {
const error = e as Prisma.PrismaClientKnownRequestError
expect(error.message).toContain(
'Assertion violation on the database: `too many bind variables in prepared statement, expected maximum of 32767, received 65533`',
)
expect(error.code).toBe('P2035')
expect(error.meta).toMatchObject({
database_error:
'too many bind variables in prepared statement, expected maximum of 32767, received 65533',
})
}
})
test('should fail with `Assertion violation` when "in" has 32766 ids and a "take" filter', async () => {
expect.assertions(3)
const n = 32766
const ids = await createTags(n)
try {
await prisma.tag.findMany({
where: {
id: { in: ids },
},
take: 1,
})
} catch (e) {
const error = e as Prisma.PrismaClientKnownRequestError
expect(error.message).toContain(
'Assertion violation on the database: `too many bind variables in prepared statement, expected maximum of 32767, received 32768`',
)
expect(error.code).toBe('P2035')
expect(error.meta).toMatchObject({
database_error:
'too many bind variables in prepared statement, expected maximum of 32767, received 32768',
})
}
})
test('should succeed when "in" has 32766 ids and a "skip" filter', async () => {
const n = 32766
const ids = await createTags(n)
const tags = await prisma.tag.findMany({
where: {
id: { in: ids },
},
skip: 1,
})
expect(tags.length).toBe(n - 1)
})
})
})
},
{
optOut: {
from: ['mysql', 'sqlserver', 'cockroachdb', 'sqlite', 'mongodb'],
reason: 'we have only captured this issue with postgres',
},
// see: https://github.com/prisma/mini-proxy/issues/30
skipDataProxy: {
runtimes: ['node', 'edge'],
reason: "Mini-Proxy can't currently handle big queries, un-skip when it starts using QE server instead of CLI",
},
},
)