Skip to content

Commit b48674b

Browse files
authored
Merge pull request microsoft#4555 from iclanton/sleep-0
Update 1ms sleeps in tests to 0ms
2 parents f7fd624 + 2c6ef3f commit b48674b

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "",
5+
"type": "none",
6+
"packageName": "@rushstack/node-core-library"
7+
}
8+
],
9+
"packageName": "@rushstack/node-core-library",
10+
"email": "[email protected]"
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "",
5+
"type": "none",
6+
"packageName": "@rushstack/operation-graph"
7+
}
8+
],
9+
"packageName": "@rushstack/operation-graph",
10+
"email": "[email protected]"
11+
}

libraries/node-core-library/src/test/Async.test.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe(Async.name, () => {
4242

4343
const fn: (item: number) => Promise<string> = async (item) => {
4444
running++;
45-
await Async.sleep(1);
45+
await Async.sleep(0);
4646
maxRunning = Math.max(maxRunning, running);
4747
running--;
4848
return `result ${item}`;
@@ -137,7 +137,7 @@ describe(Async.name, () => {
137137

138138
const fn: (item: number) => Promise<void> = jest.fn(async (item) => {
139139
running++;
140-
await Async.sleep(1);
140+
await Async.sleep(0);
141141
maxRunning = Math.max(maxRunning, running);
142142
running--;
143143
});
@@ -155,7 +155,7 @@ describe(Async.name, () => {
155155

156156
const fn: (item: number) => Promise<void> = jest.fn(async (item) => {
157157
running++;
158-
await Async.sleep(1);
158+
await Async.sleep(0);
159159
maxRunning = Math.max(maxRunning, running);
160160
running--;
161161
});
@@ -171,14 +171,14 @@ describe(Async.name, () => {
171171
array.push(i);
172172
}
173173

174-
await Async.forEachAsync(array, async () => await Async.sleep(1), { concurrency: 3 });
174+
await Async.forEachAsync(array, async () => await Async.sleep(0), { concurrency: 3 });
175175
});
176176

177177
it('rejects if any operation rejects', async () => {
178178
const array: number[] = [1, 2, 3];
179179

180180
const fn: (item: number) => Promise<void> = jest.fn(async (item) => {
181-
await Async.sleep(1);
181+
await Async.sleep(0);
182182
if (item === 3) throw new Error('Something broke');
183183
});
184184

@@ -223,7 +223,7 @@ describe(Async.name, () => {
223223
};
224224

225225
await expect(() =>
226-
Async.forEachAsync(syncIterable, async (item) => await Async.sleep(1))
226+
Async.forEachAsync(syncIterable, async (item) => await Async.sleep(0))
227227
).rejects.toThrow(expectedError);
228228
});
229229

@@ -245,7 +245,7 @@ describe(Async.name, () => {
245245
};
246246

247247
await expect(() =>
248-
Async.forEachAsync(syncIterable, async (item) => await Async.sleep(1))
248+
Async.forEachAsync(syncIterable, async (item) => await Async.sleep(0))
249249
).rejects.toThrow(expectedError);
250250
});
251251

@@ -285,7 +285,7 @@ describe(Async.name, () => {
285285
);
286286

287287
// Wait for all the instant resolutions to be done
288-
await Async.sleep(1);
288+
await Async.sleep(0);
289289
expect(waitingIterators).toEqual(expectedConcurrency);
290290
resolve2({ done: true, value: undefined });
291291
await finalPromise;
@@ -309,7 +309,7 @@ describe(Async.name, () => {
309309
};
310310

311311
await expect(() =>
312-
Async.forEachAsync(syncIterable, async (item) => await Async.sleep(1))
312+
Async.forEachAsync(syncIterable, async (item) => await Async.sleep(0))
313313
).rejects.toThrow(expectedError);
314314
});
315315
});
@@ -516,7 +516,7 @@ describe(AsyncQueue.name, () => {
516516
queue,
517517
async ([item, callback]) => {
518518
// Add an async tick to ensure that the queue is actually running concurrently
519-
await Async.sleep(1);
519+
await Async.sleep(0);
520520
seenItems++;
521521
expect(expectedItems.has(item)).toBe(true);
522522
expectedItems.delete(item);
@@ -543,7 +543,7 @@ describe(AsyncQueue.name, () => {
543543
queue,
544544
async ([item, callback]) => {
545545
// Add an async tick to ensure that the queue is actually running concurrently
546-
await Async.sleep(1);
546+
await Async.sleep(0);
547547
seenItems++;
548548
if (item < 4) {
549549
expect(expectedItems.has(item)).toBe(true);
@@ -577,7 +577,7 @@ describe(AsyncQueue.name, () => {
577577
queue,
578578
async ([item, callback]) => {
579579
// Add an async tick to ensure that the queue is actually running concurrently
580-
await Async.sleep(1);
580+
await Async.sleep(0);
581581
seenItems++;
582582
if (item < 4) {
583583
expect(expectedItems.has(item)).toBe(true);

libraries/operation-graph/src/test/OperationExecutionManager.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ describe(OperationExecutionManager.name, () => {
287287
const run: ExecuteAsyncMock = jest.fn(
288288
async (context: IOperationRunnerContext): Promise<OperationStatus> => {
289289
++concurrency;
290-
await Async.sleep(1);
290+
await Async.sleep(0);
291291
if (concurrency > maxConcurrency) {
292292
maxConcurrency = concurrency;
293293
}

libraries/operation-graph/src/test/WorkQueue.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe(WorkQueue.name, () => {
128128

129129
const fn: () => Promise<OperationStatus> = jest.fn(async () => {
130130
running++;
131-
await Async.sleep(1);
131+
await Async.sleep(0);
132132
maxRunning = Math.max(maxRunning, running);
133133
running--;
134134
return OperationStatus.Success;

0 commit comments

Comments
 (0)