-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
192 additions
and
6 deletions.
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
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
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
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
158 changes: 158 additions & 0 deletions
158
packages/async-flow/test/replay-membrane-zombie.test.js
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,158 @@ | ||
// eslint-disable-next-line import/order | ||
import { | ||
test, | ||
getBaggage, | ||
annihilate, | ||
nextLife, | ||
} from './prepare-test-env-ava.js'; | ||
|
||
import { Fail } from '@endo/errors'; | ||
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js'; | ||
import { prepareVowTools } from '@agoric/vow'; | ||
import { makeHeapZone } from '@agoric/zone/heap.js'; | ||
import { makeVirtualZone } from '@agoric/zone/virtual.js'; | ||
import { makeDurableZone } from '@agoric/zone/durable.js'; | ||
|
||
import { prepareLogStore } from '../src/log-store.js'; | ||
import { prepareBijection } from '../src/bijection.js'; | ||
import { makeReplayMembrane } from '../src/replay-membrane.js'; | ||
|
||
const watchWake = _vowish => {}; | ||
const panic = problem => Fail`panic over ${problem}`; | ||
|
||
/** | ||
* @param {any} t | ||
* @param {Zone} zone | ||
*/ | ||
const testMissingStop = async (t, zone) => { | ||
const vowTools = prepareVowTools(zone); | ||
const { makeVowKit } = vowTools; | ||
const makeLogStore = prepareLogStore(zone); | ||
const makeBijection = prepareBijection(zone); | ||
|
||
const log = makeLogStore(); | ||
const bij = makeBijection(); | ||
|
||
const memA = makeReplayMembrane(log, bij, vowTools, watchWake, panic); | ||
|
||
const { vow: v1, resolver: r1 } = makeVowKit(); | ||
|
||
const p1A = memA.hostToGuest(v1); | ||
t.true(bij.has(p1A, v1)); | ||
|
||
await eventLoopIteration(); | ||
|
||
t.deepEqual(log.dump(), []); | ||
|
||
// do all the steps to drop an old membrane and set up a new membrane, | ||
// except stopping the old membrane, | ||
// to demonstate why `makeGuestForHostVow` also tests`stopped`. | ||
log.reset(); | ||
bij.reset(); | ||
const memB = makeReplayMembrane(log, bij, vowTools, watchWake, panic); | ||
|
||
const p1B = memB.hostToGuest(v1); | ||
t.true(bij.has(p1B, v1)); | ||
t.false(bij.hasGuest(p1A)); | ||
|
||
await eventLoopIteration(); | ||
|
||
t.deepEqual(log.dump(), []); | ||
|
||
r1.resolve('x'); | ||
|
||
await eventLoopIteration(); | ||
|
||
t.deepEqual(log.dump(), [ | ||
// keep line break | ||
['doFulfill', v1, 'x'], | ||
['doFulfill', v1, 'x'], // this duplication is wrong, is the point | ||
]); | ||
}; | ||
|
||
/** | ||
* @param {any} t | ||
* @param {Zone} zone | ||
*/ | ||
const testProperStop = async (t, zone) => { | ||
const vowTools = prepareVowTools(zone); | ||
const { makeVowKit } = vowTools; | ||
const makeLogStore = prepareLogStore(zone); | ||
const makeBijection = prepareBijection(zone); | ||
|
||
const log = makeLogStore(); | ||
const bij = makeBijection(); | ||
|
||
const memA = makeReplayMembrane(log, bij, vowTools, watchWake, panic); | ||
|
||
const { vow: v1, resolver: r1 } = makeVowKit(); | ||
|
||
const p1A = memA.hostToGuest(v1); | ||
t.true(bij.has(p1A, v1)); | ||
|
||
await eventLoopIteration(); | ||
|
||
t.deepEqual(log.dump(), []); | ||
|
||
// do all the steps to drop an old membrane and set up a new membrane, | ||
// including stopping the old membrane, | ||
// to demonstate why `makeGuestForHostVow` also tests`stopped`. | ||
log.reset(); | ||
bij.reset(); | ||
memA.stop(); // the point | ||
const memB = makeReplayMembrane(log, bij, vowTools, watchWake, panic); | ||
|
||
const p1B = memB.hostToGuest(v1); | ||
t.true(bij.has(p1B, v1)); | ||
t.false(bij.hasGuest(p1A)); | ||
|
||
await eventLoopIteration(); | ||
|
||
t.deepEqual(log.dump(), []); | ||
|
||
r1.resolve('x'); | ||
|
||
await eventLoopIteration(); | ||
|
||
t.deepEqual(log.dump(), [ | ||
// keep line break | ||
['doFulfill', v1, 'x'], | ||
]); | ||
}; | ||
|
||
await test.serial('test heap replay-membrane missing stop', async t => { | ||
const zone = makeHeapZone('heapRoot'); | ||
return testMissingStop(t, zone); | ||
}); | ||
|
||
await test.serial('test heap replay-membrane proper stop', async t => { | ||
annihilate(); | ||
const zone = makeHeapZone('heapRoot'); | ||
return testProperStop(t, zone); | ||
}); | ||
|
||
await test.serial('test virtual replay-membrane missing stop', async t => { | ||
annihilate(); | ||
const zone = makeVirtualZone('virtualRoot'); | ||
return testMissingStop(t, zone); | ||
}); | ||
|
||
await test.serial('test virtual replay-membrane proper stop', async t => { | ||
annihilate(); | ||
const zone = makeVirtualZone('virtualRoot'); | ||
return testProperStop(t, zone); | ||
}); | ||
|
||
await test.serial('test durable replay-membrane missing stop', async t => { | ||
annihilate(); | ||
nextLife(); | ||
const zone = makeDurableZone(getBaggage(), 'durableRoot'); | ||
return testMissingStop(t, zone); | ||
}); | ||
|
||
await test.serial('test durable replay-membrane proper stop', async t => { | ||
annihilate(); | ||
nextLife(); | ||
const zone = makeDurableZone(getBaggage(), 'durableRoot'); | ||
return testProperStop(t, zone); | ||
}); |