@open-mercato/queue 0.8.1-develop.7297.1.67605e74f9 → 0.8.1-develop.7441.1.b42958b98c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/queue",
|
|
3
|
-
"version": "0.8.1-develop.
|
|
3
|
+
"version": "0.8.1-develop.7441.1.b42958b98c",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Multi-strategy job queue with local and BullMQ support",
|
|
6
6
|
"type": "module",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@open-mercato/shared": "0.8.1-develop.
|
|
60
|
-
"@open-mercato/telemetry": "0.8.1-develop.
|
|
59
|
+
"@open-mercato/shared": "0.8.1-develop.7441.1.b42958b98c",
|
|
60
|
+
"@open-mercato/telemetry": "0.8.1-develop.7441.1.b42958b98c"
|
|
61
61
|
},
|
|
62
62
|
"repository": {
|
|
63
63
|
"type": "git",
|
|
@@ -45,9 +45,9 @@ function createWatcherStub(): fs.FSWatcher {
|
|
|
45
45
|
return watcher as unknown as fs.FSWatcher
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
async function waitUntil(condition: () => boolean
|
|
48
|
+
async function waitUntil(condition: () => boolean | Promise<boolean>, timeoutMs = 5000): Promise<void> {
|
|
49
49
|
const deadline = Date.now() + timeoutMs
|
|
50
|
-
while (!condition()) {
|
|
50
|
+
while (!await condition()) {
|
|
51
51
|
if (Date.now() > deadline) throw new Error('[internal] Timed out waiting for the expected filesystem state')
|
|
52
52
|
await new Promise((resolve) => { setTimeout(resolve, 5) })
|
|
53
53
|
}
|
|
@@ -730,6 +730,14 @@ describe('Queue - local strategy', () => {
|
|
|
730
730
|
jest.useFakeTimers()
|
|
731
731
|
const baseDir = path.join(tmp, 'recreated-queue')
|
|
732
732
|
const movedDir = path.join(tmp, 'moved-queue')
|
|
733
|
+
const queueFile = path.join(baseDir, 'recreated-queue', 'queue.json')
|
|
734
|
+
const actualWatch = fs.watch
|
|
735
|
+
let watchedQueueInode: number | undefined
|
|
736
|
+
const watchSpy = jest.spyOn(fs, 'watch').mockImplementation((...args) => {
|
|
737
|
+
const watcher = actualWatch(...args)
|
|
738
|
+
watchedQueueInode = fs.statSync(queueFile).ino
|
|
739
|
+
return watcher
|
|
740
|
+
})
|
|
733
741
|
const consumer = createQueue<{ value: number }>('recreated-queue', 'local', { baseDir })
|
|
734
742
|
let resolveRecovered!: (value: number) => void
|
|
735
743
|
const recovered = new Promise<number>((resolve) => {
|
|
@@ -753,28 +761,29 @@ describe('Queue - local strategy', () => {
|
|
|
753
761
|
|
|
754
762
|
try {
|
|
755
763
|
await producer.enqueue({ value: 7 })
|
|
756
|
-
const recoveredWithinFallback = within(recovered, 5500)
|
|
757
764
|
await jest.advanceTimersByTimeAsync(5000)
|
|
758
|
-
|
|
759
|
-
|
|
765
|
+
jest.clearAllTimers()
|
|
760
766
|
jest.useRealTimers()
|
|
761
|
-
await within(
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
})(), 800)
|
|
767
|
+
await expect(within(recovered, 5000)).resolves.toBe(7)
|
|
768
|
+
await waitUntil(async () => {
|
|
769
|
+
const counts = await consumer.getJobCounts()
|
|
770
|
+
const queueStats = await fs.promises.stat(queueFile)
|
|
771
|
+
return counts.completed === 1 && counts.waiting === 0 && watchedQueueInode === queueStats.ino
|
|
772
|
+
})
|
|
768
773
|
await producer.enqueue({ value: 8 })
|
|
769
|
-
await expect(within(eventDriven,
|
|
774
|
+
await expect(within(eventDriven, 5000)).resolves.toBe(8)
|
|
770
775
|
} finally {
|
|
771
776
|
await producer.close()
|
|
772
777
|
}
|
|
773
778
|
} finally {
|
|
774
779
|
jest.useRealTimers()
|
|
775
|
-
|
|
780
|
+
try {
|
|
781
|
+
await consumer.close()
|
|
782
|
+
} finally {
|
|
783
|
+
watchSpy.mockRestore()
|
|
784
|
+
}
|
|
776
785
|
}
|
|
777
|
-
})
|
|
786
|
+
}, 20_000)
|
|
778
787
|
|
|
779
788
|
test('clear cancels queued-work polling after draining the queue', async () => {
|
|
780
789
|
jest.useFakeTimers()
|
|
@@ -949,11 +958,11 @@ describe('Queue - local strategy', () => {
|
|
|
949
958
|
const baseDir = path.join(tmp, 'active-batch')
|
|
950
959
|
const producer = createQueue<{ value: number }>('active-batch', 'local', {
|
|
951
960
|
baseDir,
|
|
952
|
-
pollInterval:
|
|
961
|
+
pollInterval: 10_000,
|
|
953
962
|
})
|
|
954
963
|
const consumer = createQueue<{ value: number }>('active-batch', 'local', {
|
|
955
964
|
baseDir,
|
|
956
|
-
pollInterval:
|
|
965
|
+
pollInterval: 10_000,
|
|
957
966
|
})
|
|
958
967
|
let resolveFirstStarted!: () => void
|
|
959
968
|
const firstStarted = new Promise<void>((resolve) => {
|
|
@@ -979,11 +988,11 @@ describe('Queue - local strategy', () => {
|
|
|
979
988
|
})
|
|
980
989
|
|
|
981
990
|
await producer.enqueue({ value: 1 })
|
|
982
|
-
await within(firstStarted,
|
|
991
|
+
await within(firstStarted, 5000)
|
|
983
992
|
await producer.enqueue({ value: 2 })
|
|
984
993
|
releaseFirst()
|
|
985
994
|
|
|
986
|
-
await expect(within(secondProcessed,
|
|
995
|
+
await expect(within(secondProcessed, 5000)).resolves.toBe(2)
|
|
987
996
|
} finally {
|
|
988
997
|
releaseFirst()
|
|
989
998
|
await consumer.close()
|