Skip to content

Commit

Permalink
Fix flaky fileStore test (#4723)
Browse files Browse the repository at this point in the history
  • Loading branch information
danield9tqh authored Feb 13, 2024
1 parent df84a1c commit 5f3598c
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions ironfish/src/fileStores/fileStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ describe('FileStore', () => {
await files.init()
const store = new FileStore<{ foo: string }>(files, 'test', dir)

const [promise1, resolve1] = PromiseUtils.split<void>()
const [promise2, resolve2] = PromiseUtils.split<void>()
writeFileSpy.mockReturnValueOnce(promise1)
writeFileSpy.mockReturnValueOnce(promise2)
const [promiseFirstWrite, resolveFirstWrite] = PromiseUtils.split<void>()
writeFileSpy.mockReturnValueOnce(promiseFirstWrite)

const save1 = store.save({ foo: 'hello' })
const save2 = store.save({ foo: 'hello' })
Expand All @@ -58,19 +56,9 @@ describe('FileStore', () => {
await flushTimeout()
expect(writeFileSpy).toHaveBeenCalledTimes(1)

resolve1()
// Resolve the first promise, freeing the mutex and allowing save2 to
// execute
await flushTimeout()
await flushTimeout()
await flushTimeout()
await flushTimeout()
expect(writeFileSpy).toHaveBeenCalledTimes(2)

resolveFirstWrite()
await save1
resolve2()
await save2

expect(writeFileSpy).toHaveBeenCalledTimes(2)
})
})

0 comments on commit 5f3598c

Please sign in to comment.