-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscheduler.test.ts
More file actions
58 lines (54 loc) · 1.68 KB
/
scheduler.test.ts
File metadata and controls
58 lines (54 loc) · 1.68 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
55
56
57
58
import test from 'ava';
import { createTable } from '../schema/table.js';
import { getRoundRobinTableClients } from './scheduler.js';
test('getRoundRobinTableClients', (t): void => {
const client = { id: () => 'client_0' };
const tables = [
createTable({
name: 'table1',
multiplexer: () => {
return Array.from({ length: 2 }).map((_, index) => ({
id: () => `client_${index}`,
}));
},
}),
createTable({
name: 'table2',
multiplexer: () => {
return Array.from({ length: 4 }).map((_, index) => ({
id: () => `client_${index}`,
}));
},
}),
createTable({
name: 'table3',
multiplexer: () => {
return Array.from({ length: 1 }).map((_, index) => ({
id: () => `client_${index}`,
}));
},
}),
createTable({
name: 'table4',
multiplexer: () => {
return [];
},
}),
];
const tableClients = getRoundRobinTableClients(tables, client);
t.is(tableClients.length, 7);
t.is(tableClients[0].table.name, 'table1');
t.is(tableClients[0].client.id(), 'client_0');
t.is(tableClients[1].table.name, 'table2');
t.is(tableClients[1].client.id(), 'client_0');
t.is(tableClients[2].table.name, 'table3');
t.is(tableClients[2].client.id(), 'client_0');
t.is(tableClients[3].table.name, 'table1');
t.is(tableClients[3].client.id(), 'client_1');
t.is(tableClients[4].table.name, 'table2');
t.is(tableClients[4].client.id(), 'client_1');
t.is(tableClients[5].table.name, 'table2');
t.is(tableClients[5].client.id(), 'client_2');
t.is(tableClients[6].table.name, 'table2');
t.is(tableClients[6].client.id(), 'client_3');
});