trusted resolve and unverify, second try resolve
This commit is contained in:
parent
5e4db47520
commit
1d53aa46fa
@ -1024,69 +1024,69 @@ describe('fetchAndVerifyIfNeeded tests', () => {
|
||||
});
|
||||
|
||||
|
||||
/* test('ab: a: primary with null, b: primary dedup, ab: resolve trusted fetch and unverify, second trusted with value', async () => { */
|
||||
/* const { */
|
||||
/* nextPrimary, nextTrusted, nextVerify, */
|
||||
/* primaryFunc, trustedFunc, verifyFunc */
|
||||
/* } = getManualsAndMocks(); */
|
||||
test('ab: a: primary with null, b: primary dedup, ab: resolve trusted fetch and unverify, second trusted with value', async () => {
|
||||
const {
|
||||
nextPrimary, nextTrusted, nextVerify,
|
||||
primaryFunc, trustedFunc, verifyFunc
|
||||
} = getManualsAndMocks();
|
||||
|
||||
/* const av = new AutoVerifier(primaryFunc, trustedFunc, verifyFunc); */
|
||||
const av = new AutoVerifier(primaryFunc, trustedFunc, verifyFunc);
|
||||
|
||||
/* const a = fetchAndVerifyIfNeededManually(av, nextPrimary, nextTrusted, nextVerify); */
|
||||
/* const b = fetchAndVerifyIfNeededManually(av, nextPrimary, nextTrusted, nextVerify); */
|
||||
/* */
|
||||
/* expect(av.primaryPromise).toBe(a.primary.promise); */
|
||||
/* expect(av.trustedPromise).toBe(a.trusted.promise); */
|
||||
/* expect(av.trustedStatus).toBe('fetching'); */
|
||||
/* expect(primaryFunc).toHaveBeenCalled(); */
|
||||
/* expect(trustedFunc).toHaveBeenCalled(); */
|
||||
const a = fetchAndVerifyIfNeededManually(av, nextPrimary, nextTrusted, nextVerify);
|
||||
const b = fetchAndVerifyIfNeededManually(av, nextPrimary, nextTrusted, nextVerify);
|
||||
|
||||
/* a.primary.resolve(null); */
|
||||
/* await disjoint(); */
|
||||
expect(av.primaryPromise).toBe(a.primary.promise);
|
||||
expect(av.trustedPromise).toBe(a.trusted.promise);
|
||||
expect(av.trustedStatus).toBe('fetching');
|
||||
expect(primaryFunc).toHaveBeenCalled();
|
||||
expect(trustedFunc).toHaveBeenCalled();
|
||||
|
||||
/* expect(av.primaryPromise).toBe(null); */
|
||||
/* expect(av.trustedPromise).toBe(a.trusted.promise); */
|
||||
/* expect(av.trustedStatus).toBe('verifying'); */
|
||||
/* */
|
||||
/* a.trusted.reject(new Error('rejected')); */
|
||||
/* av.unverify() */
|
||||
/* */
|
||||
/* expect(av.primaryPromise).toBe(null); */
|
||||
/* expect(av.trustedPromise).toBe(null); */
|
||||
/* expect(av.trustedStatus).toBe('none'); */
|
||||
a.primary.resolve(null);
|
||||
await disjoint();
|
||||
|
||||
/* await disjoint(); */
|
||||
expect(av.primaryPromise).toBe(null);
|
||||
expect(av.trustedPromise).toBe(a.trusted.promise);
|
||||
expect(av.trustedStatus).toBe('verifying');
|
||||
|
||||
/* expect(av.primaryPromise).toBe(null); */
|
||||
/* expect(av.trustedPromise).toBe(b.trusted.promise); */
|
||||
/* expect(av.trustedStatus).toBe('verifying'); */
|
||||
a.trusted.resolve(new BasicWE(2));
|
||||
av.unverify()
|
||||
|
||||
/* expect(verifyFunc).toHaveBeenCalledTimes(0); */
|
||||
/* b.trusted.resolve(new BasicWE(2)); */
|
||||
/* await disjoint(); */
|
||||
expect(av.primaryPromise).toBe(null);
|
||||
expect(av.trustedPromise).toBe(null);
|
||||
expect(av.trustedStatus).toBe('none');
|
||||
|
||||
/* expect(verifyFunc).toHaveBeenCalledWith(null, new BasicWE(2)); */
|
||||
/* expect(av.primaryPromise).toBe(null); */
|
||||
/* expect(av.trustedPromise).toBe(b.trusted.promise); */
|
||||
/* expect(av.trustedStatus).toBe('verifying'); */
|
||||
await disjoint();
|
||||
|
||||
/* expect(a.result).toBeUndefined(); */
|
||||
/* expect(b.result).toBeUndefined(); */
|
||||
/* a.verify.resolve(true); */
|
||||
/* await disjoint() */
|
||||
expect(av.primaryPromise).toBe(null);
|
||||
expect(av.trustedPromise).toBe(b.trusted.promise);
|
||||
expect(av.trustedStatus).toBe('verifying');
|
||||
|
||||
/* expect(a.result).toEqual(new BasicWE(2)); */
|
||||
/* expect(b.result).toEqual(new BasicWE(2)); */
|
||||
/* expect(av.primaryPromise).toBe(null); */
|
||||
/* expect(av.trustedPromise).toBe(b.trusted.promise); */
|
||||
/* expect(av.trustedStatus).toBe('verified'); */
|
||||
expect(verifyFunc).toHaveBeenCalledTimes(0);
|
||||
b.trusted.resolve(new BasicWE(3));
|
||||
await disjoint();
|
||||
|
||||
/* await disjoint(); */
|
||||
expect(verifyFunc).toHaveBeenCalledWith(null, new BasicWE(3));
|
||||
expect(av.primaryPromise).toBe(null);
|
||||
expect(av.trustedPromise).toBe(b.trusted.promise);
|
||||
expect(av.trustedStatus).toBe('verifying');
|
||||
|
||||
/* expect(primaryFunc).toHaveBeenCalledTimes(1); */
|
||||
/* expect(trustedFunc).toHaveBeenCalledTimes(2); */
|
||||
/* expect(verifyFunc).toHaveBeenCalledTimes(1); */
|
||||
/* }); */
|
||||
expect(a.result).toBeUndefined();
|
||||
expect(b.result).toBeUndefined();
|
||||
a.verify.resolve(true);
|
||||
await disjoint()
|
||||
|
||||
expect(a.result).toEqual(new BasicWE(3));
|
||||
expect(b.result).toEqual(new BasicWE(3));
|
||||
expect(av.primaryPromise).toBe(null);
|
||||
expect(av.trustedPromise).toBe(b.trusted.promise);
|
||||
expect(av.trustedStatus).toBe('verified');
|
||||
|
||||
await disjoint();
|
||||
|
||||
expect(primaryFunc).toHaveBeenCalledTimes(1);
|
||||
expect(trustedFunc).toHaveBeenCalledTimes(2);
|
||||
expect(verifyFunc).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
// TODO: Why not have fetcher and a simple dedup wrapper to remove some complexity from this function?
|
||||
// This would likely make it possible to get rid of the "else" block in tryResolveTrustedPromise
|
||||
|
@ -296,7 +296,7 @@ export class AutoVerifier<T> {
|
||||
try {
|
||||
trustedResult = await origTrustedPromise;
|
||||
} catch (e: unknown) {
|
||||
if (this.trustedPromise == origTrustedPromise) {
|
||||
if (this.trustedPromise === origTrustedPromise) {
|
||||
throw e;
|
||||
} else {
|
||||
console.warn('trusted promise from another path rejected after unverify', e);
|
||||
@ -343,8 +343,8 @@ export class AutoVerifier<T> {
|
||||
await tryResolveTrustedPromise();
|
||||
} catch (e: unknown) {
|
||||
if (!resolved) {
|
||||
this.trustedPromise = null; // suppress warnings about uncaught rejections
|
||||
this.primaryPromise = null; // suppress warnings about uncaught rejections
|
||||
//this.trustedPromise = null; // suppress warnings about uncaught rejections
|
||||
this.verifyPromise = null; // suppress warnings about uncaught rejections
|
||||
this.unverify();
|
||||
// eslint-disable-next-line prefer-promise-reject-errors
|
||||
|
Loading…
Reference in New Issue
Block a user