Skip to content

Commit

Permalink
Attempt to make throttler test case less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
lramos15 committed Oct 2, 2024
1 parent d085816 commit 2493dc2
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/vs/base/test/common/async.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1527,29 +1527,24 @@ suite('Async', () => {
const worker = store.add(new async.ThrottledWorker<number>({
maxWorkChunkSize: 5,
maxBufferedWork: undefined,
throttleDelay: 20, // 100ms delay
throttleDelay: 5,
waitThrottleDelayBetweenWorkUnits: true
}, handler));

let worked = worker.work([1, 2, 3]);
assert.strictEqual(worked, true);
assertArrayEquals(handled, [1, 2, 3]);

// Add more work immediately, should not be processed due to throttle delay
await async.timeout(2);

// Add more work immediately, should not be processed due to the `waitThrottleDelayBetweenWorkUnits`. We only waited 2 of the 5ms.
worked = worker.work([4, 5, 6]);
assert.strictEqual(worked, true);
assertArrayEquals(handled, [1, 2, 3]);

// Wait for throttle delay to pass
await new Promise(resolve => setTimeout(resolve, 150));

// Verify that the second batch of work has been processed
// Wait an additional 5 ms and check that the work has now been processed
await async.timeout(5);
assertArrayEquals(handled, [1, 2, 3, 4, 5, 6]);

// Add more work after throttle delay
worked = worker.work([7, 8, 9]);
assert.strictEqual(worked, true);
assertArrayEquals(handled, [1, 2, 3, 4, 5, 6, 7, 8, 9]);
});
});

Expand Down

0 comments on commit 2493dc2

Please sign in to comment.