Fix notebook execution test failures (#157290)

* Fix notebook execution test failures
An error thrown in an event handler did not cause the test to fail, using DeferredPromise. Adjusting the api event to account for Unconfirmed vs Pending states. And accounting for onDidChangeNotebookDocument being fired multiple times during a test, causing the test to complete early while execution was still happening.
Fixes #157067

* Remove log
This commit is contained in:
Rob Lourens
2022-08-05 13:07:20 -05:00
committed by GitHub
parent 6d24a019d8
commit 8671778f8d
5 changed files with 105 additions and 42 deletions

View File

@@ -184,3 +184,61 @@ export async function poll<T>(
trial++;
}
}
export type ValueCallback<T = unknown> = (value: T | Promise<T>) => void;
/**
* Creates a promise whose resolution or rejection can be controlled imperatively.
*/
export class DeferredPromise<T> {
private completeCallback!: ValueCallback<T>;
private errorCallback!: (err: unknown) => void;
private rejected = false;
private resolved = false;
public get isRejected() {
return this.rejected;
}
public get isResolved() {
return this.resolved;
}
public get isSettled() {
return this.rejected || this.resolved;
}
public readonly p: Promise<T>;
constructor() {
this.p = new Promise<T>((c, e) => {
this.completeCallback = c;
this.errorCallback = e;
});
}
public complete(value: T) {
return new Promise<void>(resolve => {
this.completeCallback(value);
this.resolved = true;
resolve();
});
}
public error(err: unknown) {
return new Promise<void>(resolve => {
this.errorCallback(err);
this.rejected = true;
resolve();
});
}
public cancel() {
new Promise<void>(resolve => {
this.errorCallback(new Error('Canceled'));
this.rejected = true;
resolve();
});
}
}