Skip to content

Commit 0e1edf7

Browse files
committed
chore: wip
1 parent 22682e9 commit 0e1edf7

53 files changed

Lines changed: 14757 additions & 14555 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

test/bulk.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Job } from '../src/classes'
22
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'bun:test'
33
import process from 'node:process'
4-
import { default as IORedis } from 'ioredis'
4+
import IORedis from 'ioredis'
55
import { v4 } from 'uuid'
66
import { Queue, QueueEvents, Worker } from '../src/classes'
77
import { delay, removeAllQueueData } from '../src/utils'
@@ -13,7 +13,7 @@ describe('bulk jobs', () => {
1313
let queue: Queue
1414
let queueName: string
1515

16-
let connection
16+
let connection: IORedis
1717
beforeAll(async () => {
1818
connection = new IORedis(redisHost, { maxRetriesPerRequest: null })
1919
})
@@ -28,7 +28,7 @@ describe('bulk jobs', () => {
2828
await removeAllQueueData(new IORedis(redisHost), queueName)
2929
})
3030

31-
after(async () => {
31+
afterAll(async () => {
3232
await connection.quit()
3333
})
3434

@@ -55,11 +55,11 @@ describe('bulk jobs', () => {
5555
{ name, data: { idx: 0, foo: 'bar' } },
5656
{ name, data: { idx: 1, foo: 'baz' } },
5757
])
58-
expect(jobs).to.have.length(2)
58+
expect(jobs).toHaveLength(2)
5959

60-
expect(jobs[0].id).to.be.ok
60+
expect(jobs[0].id).toBeTruthy()
6161
expect(jobs[0].data.foo).toBe('bar')
62-
expect(jobs[1].id).to.be.ok
62+
expect(jobs[1].id).toBeTruthy()
6363
expect(jobs[1].data.foo).toBe('baz')
6464

6565
await processing
@@ -102,11 +102,11 @@ describe('bulk jobs', () => {
102102
},
103103
},
104104
])
105-
expect(jobs).to.have.length(2)
105+
expect(jobs).toHaveLength(2)
106106

107-
expect(jobs[0].id).to.be.ok
107+
expect(jobs[0].id).toBeTruthy()
108108
expect(jobs[0].data.foo).toBe('bar')
109-
expect(jobs[1].id).to.be.ok
109+
expect(jobs[1].id).toBeTruthy()
110110
expect(jobs[1].data.foo).toBe('baz')
111111

112112
const { unprocessed } = await parent.getDependenciesCount({
@@ -164,7 +164,7 @@ describe('bulk jobs', () => {
164164
await worker.close()
165165
await worker2.close()
166166
await queueEvents.close()
167-
}).timeout(10_000)
167+
}, 10_000)
168168

169169
it('should process jobs with custom ids', async () => {
170170
const name = 'test'
@@ -189,7 +189,7 @@ describe('bulk jobs', () => {
189189
{ name, data: { idx: 0, foo: 'bar' }, opts: { jobId: 'test1' } },
190190
{ name, data: { idx: 1, foo: 'baz' }, opts: { jobId: 'test2' } },
191191
])
192-
expect(jobs).to.have.length(2)
192+
expect(jobs).toHaveLength(2)
193193

194194
expect(jobs[0].id).toBe('test1')
195195
expect(jobs[0].data.foo).toBe('bar')

test/child-pool.test.ts

Lines changed: 81 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,118 @@
1-
import { expect } from 'chai';
2-
import { ChildPool } from '../src/classes';
3-
import { join } from 'path';
1+
import { afterEach, beforeEach, describe, expect, it } from 'bun:test'
2+
import { join } from 'node:path'
3+
import { ChildPool } from '../src/classes'
44

5-
const NoopProc = () => {};
6-
describe('Child pool for Child Processes', () => {
7-
sandboxProcessTests();
8-
});
5+
describe('child pool for Child Processes', () => {
6+
sandboxProcessTests()
7+
})
98

10-
describe('Child pool for Worker Threads', () => {
9+
describe('child pool for Worker Threads', () => {
1110
sandboxProcessTests({
1211
mainFile: join(process.cwd(), 'dist/cjs/classes/main-worker.js'),
1312
useWorkerThreads: true,
14-
});
15-
});
13+
})
14+
})
1615

1716
function sandboxProcessTests(
1817
{
1918
mainFile,
2019
useWorkerThreads,
21-
}: { mainFile?: string; useWorkerThreads?: boolean } = {
20+
}: { mainFile?: string, useWorkerThreads?: boolean } = {
2221
useWorkerThreads: false,
2322
},
2423
) {
25-
describe('Child pool', () => {
26-
let pool: ChildPool;
24+
describe('child pool', () => {
25+
let pool: ChildPool
2726

2827
beforeEach(() => {
29-
pool = new ChildPool({ mainFile, useWorkerThreads });
30-
});
28+
pool = new ChildPool({ mainFile, useWorkerThreads })
29+
})
3130

32-
afterEach(() => pool.clean());
31+
afterEach(() => pool.clean())
3332

3433
it('should return same child if free', async () => {
35-
const processor = __dirname + '/fixtures/fixture_processor_bar.js';
36-
const child = await pool.retain(processor, NoopProc);
37-
expect(child).to.be.ok;
38-
pool.release(child);
39-
expect(pool.retained).to.be.empty;
40-
const newChild = await pool.retain(processor, NoopProc);
41-
expect(child).toBe(newChild);
42-
});
34+
const processor = join(__dirname, 'fixtures/fixture_processor_bar.js')
35+
const child = await pool.retain(processor)
36+
expect(child).toBeTruthy()
37+
pool.release(child)
38+
expect(pool.retained).toEqual({})
39+
const newChild = await pool.retain(processor)
40+
expect(child).toBe(newChild)
41+
})
4342

4443
it('should return a new child if reused the last free one', async () => {
45-
const processor = __dirname + '/fixtures/fixture_processor_bar.js';
46-
let child = await pool.retain(processor, NoopProc);
47-
expect(child).to.be.ok;
48-
pool.release(child);
49-
expect(pool.retained).to.be.empty;
50-
let newChild = await pool.retain(processor, NoopProc);
51-
expect(child).toBe(newChild);
52-
child = newChild;
53-
newChild = await pool.retain(processor, NoopProc);
54-
expect(child).not.toBe(newChild);
55-
});
44+
const processor = join(__dirname, 'fixtures/fixture_processor_bar.js')
45+
let child = await pool.retain(processor)
46+
expect(child).toBeTruthy()
47+
pool.release(child)
48+
expect(pool.retained).toEqual({})
49+
let newChild = await pool.retain(processor)
50+
expect(child).toBe(newChild)
51+
child = newChild
52+
newChild = await pool.retain(processor)
53+
expect(child).not.toBe(newChild)
54+
})
5655

5756
it('should return a new child if none free', async () => {
58-
const processor = __dirname + '/fixtures/fixture_processor_bar.js';
59-
const child = await pool.retain(processor, NoopProc);
60-
expect(child).to.be.ok;
61-
expect(pool.retained).not.to.be.empty;
62-
const newChild = await pool.retain(processor, NoopProc);
63-
expect(child).to.not.be.eql(newChild);
64-
});
57+
const processor = join(__dirname, 'fixtures/fixture_processor_bar.js')
58+
const child = await pool.retain(processor)
59+
expect(child).toBeTruthy()
60+
expect(pool.retained).not.toEqual({})
61+
const newChild = await pool.retain(processor)
62+
expect(child).not.toEqual(newChild)
63+
})
6564

6665
it('should return a new child if killed', async () => {
67-
const processor = __dirname + '/fixtures/fixture_processor_bar.js';
68-
const child = await pool.retain(processor, NoopProc);
69-
expect(child).to.be.ok;
70-
await pool.kill(child);
71-
expect(pool.retained).to.be.empty;
72-
const newChild = await pool.retain(processor, NoopProc);
73-
expect(child).to.not.be.eql(newChild);
74-
});
66+
const processor = join(__dirname, 'fixtures/fixture_processor_bar.js')
67+
const child = await pool.retain(processor)
68+
expect(child).toBeTruthy()
69+
await pool.kill(child)
70+
expect(pool.retained).toEqual({})
71+
const newChild = await pool.retain(processor)
72+
expect(child).not.toEqual(newChild)
73+
})
7574

7675
it('should return a new child if many retained and none free', async () => {
77-
const processor = __dirname + '/fixtures/fixture_processor_bar.js';
76+
const processor = join(__dirname, 'fixtures/fixture_processor_bar.js')
7877
const children = await Promise.all([
79-
pool.retain(processor, NoopProc),
80-
pool.retain(processor, NoopProc),
81-
pool.retain(processor, NoopProc),
82-
pool.retain(processor, NoopProc),
83-
pool.retain(processor, NoopProc),
84-
pool.retain(processor, NoopProc),
85-
]);
86-
expect(children).to.have.length(6);
87-
const child = await pool.retain(processor, NoopProc);
88-
expect(children).not.to.include(child);
89-
}).timeout(10000);
78+
pool.retain(processor),
79+
pool.retain(processor),
80+
pool.retain(processor),
81+
pool.retain(processor),
82+
pool.retain(processor),
83+
pool.retain(processor),
84+
])
85+
expect(children).toHaveLength(6)
86+
const child = await pool.retain(processor)
87+
expect(children).not.toContain(child)
88+
}, 10000)
9089

9190
it('should return an old child if many retained and one free', async () => {
92-
const processor = __dirname + '/fixtures/fixture_processor_bar.js';
91+
const processor = join(__dirname, 'fixtures/fixture_processor_bar.js')
9392
const children = await Promise.all([
94-
pool.retain(processor, NoopProc),
95-
pool.retain(processor, NoopProc),
96-
pool.retain(processor, NoopProc),
97-
pool.retain(processor, NoopProc),
98-
pool.retain(processor, NoopProc),
99-
pool.retain(processor, NoopProc),
100-
]);
93+
pool.retain(processor),
94+
pool.retain(processor),
95+
pool.retain(processor),
96+
pool.retain(processor),
97+
pool.retain(processor),
98+
pool.retain(processor),
99+
])
101100

102-
expect(children).to.have.length(6);
103-
pool.release(children[0]);
104-
const child = await pool.retain(processor);
105-
expect(children).to.include(child);
106-
}).timeout(10000);
101+
expect(children).toHaveLength(6)
102+
pool.release(children[0])
103+
const child = await pool.retain(processor)
104+
expect(children).toContain(child)
105+
}, 10000)
107106

108107
it('should consume execArgv array from process', async () => {
109-
const processor = __dirname + '/fixtures/fixture_processor_bar.js';
110-
process.execArgv.push('--no-warnings');
108+
const processor = join(__dirname, 'fixtures/fixture_processor_bar.js')
109+
process.execArgv.push('--no-warnings')
111110

112-
const child = await pool.retain(processor, NoopProc);
113-
expect(child).to.be.ok;
111+
const child = await pool.retain(processor)
112+
expect(child).toBeTruthy()
114113
if (!useWorkerThreads) {
115-
expect(child.childProcess.spawnargs).to.include('--no-warnings');
114+
expect(child.childProcess.spawnargs).toContain('--no-warnings')
116115
}
117-
});
118-
});
116+
})
117+
})
119118
}

0 commit comments

Comments
 (0)