Skip to content

Commit b221d9c

Browse files
committed
test: Improve the test timeout definition
The timeout was being defined using the jasmine global variable and it was causing some flakyness in the tests.
1 parent 26b8b97 commit b221d9c

16 files changed

+1160
-944
lines changed

test/bolt-v3.test.js

+141-91
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,18 @@ describe('#integration Bolt V3 API', () => {
3434
let driver
3535
let session
3636
let protocolVersion
37-
let originalTimeout
3837

3938
beforeEach(async () => {
4039
driver = neo4j.driver(
4140
`bolt://${sharedNeo4j.hostname}`,
4241
sharedNeo4j.authToken
4342
)
4443
session = driver.session()
45-
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
46-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000
4744

4845
protocolVersion = await sharedNeo4j.cleanupAndGetProtocolVersion(driver)
4946
})
5047

5148
afterEach(async () => {
52-
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
5349
await session.close()
5450
await driver.close()
5551
})
@@ -73,7 +69,7 @@ describe('#integration Bolt V3 API', () => {
7369
)
7470
const receivedMetadatas = result.records.map(r => r.get('metaData'))
7571
expect(receivedMetadatas).toContain(metadata)
76-
})
72+
}, 20000)
7773

7874
it('should set transaction timeout for auto-commit transaction', async () => {
7975
if (!databaseSupportsBoltV3()) {
@@ -104,47 +100,77 @@ describe('#integration Bolt V3 API', () => {
104100
}
105101
await tx.rollback()
106102
await otherSession.close()
107-
})
108-
109-
it('should set transaction metadata with read transaction function', () =>
110-
testTransactionMetadataWithTransactionFunctions(true))
111-
112-
it('should set transaction metadata with write transaction function', () =>
113-
testTransactionMetadataWithTransactionFunctions(false))
114-
115-
it('should fail auto-commit transaction with metadata when database does not support Bolt V3', () =>
116-
testAutoCommitTransactionConfigWhenBoltV3NotSupported(
117-
TX_CONFIG_WITH_METADATA
118-
))
119-
120-
it('should fail auto-commit transaction with timeout when database does not support Bolt V3', () =>
121-
testAutoCommitTransactionConfigWhenBoltV3NotSupported(
122-
TX_CONFIG_WITH_TIMEOUT
123-
))
124-
125-
it('should fail read transaction function with metadata when database does not support Bolt V3', () =>
126-
testTransactionFunctionConfigWhenBoltV3NotSupported(
127-
true,
128-
TX_CONFIG_WITH_METADATA
129-
))
130-
131-
it('should fail read transaction function with timeout when database does not support Bolt V3', () =>
132-
testTransactionFunctionConfigWhenBoltV3NotSupported(
133-
true,
134-
TX_CONFIG_WITH_TIMEOUT
135-
))
136-
137-
it('should fail write transaction function with metadata when database does not support Bolt V3', () =>
138-
testTransactionFunctionConfigWhenBoltV3NotSupported(
139-
false,
140-
TX_CONFIG_WITH_METADATA
141-
))
142-
143-
it('should fail write transaction function with timeout when database does not support Bolt V3', () =>
144-
testTransactionFunctionConfigWhenBoltV3NotSupported(
145-
false,
146-
TX_CONFIG_WITH_TIMEOUT
147-
))
103+
}, 20000)
104+
105+
it(
106+
'should set transaction metadata with read transaction function',
107+
() => testTransactionMetadataWithTransactionFunctions(true),
108+
20000
109+
)
110+
111+
it(
112+
'should set transaction metadata with write transaction function',
113+
() => testTransactionMetadataWithTransactionFunctions(false),
114+
20000
115+
)
116+
117+
it(
118+
'should fail auto-commit transaction with metadata when database does not support Bolt V3',
119+
() =>
120+
testAutoCommitTransactionConfigWhenBoltV3NotSupported(
121+
TX_CONFIG_WITH_METADATA
122+
),
123+
20000
124+
)
125+
126+
it(
127+
'should fail auto-commit transaction with timeout when database does not support Bolt V3',
128+
() =>
129+
testAutoCommitTransactionConfigWhenBoltV3NotSupported(
130+
TX_CONFIG_WITH_TIMEOUT
131+
),
132+
20000
133+
)
134+
135+
it(
136+
'should fail read transaction function with metadata when database does not support Bolt V3',
137+
() =>
138+
testTransactionFunctionConfigWhenBoltV3NotSupported(
139+
true,
140+
TX_CONFIG_WITH_METADATA
141+
),
142+
20000
143+
)
144+
145+
it(
146+
'should fail read transaction function with timeout when database does not support Bolt V3',
147+
() =>
148+
testTransactionFunctionConfigWhenBoltV3NotSupported(
149+
true,
150+
TX_CONFIG_WITH_TIMEOUT
151+
),
152+
20000
153+
)
154+
155+
it(
156+
'should fail write transaction function with metadata when database does not support Bolt V3',
157+
() =>
158+
testTransactionFunctionConfigWhenBoltV3NotSupported(
159+
false,
160+
TX_CONFIG_WITH_METADATA
161+
),
162+
20000
163+
)
164+
165+
it(
166+
'should fail write transaction function with timeout when database does not support Bolt V3',
167+
() =>
168+
testTransactionFunctionConfigWhenBoltV3NotSupported(
169+
false,
170+
TX_CONFIG_WITH_TIMEOUT
171+
),
172+
20000
173+
)
148174

149175
it('should set transaction metadata for explicit transactions', async () => {
150176
if (!databaseSupportsBoltV3() || !databaseSupportsListTransaction()) {
@@ -165,7 +191,7 @@ describe('#integration Bolt V3 API', () => {
165191
expect(receivedMetadatas).toContain(metadata)
166192

167193
await tx.commit()
168-
})
194+
}, 20000)
169195

170196
it('should set transaction timeout for explicit transactions', async () => {
171197
if (!databaseSupportsBoltV3()) {
@@ -198,65 +224,89 @@ describe('#integration Bolt V3 API', () => {
198224

199225
await otherTx.rollback()
200226
await otherSession.close()
201-
})
202-
203-
it('should fail to run in explicit transaction with metadata when database does not support Bolt V3', () =>
204-
testRunInExplicitTransactionWithConfigWhenBoltV3NotSupported(
205-
TX_CONFIG_WITH_METADATA
206-
))
207-
208-
it('should fail to run in explicit transaction with timeout when database does not support Bolt V3', () =>
209-
testRunInExplicitTransactionWithConfigWhenBoltV3NotSupported(
210-
TX_CONFIG_WITH_TIMEOUT
211-
))
212-
213-
it('should fail to commit explicit transaction with metadata when database does not support Bolt V3', () =>
214-
testCloseExplicitTransactionWithConfigWhenBoltV3NotSupported(
215-
true,
216-
TX_CONFIG_WITH_METADATA
217-
))
218-
219-
it('should fail to commit explicit transaction with timeout when database does not support Bolt V3', () =>
220-
testCloseExplicitTransactionWithConfigWhenBoltV3NotSupported(
221-
true,
222-
TX_CONFIG_WITH_TIMEOUT
223-
))
224-
225-
it('should fail to rollback explicit transaction with metadata when database does not support Bolt V3', () =>
226-
testCloseExplicitTransactionWithConfigWhenBoltV3NotSupported(
227-
false,
228-
TX_CONFIG_WITH_METADATA
229-
))
230-
231-
it('should fail to rollback explicit transaction with timeout when database does not support Bolt V3', () =>
232-
testCloseExplicitTransactionWithConfigWhenBoltV3NotSupported(
233-
false,
234-
TX_CONFIG_WITH_TIMEOUT
235-
))
227+
}, 20000)
228+
229+
it(
230+
'should fail to run in explicit transaction with metadata when database does not support Bolt V3',
231+
() =>
232+
testRunInExplicitTransactionWithConfigWhenBoltV3NotSupported(
233+
TX_CONFIG_WITH_METADATA
234+
),
235+
20000
236+
)
237+
238+
it(
239+
'should fail to run in explicit transaction with timeout when database does not support Bolt V3',
240+
() =>
241+
testRunInExplicitTransactionWithConfigWhenBoltV3NotSupported(
242+
TX_CONFIG_WITH_TIMEOUT
243+
),
244+
20000
245+
)
246+
247+
it(
248+
'should fail to commit explicit transaction with metadata when database does not support Bolt V3',
249+
() =>
250+
testCloseExplicitTransactionWithConfigWhenBoltV3NotSupported(
251+
true,
252+
TX_CONFIG_WITH_METADATA
253+
),
254+
20000
255+
)
256+
257+
it(
258+
'should fail to commit explicit transaction with timeout when database does not support Bolt V3',
259+
() =>
260+
testCloseExplicitTransactionWithConfigWhenBoltV3NotSupported(
261+
true,
262+
TX_CONFIG_WITH_TIMEOUT
263+
),
264+
20000
265+
)
266+
267+
it(
268+
'should fail to rollback explicit transaction with metadata when database does not support Bolt V3',
269+
() =>
270+
testCloseExplicitTransactionWithConfigWhenBoltV3NotSupported(
271+
false,
272+
TX_CONFIG_WITH_METADATA
273+
),
274+
20000
275+
)
276+
277+
it(
278+
'should fail to rollback explicit transaction with timeout when database does not support Bolt V3',
279+
() =>
280+
testCloseExplicitTransactionWithConfigWhenBoltV3NotSupported(
281+
false,
282+
TX_CONFIG_WITH_TIMEOUT
283+
),
284+
20000
285+
)
236286

237287
it('should fail to run auto-commit transaction with invalid timeout', () => {
238288
INVALID_TIMEOUT_VALUES.forEach(invalidValue =>
239289
expect(() =>
240290
session.run('RETURN $x', { x: 42 }, { timeout: invalidValue })
241291
).toThrow()
242292
)
243-
})
293+
}, 20000)
244294

245295
it('should fail to run auto-commit transaction with invalid metadata', () => {
246296
INVALID_METADATA_VALUES.forEach(invalidValue =>
247297
expect(() =>
248298
session.run('RETURN $x', { x: 42 }, { metadata: invalidValue })
249299
).toThrow()
250300
)
251-
})
301+
}, 20000)
252302

253303
it('should fail to begin explicit transaction with invalid timeout', () => {
254304
INVALID_TIMEOUT_VALUES.forEach(invalidValue =>
255305
expect(() =>
256306
session.beginTransaction({ timeout: invalidValue })
257307
).toThrow()
258308
)
259-
})
309+
}, 20000)
260310

261311
it('should fail to begin explicit transaction with invalid metadata', () => {
262312
INVALID_METADATA_VALUES.forEach(invalidValue =>
@@ -274,7 +324,7 @@ describe('#integration Bolt V3 API', () => {
274324
})
275325
).toThrow()
276326
)
277-
})
327+
}, 20000)
278328

279329
it('should fail to run read transaction function with invalid metadata', () => {
280330
INVALID_METADATA_VALUES.forEach(invalidValue =>
@@ -294,7 +344,7 @@ describe('#integration Bolt V3 API', () => {
294344
})
295345
).toThrow()
296346
)
297-
})
347+
}, 20000)
298348

299349
it('should fail to run write transaction function with invalid metadata', () => {
300350
INVALID_METADATA_VALUES.forEach(invalidValue =>
@@ -304,7 +354,7 @@ describe('#integration Bolt V3 API', () => {
304354
})
305355
).toThrow()
306356
)
307-
})
357+
}, 20000)
308358

309359
it('should use bookmarks for auto commit transactions', async () => {
310360
if (!databaseSupportsBoltV3()) {
@@ -333,7 +383,7 @@ describe('#integration Bolt V3 API', () => {
333383
expect(bookmark3).not.toEqual(initialBookmark)
334384
expect(bookmark3).not.toEqual(bookmark1)
335385
expect(bookmark3).not.toEqual(bookmark2)
336-
})
386+
}, 20000)
337387

338388
it('should use bookmarks for auto commit and explicit transactions', async () => {
339389
if (!databaseSupportsBoltV3()) {
@@ -366,7 +416,7 @@ describe('#integration Bolt V3 API', () => {
366416
expect(bookmark3).not.toEqual(initialBookmark)
367417
expect(bookmark3).not.toEqual(bookmark1)
368418
expect(bookmark3).not.toEqual(bookmark2)
369-
})
419+
}, 20000)
370420

371421
it('should use bookmarks for auto commit transactions and transaction functions', async () => {
372422
if (!databaseSupportsBoltV3()) {
@@ -395,7 +445,7 @@ describe('#integration Bolt V3 API', () => {
395445
expect(bookmark3).not.toEqual(initialBookmark)
396446
expect(bookmark3).not.toEqual(bookmark1)
397447
expect(bookmark3).not.toEqual(bookmark2)
398-
})
448+
}, 20000)
399449

400450
async function testTransactionMetadataWithTransactionFunctions (read) {
401451
if (!databaseSupportsBoltV3() || !databaseSupportsListTransaction()) {

0 commit comments

Comments
 (0)