-
Notifications
You must be signed in to change notification settings - Fork 357
Expand file tree
/
Copy pathaction-queue.test.ts
More file actions
54 lines (49 loc) · 1.78 KB
/
Copy pathaction-queue.test.ts
File metadata and controls
54 lines (49 loc) · 1.78 KB
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
import createResolvable from '@josephg/resolvable'
import { setupBackgroundIntegrationTest } from '../tests/background-integration-tests'
import ActionQueue from '../../external/@worldbrain/memex-common/ts/action-queue'
async function setupTest() {
const { backgroundModules } = await setupBackgroundIntegrationTest()
const { actionQueue } = backgroundModules.personalCloud
return {
actionQueue: actionQueue as ActionQueue<any>,
}
}
describe('Action queue', () => {
it('should be able to skip the queue', async () => {
const { actionQueue } = await setupTest()
let executed = false
actionQueue.options.executeAction = async () => {
executed = true
}
actionQueue.storage.queueAction = async () => {
throw new Error(`Action should not be queued`)
}
await actionQueue.scheduleAction(
{ type: 'test' },
{ queueInteraction: 'skip-queue' },
)
})
it('should be able to schedule a skipping action while another skipping action is being executed', async () => {
const { actionQueue } = await setupTest()
let executing = createResolvable()
const resolvable = createResolvable()
actionQueue.options.executeAction = async () => {
executing.resolve()
await resolvable
}
const first = actionQueue.scheduleAction(
{ type: 'test' },
{ queueInteraction: 'skip-queue' },
)
await executing
executing = createResolvable()
const second = actionQueue.scheduleAction(
{ type: 'test' },
{ queueInteraction: 'skip-queue' },
)
await executing
resolvable.resolve()
await first
await second
})
})