-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! test: use fine-grained expected unhandled rejections
- Loading branch information
1 parent
2b9ae71
commit 4e18904
Showing
2 changed files
with
250 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
import { | ||
annihilate, | ||
startLife, | ||
test, | ||
} from '@agoric/swingset-vat/tools/prepare-strict-test-env-ava.js'; | ||
|
||
import { Far } from '@endo/far'; | ||
import { makeDurableZone } from '@agoric/zone/durable.js'; | ||
|
||
import { makeExpectUnhandledRejectionMacro } from '@agoric/internal/src/lib-nodejs/ava-unhandled-rejection.js'; | ||
import { makeGcAndFinalize } from '@agoric/internal/src/lib-nodejs/gc-and-finalize.js'; | ||
import engineGC from '@agoric/internal/src/lib-nodejs/engine-gc.js'; | ||
import { prepareVowTools } from '../vat.js'; | ||
|
||
const expectUnhandled = test.macro( | ||
makeExpectUnhandledRejectionMacro(import.meta.url), | ||
); | ||
|
||
const gcAndFinalize = makeGcAndFinalize(engineGC); | ||
test.afterEach.always(gcAndFinalize); | ||
|
||
const makeRejectedVow = ( | ||
{ makeVowKit }, | ||
reason = Error('caught the rejection'), | ||
) => { | ||
const { resolver, vow } = makeVowKit(); | ||
resolver.reject(reason); | ||
return vow; | ||
}; | ||
|
||
const makeAndShortenRejectedVow = async ({ makeVowKit }) => { | ||
const vow = makeRejectedVow({ makeVowKit }); | ||
await gcAndFinalize(); | ||
return vow.payload.vowV0.shorten(); | ||
}; | ||
|
||
test.serial('vow shortened, then rejected', async t => { | ||
annihilate(); | ||
|
||
await startLife(async baggage => { | ||
const zone = makeDurableZone(baggage, 'durableRoot'); | ||
const vowTools = prepareVowTools(zone); | ||
|
||
const testVowKit = vowTools.makeVowKit(); | ||
|
||
void testVowKit.vow.payload.vowV0.shorten().then( | ||
value => t.fail(value), | ||
reason => | ||
t.throws( | ||
() => { | ||
throw reason; | ||
}, | ||
{ message: 'caught the rejection' }, | ||
), | ||
); | ||
testVowKit.resolver.reject(Error('caught the rejection')); | ||
}); | ||
}); | ||
|
||
test.serial('vow resolved to rejected promise, then shortened', async t => { | ||
annihilate(); | ||
|
||
await startLife(async baggage => { | ||
const zone = makeDurableZone(baggage, 'durableRoot'); | ||
const vowTools = prepareVowTools(zone); | ||
|
||
const testVowKit = vowTools.makeVowKit(); | ||
|
||
const rejection = Promise.reject(Error('caught the rejection')); | ||
testVowKit.resolver.resolve(rejection); | ||
testVowKit.vow.payload.vowV0.shorten().then( | ||
value => t.fail(value), | ||
reason => | ||
t.throws( | ||
() => { | ||
throw reason; | ||
}, | ||
{ message: 'caught the rejection' }, | ||
), | ||
); | ||
}); | ||
}); | ||
|
||
test.serial.failing( | ||
expectUnhandled, | ||
1, | ||
'vow rejected, then shorten after status update', | ||
async t => { | ||
annihilate(); | ||
|
||
await startLife(async baggage => { | ||
const zone = makeDurableZone(baggage, 'durableRoot'); | ||
const vowTools = prepareVowTools(zone); | ||
|
||
const shorter = makeAndShortenRejectedVow(vowTools); | ||
await gcAndFinalize(); | ||
shorter.then( | ||
value => t.fail(value), | ||
reason => | ||
t.throws( | ||
() => { | ||
throw reason; | ||
}, | ||
{ message: 'caught the rejection' }, | ||
), | ||
); | ||
}); | ||
}, | ||
); | ||
|
||
test.serial.failing( | ||
expectUnhandled, | ||
1, | ||
'vow shortened, upgraded, then shortened again', | ||
async t => { | ||
annihilate(); | ||
|
||
await startLife(async baggage => { | ||
const zone = makeDurableZone(baggage, 'durableRoot'); | ||
const vowTools = prepareVowTools(zone); | ||
|
||
const testVowKit = zone.makeOnce('testVowKit', () => | ||
vowTools.makeVowKit(), | ||
); | ||
|
||
testVowKit.vow.payload.vowV0.shorten().then( | ||
value => t.fail(value), | ||
reason => t.fail(reason), | ||
); | ||
}); | ||
|
||
await startLife(async baggage => { | ||
const zone = makeDurableZone(baggage, 'durableRoot'); | ||
prepareVowTools(zone); | ||
|
||
const testVowKit = zone.makeOnce('testVowKit', () => | ||
t.fail('need testVowKit in baggage'), | ||
); | ||
|
||
testVowKit.resolver.reject(Error('caught the rejection')); | ||
|
||
testVowKit.vow.payload.vowV0.shorten().then( | ||
value => t.fail(value), | ||
reason => | ||
t.throws( | ||
() => { | ||
throw reason; | ||
}, | ||
{ message: 'caught the rejection' }, | ||
), | ||
); | ||
}); | ||
}, | ||
); | ||
|
||
test.serial(expectUnhandled, 1, 'vow rejected, then dropped', async t => { | ||
annihilate(); | ||
|
||
await startLife(async baggage => { | ||
const zone = makeDurableZone(baggage, 'durableRoot'); | ||
const vowTools = prepareVowTools(zone); | ||
|
||
makeRejectedVow(vowTools); | ||
await gcAndFinalize(); | ||
}); | ||
|
||
await gcAndFinalize(); | ||
t.pass(); | ||
}); | ||
|
||
test.serial( | ||
expectUnhandled, | ||
2, | ||
'vow rejected with storable reason, upgraded, then handled', | ||
async t => { | ||
annihilate(); | ||
|
||
await startLife(async baggage => { | ||
const zone = makeDurableZone(baggage, 'durableRoot'); | ||
const vowTools = prepareVowTools(zone); | ||
|
||
zone.makeOnce('testVow', () => makeRejectedVow(vowTools)); | ||
}); | ||
|
||
await startLife(async baggage => { | ||
const zone = makeDurableZone(baggage, 'durableRoot'); | ||
prepareVowTools(zone); | ||
|
||
const vow = zone.makeOnce('testVow', () => | ||
t.fail('need testVow in baggage'), | ||
); | ||
|
||
vow.payload.vowV0.shorten().then( | ||
value => t.fail(value), | ||
reason => | ||
t.throws( | ||
() => { | ||
throw reason; | ||
}, | ||
{ message: 'caught the rejection' }, | ||
), | ||
); | ||
}); | ||
}, | ||
); | ||
|
||
test.serial( | ||
expectUnhandled, | ||
2, | ||
'vow rejected with non-storable reason, upgraded, then handled', | ||
async t => { | ||
annihilate(); | ||
|
||
await startLife(async baggage => { | ||
const zone = makeDurableZone(baggage, 'durableRoot'); | ||
const vowTools = prepareVowTools(zone); | ||
|
||
const nonStorable = Far('non-storable', { | ||
toString() { | ||
return 'is not storable'; | ||
}, | ||
}); | ||
zone.makeOnce('testVow', () => makeRejectedVow(vowTools, nonStorable)); | ||
}); | ||
|
||
await startLife(async baggage => { | ||
const zone = makeDurableZone(baggage, 'durableRoot'); | ||
prepareVowTools(zone); | ||
|
||
const vow = zone.makeOnce('testVow', () => | ||
t.fail('need testVow in baggage'), | ||
); | ||
|
||
vow.payload.vowV0.shorten().then( | ||
value => t.fail(value), | ||
reason => | ||
t.throws( | ||
() => { | ||
throw reason; | ||
}, | ||
{ | ||
message: `Vow rejection reason was not stored: "[Alleged: non-storable]"`, | ||
}, | ||
), | ||
); | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters