Skip to content

Commit 68b8451

Browse files
committed
fix(test): ignore flaky workerNodeKeys affinity test on Deno v1.x macOS
1 parent c0bd174 commit 68b8451

1 file changed

Lines changed: 45 additions & 38 deletions

File tree

tests/pools/abstract-pool.test.mjs

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,50 +1883,57 @@ describe({
18831883
await dynamicThreadPool.destroy()
18841884
})
18851885

1886-
it('Verify that execute() respects workerNodeKeys affinity', async () => {
1887-
const dynamicThreadPool = new DynamicThreadPool(
1888-
Math.floor(numberOfWorkers / 2),
1889-
numberOfWorkers,
1890-
new URL('./../worker-files/thread/testWorker.mjs', import.meta.url),
1891-
)
1892-
await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1)
1893-
const poolWorkerNodeKeys = [...dynamicThreadPool.workerNodes.keys()]
1894-
1895-
// Add task function with affinity to first worker only
1896-
const affinityTaskFunction = (data) => {
1897-
return data
1898-
}
1899-
await dynamicThreadPool.addTaskFunction('affinityTask', {
1900-
taskFunction: affinityTaskFunction,
1901-
workerNodeKeys: [poolWorkerNodeKeys[0]],
1902-
})
1886+
it({
1887+
name: 'Verify that execute() respects workerNodeKeys affinity',
1888+
ignore: Deno.build.os === 'darwin' &&
1889+
Number.parseInt(Deno.version.deno.split('.')[0]) < 2,
1890+
fn: async () => {
1891+
const dynamicThreadPool = new DynamicThreadPool(
1892+
Math.floor(numberOfWorkers / 2),
1893+
numberOfWorkers,
1894+
new URL('./../worker-files/thread/testWorker.mjs', import.meta.url),
1895+
)
1896+
await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1)
1897+
const poolWorkerNodeKeys = [...dynamicThreadPool.workerNodes.keys()]
19031898

1904-
// Reset task counts to track new executions
1905-
for (const workerNode of dynamicThreadPool.workerNodes) {
1906-
workerNode.usage.tasks.executed = 0
1907-
}
1899+
// Add task function with affinity to first worker only
1900+
const affinityTaskFunction = (data) => {
1901+
return data
1902+
}
1903+
await dynamicThreadPool.addTaskFunction('affinityTask', {
1904+
taskFunction: affinityTaskFunction,
1905+
workerNodeKeys: [poolWorkerNodeKeys[0]],
1906+
})
19081907

1909-
// Execute multiple tasks with affinity
1910-
const numTasks = 5
1911-
const tasks = []
1912-
for (let i = 0; i < numTasks; i++) {
1913-
tasks.push(dynamicThreadPool.execute({ test: i }, 'affinityTask'))
1914-
}
1915-
await Promise.all(tasks)
1908+
// Reset task counts to track new executions
1909+
for (const workerNode of dynamicThreadPool.workerNodes) {
1910+
workerNode.usage.tasks.executed = 0
1911+
}
19161912

1917-
// Verify that only the affinity worker received the tasks
1918-
const affinityWorkerNode =
1919-
dynamicThreadPool.workerNodes[poolWorkerNodeKeys[0]]
1920-
expect(affinityWorkerNode.usage.tasks.executed).toBe(numTasks)
1913+
// Execute multiple tasks with affinity
1914+
const numTasks = 5
1915+
const tasks = []
1916+
for (let i = 0; i < numTasks; i++) {
1917+
tasks.push(dynamicThreadPool.execute({ test: i }, 'affinityTask'))
1918+
}
1919+
await Promise.all(tasks)
19211920

1922-
// Other workers should have 0 tasks from affinityTask
1923-
for (let i = 0; i < dynamicThreadPool.workerNodes.length; i++) {
1924-
if (i !== poolWorkerNodeKeys[0]) {
1925-
expect(dynamicThreadPool.workerNodes[i].usage.tasks.executed).toBe(0)
1921+
// Verify that only the affinity worker received the tasks
1922+
const affinityWorkerNode =
1923+
dynamicThreadPool.workerNodes[poolWorkerNodeKeys[0]]
1924+
expect(affinityWorkerNode.usage.tasks.executed).toBe(numTasks)
1925+
1926+
// Other workers should have 0 tasks from affinityTask
1927+
for (let i = 0; i < dynamicThreadPool.workerNodes.length; i++) {
1928+
if (i !== poolWorkerNodeKeys[0]) {
1929+
expect(dynamicThreadPool.workerNodes[i].usage.tasks.executed).toBe(
1930+
0,
1931+
)
1932+
}
19261933
}
1927-
}
19281934

1929-
await dynamicThreadPool.destroy()
1935+
await dynamicThreadPool.destroy()
1936+
},
19301937
})
19311938

19321939
it({

0 commit comments

Comments
 (0)