Skip to content

Commit 00296cf

Browse files
committed
Fix promise handling in poll functions to avoid test timeout
1 parent 131e847 commit 00296cf

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/windowsTerminal.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface IWindowsProcessTreeResult {
2020
}
2121

2222
function pollForProcessState(desiredState: IProcessState, intervalMs: number = 100, timeoutMs: number = 2000): Promise<void> {
23-
return new Promise<void>(resolve => {
23+
return new Promise<void>((resolve, reject) => {
2424
let tries = 0;
2525
const interval = setInterval(() => {
2626
psList({ all: true }).then(ps => {
@@ -49,16 +49,15 @@ function pollForProcessState(desiredState: IProcessState, intervalMs: number = 1
4949
if (tries * intervalMs >= timeoutMs) {
5050
clearInterval(interval);
5151
const processListing = pids.map(k => `${k}: ${desiredState[k]}`).join('\n');
52-
assert.fail(`Bad process state, expected:\n${processListing}`);
53-
resolve();
52+
reject(new Error(`Bad process state, expected:\n${processListing}`));
5453
}
5554
});
5655
}, intervalMs);
5756
});
5857
}
5958

6059
function pollForProcessTreeSize(pid: number, size: number, intervalMs: number = 100, timeoutMs: number = 2000): Promise<IWindowsProcessTreeResult[]> {
61-
return new Promise<IWindowsProcessTreeResult[]>(resolve => {
60+
return new Promise<IWindowsProcessTreeResult[]>((resolve, reject) => {
6261
let tries = 0;
6362
const interval = setInterval(() => {
6463
psList({ all: true }).then(ps => {
@@ -84,7 +83,7 @@ function pollForProcessTreeSize(pid: number, size: number, intervalMs: number =
8483
tries++;
8584
if (tries * intervalMs >= timeoutMs) {
8685
clearInterval(interval);
87-
assert.fail(`Bad process state, expected: ${size}, actual: ${list.length}`);
86+
reject(new Error(`Bad process state, expected: ${size}, actual: ${list.length}`));
8887
}
8988
});
9089
}, intervalMs);
@@ -120,9 +119,9 @@ if (process.platform === 'win32') {
120119
term.on('exit', () => {
121120
pollForProcessState(desiredState, 1000, 5000).then(() => {
122121
done();
123-
});
122+
}).catch(done);
124123
});
125-
});
124+
}).catch(done);
126125
});
127126
});
128127

0 commit comments

Comments
 (0)