Skip to content

Commit

Permalink
simplified buffer tests to reduce flakyness (#73024) (#73258)
Browse files Browse the repository at this point in the history
simplified buffer tests to reduce flakyness
  • Loading branch information
gmmorris authored Jul 27, 2020
1 parent 1688e59 commit d15da24
Showing 1 changed file with 32 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ function errorAttempts(task: TaskInstance): Err<OperationError<TaskInstance, Err
});
}

// FLAKY: https://github.com/elastic/kibana/issues/72864
describe.skip('Bulk Operation Buffer', () => {
describe('Bulk Operation Buffer', () => {
describe('createBuffer()', () => {
test('batches up multiple Operation calls', async () => {
const bulkUpdate: jest.Mocked<BulkOperation<TaskInstance, Error>> = jest.fn(
Expand Down Expand Up @@ -67,8 +66,6 @@ describe.skip('Bulk Operation Buffer', () => {
const task2 = createTask();
const task3 = createTask();
const task4 = createTask();
const task5 = createTask();
const task6 = createTask();

return new Promise((resolve) => {
Promise.all([bufferedUpdate(task1), bufferedUpdate(task2)]).then((_) => {
Expand All @@ -79,22 +76,18 @@ describe.skip('Bulk Operation Buffer', () => {

setTimeout(() => {
// on next tick
setTimeout(() => {
// on next tick
expect(bulkUpdate).toHaveBeenCalledTimes(2);
Promise.all([bufferedUpdate(task5), bufferedUpdate(task6)]).then((_) => {
expect(bulkUpdate).toHaveBeenCalledTimes(3);
expect(bulkUpdate).toHaveBeenCalledWith([task5, task6]);
resolve();
});
}, bufferMaxDuration + 1);

expect(bulkUpdate).toHaveBeenCalledTimes(1);
Promise.all([bufferedUpdate(task3), bufferedUpdate(task4)]).then((_) => {
expect(bulkUpdate).toHaveBeenCalledTimes(2);
expect(bulkUpdate).toHaveBeenCalledWith([task3, task4]);
});
}, bufferMaxDuration + 1);

setTimeout(() => {
// on next tick
expect(bulkUpdate).toHaveBeenCalledTimes(2);
resolve();
}, bufferMaxDuration * 1.1);
}, bufferMaxDuration * 1.1);
});
});

Expand All @@ -103,8 +96,9 @@ describe.skip('Bulk Operation Buffer', () => {
return Promise.resolve(tasks.map(incrementAttempts));
});

const bufferMaxDuration = 1000;
const bufferedUpdate = createBuffer(bulkUpdate, {
bufferMaxDuration: 100,
bufferMaxDuration,
bufferMaxOperations: 2,
});

Expand All @@ -114,26 +108,19 @@ describe.skip('Bulk Operation Buffer', () => {
const task4 = createTask();
const task5 = createTask();

return new Promise((resolve) => {
bufferedUpdate(task1);
bufferedUpdate(task2);
bufferedUpdate(task3);
bufferedUpdate(task4);

setTimeout(() => {
expect(bulkUpdate).toHaveBeenCalledTimes(2);
expect(bulkUpdate).toHaveBeenCalledWith([task1, task2]);
expect(bulkUpdate).toHaveBeenCalledWith([task3, task4]);

setTimeout(() => {
expect(bulkUpdate).toHaveBeenCalledTimes(2);
bufferedUpdate(task5).then((_) => {
expect(bulkUpdate).toHaveBeenCalledTimes(3);
expect(bulkUpdate).toHaveBeenCalledWith([task5]);
resolve();
});
}, 50);
}, 50);
return Promise.all([
bufferedUpdate(task1),
bufferedUpdate(task2),
bufferedUpdate(task3),
bufferedUpdate(task4),
]).then(() => {
expect(bulkUpdate).toHaveBeenCalledTimes(2);
expect(bulkUpdate).toHaveBeenCalledWith([task1, task2]);
expect(bulkUpdate).toHaveBeenCalledWith([task3, task4]);
return bufferedUpdate(task5).then((_) => {
expect(bulkUpdate).toHaveBeenCalledTimes(3);
expect(bulkUpdate).toHaveBeenCalledWith([task5]);
});
});
});

Expand All @@ -153,29 +140,26 @@ describe.skip('Bulk Operation Buffer', () => {
const task3 = createTask();
const task4 = createTask();

return new Promise((resolve) => {
bufferedUpdate(task1);
bufferedUpdate(task2);

setTimeout(() => {
expect(bulkUpdate).toHaveBeenCalledTimes(1);
expect(bulkUpdate).toHaveBeenCalledWith([task1, task2]);
return Promise.all([bufferedUpdate(task1), bufferedUpdate(task2)]).then(() => {
expect(bulkUpdate).toHaveBeenCalledTimes(1);
expect(bulkUpdate).toHaveBeenCalledWith([task1, task2]);

bufferedUpdate(task3);
bufferedUpdate(task4);
return new Promise((resolve) => {
const futureUpdates = Promise.all([bufferedUpdate(task3), bufferedUpdate(task4)]);

setTimeout(() => {
expect(bulkUpdate).toHaveBeenCalledTimes(1);

setTimeout(() => {
futureUpdates.then(() => {
expect(bulkUpdate).toHaveBeenCalledTimes(2);
expect(bulkUpdate).toHaveBeenCalledWith([task3, task4]);
resolve();
}, bufferMaxDuration / 2);
});
}, bufferMaxDuration / 2);
}, bufferMaxDuration + 1);
});
});
});

test('handles both resolutions and rejections at individual task level', async (done) => {
const bulkUpdate: jest.Mocked<BulkOperation<TaskInstance, Error>> = jest.fn(
([task1, task2, task3]) => {
Expand Down

0 comments on commit d15da24

Please sign in to comment.