mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Merge from vscode 4c9161a3f125f5a788aafa73a4ecfcb27dcfc319 (#9143)
* Merge from vscode 4c9161a3f125f5a788aafa73a4ecfcb27dcfc319 * minor spacing fix
This commit is contained in:
@@ -557,4 +557,93 @@ suite('Async', () => {
|
||||
assert.equal(error, error);
|
||||
}
|
||||
});
|
||||
|
||||
test('TaskSequentializer - pending basics', async function () {
|
||||
const sequentializer = new async.TaskSequentializer();
|
||||
|
||||
assert.ok(!sequentializer.hasPending());
|
||||
assert.ok(!sequentializer.hasPending(2323));
|
||||
assert.ok(!sequentializer.pending);
|
||||
|
||||
// pending removes itself after done
|
||||
await sequentializer.setPending(1, Promise.resolve());
|
||||
assert.ok(!sequentializer.hasPending());
|
||||
assert.ok(!sequentializer.hasPending(1));
|
||||
assert.ok(!sequentializer.pending);
|
||||
|
||||
// pending removes itself after done (use async.timeout)
|
||||
sequentializer.setPending(2, async.timeout(1));
|
||||
assert.ok(sequentializer.hasPending());
|
||||
assert.ok(sequentializer.hasPending(2));
|
||||
assert.ok(!sequentializer.hasPending(1));
|
||||
assert.ok(sequentializer.pending);
|
||||
|
||||
await async.timeout(2);
|
||||
assert.ok(!sequentializer.hasPending());
|
||||
assert.ok(!sequentializer.hasPending(2));
|
||||
assert.ok(!sequentializer.pending);
|
||||
});
|
||||
|
||||
test('TaskSequentializer - pending and next (finishes instantly)', async function () {
|
||||
const sequentializer = new async.TaskSequentializer();
|
||||
|
||||
let pendingDone = false;
|
||||
sequentializer.setPending(1, async.timeout(1).then(() => { pendingDone = true; return; }));
|
||||
|
||||
// next finishes instantly
|
||||
let nextDone = false;
|
||||
const res = sequentializer.setNext(() => Promise.resolve(null).then(() => { nextDone = true; return; }));
|
||||
|
||||
await res;
|
||||
assert.ok(pendingDone);
|
||||
assert.ok(nextDone);
|
||||
});
|
||||
|
||||
test('TaskSequentializer - pending and next (finishes after timeout)', async function () {
|
||||
const sequentializer = new async.TaskSequentializer();
|
||||
|
||||
let pendingDone = false;
|
||||
sequentializer.setPending(1, async.timeout(1).then(() => { pendingDone = true; return; }));
|
||||
|
||||
// next finishes after async.timeout
|
||||
let nextDone = false;
|
||||
const res = sequentializer.setNext(() => async.timeout(1).then(() => { nextDone = true; return; }));
|
||||
|
||||
await res;
|
||||
assert.ok(pendingDone);
|
||||
assert.ok(nextDone);
|
||||
});
|
||||
|
||||
test('TaskSequentializer - pending and multiple next (last one wins)', async function () {
|
||||
const sequentializer = new async.TaskSequentializer();
|
||||
|
||||
let pendingDone = false;
|
||||
sequentializer.setPending(1, async.timeout(1).then(() => { pendingDone = true; return; }));
|
||||
|
||||
// next finishes after async.timeout
|
||||
let firstDone = false;
|
||||
let firstRes = sequentializer.setNext(() => async.timeout(2).then(() => { firstDone = true; return; }));
|
||||
|
||||
let secondDone = false;
|
||||
let secondRes = sequentializer.setNext(() => async.timeout(3).then(() => { secondDone = true; return; }));
|
||||
|
||||
let thirdDone = false;
|
||||
let thirdRes = sequentializer.setNext(() => async.timeout(4).then(() => { thirdDone = true; return; }));
|
||||
|
||||
await Promise.all([firstRes, secondRes, thirdRes]);
|
||||
assert.ok(pendingDone);
|
||||
assert.ok(!firstDone);
|
||||
assert.ok(!secondDone);
|
||||
assert.ok(thirdDone);
|
||||
});
|
||||
|
||||
test('TaskSequentializer - cancel pending', async function () {
|
||||
const sequentializer = new async.TaskSequentializer();
|
||||
|
||||
let pendingCancelled = false;
|
||||
sequentializer.setPending(1, async.timeout(1), () => pendingCancelled = true);
|
||||
sequentializer.cancelPending();
|
||||
|
||||
assert.ok(pendingCancelled);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user