Skip to content

Commit 430ea5c

Browse files
committed
test: safety sleep
1 parent c7a36d1 commit 430ea5c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ connectDatabaseEmulator(database, 'localhost', 8081)
5555
connectStorageEmulator(storage, 'localhost', 9199)
5656

5757
let _id = 0
58+
// wait this ms time after each operation to avoid race conditions
59+
const SLEEP_TIME = 30
5860

5961
// Storage
6062
export function setupStorageRefs() {
@@ -147,26 +149,30 @@ export function setupFirestoreRefs(id?: string) {
147149

148150
async function _addDoc(...args: Parameters<typeof addDoc>) {
149151
const d = await addDoc(...args)
152+
await sleep(SLEEP_TIME)
150153
await nextTick()
151154
return d
152155
}
153156

154157
const _setDoc: typeof setDoc = async (...args: any[]) => {
155158
// @ts-expect-error: not a tuple
156159
const d = await setDoc(...args)
160+
await sleep(SLEEP_TIME)
157161
await nextTick()
158162
return d
159163
}
160164

161165
async function _deleteDoc(...args: Parameters<typeof deleteDoc>) {
162166
const d = await deleteDoc(...args)
167+
await sleep(SLEEP_TIME)
163168
await nextTick()
164169
return d
165170
}
166171

167172
const _updateDoc: typeof updateDoc = async (...args: any[]) => {
168173
// @ts-expect-error: not a tuple
169174
const d = await updateDoc(...args)
175+
await sleep(SLEEP_TIME)
170176
await nextTick()
171177
return d
172178
}
@@ -238,18 +244,21 @@ export function setupDatabaseRefs() {
238244

239245
const _set: typeof databaseSet = async (ref, options) => {
240246
const d = await databaseSet(ref, options)
247+
sleep(SLEEP_TIME)
241248
await nextTick()
242249
return d
243250
}
244251

245252
const _update: typeof databaseUpdate = async (ref, options) => {
246253
const d = await databaseUpdate(ref, options)
254+
sleep(SLEEP_TIME)
247255
await nextTick()
248256
return d
249257
}
250258

251259
const _remove: typeof databaseRemove = async (ref) => {
252260
const d = await databaseRemove(ref)
261+
sleep(SLEEP_TIME)
253262
await nextTick()
254263
return d
255264
}
@@ -258,6 +267,7 @@ export function setupDatabaseRefs() {
258267
const _push: typeof databasePush = async (...args: any[]) => {
259268
// @ts-expect-error: not a tuple
260269
const d = await databasePush(...args)
270+
sleep(SLEEP_TIME)
261271
await nextTick()
262272
return d
263273
}

0 commit comments

Comments
 (0)