Skip to content

Commit 09e3b59

Browse files
committed
removed next tick scheduling as we dont use it and its test was too flaky
1 parent 7bd057e commit 09e3b59

File tree

2 files changed

+2
-51
lines changed

2 files changed

+2
-51
lines changed

x-pack/plugins/task_manager/server/lib/bulk_operation_buffer.test.ts

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -54,48 +54,6 @@ describe('Bulk Operation Buffer', () => {
5454
expect(bulkUpdate).toHaveBeenCalledWith([task1, task2]);
5555
});
5656

57-
test('batch updates are executed at most by the next Event Loop tick by default', async () => {
58-
const bulkUpdate: jest.Mocked<BulkOperation<TaskInstance, Error>> = jest.fn((tasks) => {
59-
return Promise.resolve(tasks.map(incrementAttempts));
60-
});
61-
62-
const bufferedUpdate = createBuffer(bulkUpdate);
63-
64-
const task1 = createTask();
65-
const task2 = createTask();
66-
const task3 = createTask();
67-
const task4 = createTask();
68-
const task5 = createTask();
69-
const task6 = createTask();
70-
71-
return new Promise((resolve) => {
72-
Promise.all([bufferedUpdate(task1), bufferedUpdate(task2)]).then((_) => {
73-
expect(bulkUpdate).toHaveBeenCalledTimes(1);
74-
expect(bulkUpdate).toHaveBeenCalledWith([task1, task2]);
75-
expect(bulkUpdate).not.toHaveBeenCalledWith([task3, task4]);
76-
});
77-
78-
setTimeout(() => {
79-
// on next tick
80-
setTimeout(() => {
81-
// on next tick
82-
expect(bulkUpdate).toHaveBeenCalledTimes(2);
83-
Promise.all([bufferedUpdate(task5), bufferedUpdate(task6)]).then((_) => {
84-
expect(bulkUpdate).toHaveBeenCalledTimes(3);
85-
expect(bulkUpdate).toHaveBeenCalledWith([task5, task6]);
86-
resolve();
87-
});
88-
}, 0);
89-
90-
expect(bulkUpdate).toHaveBeenCalledTimes(1);
91-
Promise.all([bufferedUpdate(task3), bufferedUpdate(task4)]).then((_) => {
92-
expect(bulkUpdate).toHaveBeenCalledTimes(2);
93-
expect(bulkUpdate).toHaveBeenCalledWith([task3, task4]);
94-
});
95-
}, 0);
96-
});
97-
});
98-
9957
test('batch updates can be customised to execute after a certain period', async () => {
10058
const bulkUpdate: jest.Mocked<BulkOperation<TaskInstance, Error>> = jest.fn((tasks) => {
10159
return Promise.resolve(tasks.map(incrementAttempts));

x-pack/plugins/task_manager/server/lib/bulk_operation_buffer.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,8 @@ export function createBuffer<Input extends Entity, ErrorOutput, Output extends E
9393
// the race is started in response to the first operation into the buffer
9494
// so we flush once the remaining operations come in (which is `bufferMaxOperations - 1`)
9595
storeUpdateBuffer.pipe(bufferCount(bufferMaxOperations - 1)),
96-
bufferMaxDuration
97-
? // if theres a max duration, flush buffer based on that
98-
from(resolveIn(bufferMaxDuration))
99-
: // ensure we flush by the end of the "current" event loop tick
100-
from(resolveImmediate()),
96+
// flush buffer once max duration has passed
97+
from(resolveIn(bufferMaxDuration)),
10198
]).pipe(first(), mapTo(FLUSH))
10299
: from([DONT_FLUSH]);
103100
}),
@@ -118,10 +115,6 @@ export function createBuffer<Input extends Entity, ErrorOutput, Output extends E
118115
};
119116
}
120117

121-
function resolveImmediate() {
122-
return new Promise(setImmediate);
123-
}
124-
125118
function resolveIn(ms: number) {
126119
return new Promise((resolve) => {
127120
setTimeout(resolve, ms);

0 commit comments

Comments
 (0)