console warn details

This commit is contained in:
Michael Peters 2022-10-13 21:51:13 -07:00
parent 3c22db0a2c
commit 5e4db47520
2 changed files with 77 additions and 13 deletions

View File

@ -539,11 +539,10 @@ describe('fetchAndVerifyIfNeeded tests', () => {
expect(av.trustedPromise).toBe(trusted.promise); expect(av.trustedPromise).toBe(trusted.promise);
expect(av.trustedStatus).toBe('fetching'); expect(av.trustedStatus).toBe('fetching');
expect(primaryFunc).toHaveBeenCalled(); expect(primaryFunc).toHaveBeenCalled();
expect(trustedFunc).toHaveBeenCalled(); // TODO: Is this the source of the problem? - trustedFunc needs to wait to be called until ensureTrustedFuncReadyFunc is resolved expect(trustedFunc).toHaveBeenCalled();
expect(rejection).toBeUndefined(); expect(rejection).toBeUndefined();
jest.spyOn(console, 'warn').mockImplementationOnce(() => {}); // suppress the warning primary.reject(new Error('rejection')); // this will also 'unverify' the AutoVerifier
primary.reject(new BasicWE(2)); // this will also 'unverify' the AutoVerifier
await disjoint(); await disjoint();
expect(rejection).toBeDefined(); expect(rejection).toBeDefined();
@ -556,6 +555,8 @@ describe('fetchAndVerifyIfNeeded tests', () => {
expect(primaryFunc).toHaveBeenCalledTimes(1); expect(primaryFunc).toHaveBeenCalledTimes(1);
expect(trustedFunc).toHaveBeenCalledTimes(1); // notably, this server response will be thrown out expect(trustedFunc).toHaveBeenCalledTimes(1); // notably, this server response will be thrown out
expect(verifyFunc).toHaveBeenCalledTimes(0); expect(verifyFunc).toHaveBeenCalledTimes(0);
// TODO: Make sure the trusted rejecting later doesn't throw an uncaught promise rejection error
}); });
test('primary with null, trusted rejects - cache miss, failed to ping server', async () => { test('primary with null, trusted rejects - cache miss, failed to ping server', async () => {
@ -633,11 +634,11 @@ describe('fetchAndVerifyIfNeeded tests', () => {
expect(av.trustedStatus).toBe('verifying'); expect(av.trustedStatus).toBe('verifying');
// suppress the warning about trusted rejecting after primary hit // suppress the warning about trusted rejecting after primary hit
const cwSpy = jest.spyOn(console, 'warn').mockImplementationOnce(() => {}); const cwSpy = jest.spyOn(console, 'warn').mockImplementationOnce(() => {}).mockReset(); // suppress the warning
trusted.reject(new Error()); trusted.reject(new Error());
await disjoint(); await disjoint();
expect(cwSpy).toHaveBeenCalled(); expect(cwSpy).toHaveBeenCalledTimes(1);
expect(av.primaryPromise).toBe(null); expect(av.primaryPromise).toBe(null);
expect(av.trustedPromise).toBe(null); expect(av.trustedPromise).toBe(null);
expect(av.trustedStatus).toBe('none'); expect(av.trustedStatus).toBe('none');
@ -861,11 +862,11 @@ describe('fetchAndVerifyIfNeeded tests', () => {
expect(av.trustedPromise).toBe(null); expect(av.trustedPromise).toBe(null);
expect(av.trustedStatus).toBe('none'); expect(av.trustedStatus).toBe('none');
const cwSpy = jest.spyOn(console, 'warn').mockImplementationOnce(() => {}); // suppress the warning const cwSpy = jest.spyOn(console, 'warn').mockImplementationOnce(() => {}).mockReset(); // suppress the warning
trusted1.resolve(new BasicWE(2)); trusted1.resolve(new BasicWE(2));
await disjoint(); await disjoint();
expect(cwSpy).toHaveBeenCalled(); expect(cwSpy).toHaveBeenCalledTimes(1);
expect(trustedFunc).toHaveBeenCalledTimes(2); expect(trustedFunc).toHaveBeenCalledTimes(2);
expect(av.primaryPromise).toBe(null); expect(av.primaryPromise).toBe(null);
expect(av.trustedPromise).toBe(trusted2.promise); expect(av.trustedPromise).toBe(trusted2.promise);
@ -987,8 +988,10 @@ describe('fetchAndVerifyIfNeeded tests', () => {
expect(av.trustedPromise).toBe(null); expect(av.trustedPromise).toBe(null);
expect(av.trustedStatus).toBe('none'); expect(av.trustedStatus).toBe('none');
const cwSpy = jest.spyOn(console, 'warn').mockImplementation(() => {}).mockReset(); // suppress the warning
await disjoint(); await disjoint();
expect(cwSpy).toHaveBeenCalledTimes(2);
expect(av.primaryPromise).toBe(null); expect(av.primaryPromise).toBe(null);
expect(av.trustedPromise).toBe(b.trusted.promise); expect(av.trustedPromise).toBe(b.trusted.promise);
expect(av.trustedStatus).toBe('verifying'); expect(av.trustedStatus).toBe('verifying');
@ -1020,6 +1023,71 @@ describe('fetchAndVerifyIfNeeded tests', () => {
expect(verifyFunc).toHaveBeenCalledTimes(1); expect(verifyFunc).toHaveBeenCalledTimes(1);
}); });
/* 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 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(); */
/* a.primary.resolve(null); */
/* await disjoint(); */
/* 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'); */
/* await disjoint(); */
/* expect(av.primaryPromise).toBe(null); */
/* expect(av.trustedPromise).toBe(b.trusted.promise); */
/* expect(av.trustedStatus).toBe('verifying'); */
/* expect(verifyFunc).toHaveBeenCalledTimes(0); */
/* b.trusted.resolve(new BasicWE(2)); */
/* await disjoint(); */
/* expect(verifyFunc).toHaveBeenCalledWith(null, new BasicWE(2)); */
/* expect(av.primaryPromise).toBe(null); */
/* expect(av.trustedPromise).toBe(b.trusted.promise); */
/* expect(av.trustedStatus).toBe('verifying'); */
/* expect(a.result).toBeUndefined(); */
/* expect(b.result).toBeUndefined(); */
/* a.verify.resolve(true); */
/* await disjoint() */
/* 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'); */
/* 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? // 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 // This would likely make it possible to get rid of the "else" block in tryResolveTrustedPromise
// Make sure it would work properly for retry functionality // Make sure it would work properly for retry functionality

View File

@ -163,11 +163,7 @@ export class AutoVerifier<T> {
console.warn('caught unverified primary promise', e); console.warn('caught unverified primary promise', e);
}); });
} }
if (this.trustedPromise) { // trusted promise rejections are logged through fetchAndVerifyIfNeeded
this.trustedPromise.catch(e => {
console.warn('caught unverified trusted promise', e);
});
}
if (this.verifyPromise) { if (this.verifyPromise) {
this.verifyPromise.catch(e => { this.verifyPromise.catch(e => {
console.warn('caught unverified verify promise', e); console.warn('caught unverified verify promise', e);
@ -235,7 +231,7 @@ export class AutoVerifier<T> {
try { try {
trustedResult = await origTrustedPromise; trustedResult = await origTrustedPromise;
} catch (e: unknown) { } catch (e: unknown) {
if (this.trustedPromise == origTrustedPromise) { if (this.trustedPromise === origTrustedPromise) {
throw e; throw e;
} else { } else {
console.warn('trusted promise rejected after unverify', e); console.warn('trusted promise rejected after unverify', e);