Skip to content

Commit

Permalink
waitThrottleDelayBetweenWorkUnits is flaky, commenting out (microsoft…
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli authored Oct 4, 2024
1 parent de44f0c commit 2fb92a5
Showing 1 changed file with 37 additions and 36 deletions.
73 changes: 37 additions & 36 deletions src/vs/base/test/common/async.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1520,42 +1520,43 @@ suite('Async', () => {
assert.strictEqual(worked, false);
});

test('waitThrottleDelayBetweenWorkUnits option', async () => {
const handled: number[] = [];
let handledCallback: Function;
let handledPromise = new Promise(resolve => handledCallback = resolve);
let currentTime = 0;

const handler = (units: readonly number[]) => {
handled.push(...units);
handledCallback();
handledPromise = new Promise(resolve => handledCallback = resolve);
};

const worker = store.add(new async.ThrottledWorker<number>({
maxWorkChunkSize: 5,
maxBufferedWork: undefined,
throttleDelay: 5,
waitThrottleDelayBetweenWorkUnits: true
}, handler));

// Schedule work, it should execute immediately
currentTime = Date.now();
let worked = worker.work([1, 2, 3]);
assert.strictEqual(worked, true);
assertArrayEquals(handled, [1, 2, 3]);
assert.strictEqual(Date.now() - currentTime < 5, true);

// Schedule work again, it should wait at least throttle delay before executing
currentTime = Date.now();
worked = worker.work([4, 5]);
assert.strictEqual(worked, true);
// Throttle delay hasn't reset so we still must wait
assertArrayEquals(handled, [1, 2, 3]);
await handledPromise;
assert.strictEqual(Date.now() - currentTime >= 5, true);
assertArrayEquals(handled, [1, 2, 3, 4, 5]);
});
// https://github.com/microsoft/vscode/issues/230366
// test('waitThrottleDelayBetweenWorkUnits option', async () => {
// const handled: number[] = [];
// let handledCallback: Function;
// let handledPromise = new Promise(resolve => handledCallback = resolve);
// let currentTime = 0;

// const handler = (units: readonly number[]) => {
// handled.push(...units);
// handledCallback();
// handledPromise = new Promise(resolve => handledCallback = resolve);
// };

// const worker = store.add(new async.ThrottledWorker<number>({
// maxWorkChunkSize: 5,
// maxBufferedWork: undefined,
// throttleDelay: 5,
// waitThrottleDelayBetweenWorkUnits: true
// }, handler));

// // Schedule work, it should execute immediately
// currentTime = Date.now();
// let worked = worker.work([1, 2, 3]);
// assert.strictEqual(worked, true);
// assertArrayEquals(handled, [1, 2, 3]);
// assert.strictEqual(Date.now() - currentTime < 5, true);

// // Schedule work again, it should wait at least throttle delay before executing
// currentTime = Date.now();
// worked = worker.work([4, 5]);
// assert.strictEqual(worked, true);
// // Throttle delay hasn't reset so we still must wait
// assertArrayEquals(handled, [1, 2, 3]);
// await handledPromise;
// assert.strictEqual(Date.now() - currentTime >= 5, true);
// assertArrayEquals(handled, [1, 2, 3, 4, 5]);
// });
});

suite('LimitedQueue', () => {
Expand Down

0 comments on commit 2fb92a5

Please sign in to comment.