@agoric/swingset-liveslots 0.10.3-dev-2b7c650.0 → 0.10.3-mainnet1B-dev-c0e1089.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -0
- package/package.json +17 -20
- package/src/collectionManager.js +66 -135
- package/src/index.js +1 -2
- package/src/liveslots.js +74 -47
- package/src/virtualObjectManager.js +14 -56
- package/src/virtualReferences.js +0 -51
- package/test/liveslots-helpers.js +4 -4
- package/test/mock-gc.js +0 -1
- package/test/storeGC/test-lifecycle.js +1 -1
- package/test/storeGC/test-refcount-management.js +1 -0
- package/test/storeGC/test-scalar-store-kind.js +1 -0
- package/test/storeGC/test-weak-key.js +1 -0
- package/test/test-baggage.js +1 -0
- package/test/test-cache.js +1 -0
- package/test/test-collection-schema-refcount.js +1 -0
- package/test/test-collection-upgrade.js +2 -0
- package/test/test-collections.js +14 -117
- package/test/test-dropped-collection-weakrefs.js +1 -0
- package/test/test-durabilityChecks.js +3 -2
- package/test/test-facetiousness.js +2 -1
- package/test/test-gc-sensitivity.js +1 -1
- package/test/test-handled-promises.js +6 -4
- package/test/test-initial-vrefs.js +2 -1
- package/test/test-liveslots-mock-gc.js +1 -1
- package/test/test-liveslots-real-gc.js +1 -1
- package/test/test-liveslots.js +13 -12
- package/test/test-vo-test-harness.js +1 -0
- package/test/test-vpid-liveslots.js +2 -1
- package/test/util.js +1 -1
- package/test/virtual-objects/test-cease-recognition.js +2 -2
- package/test/virtual-objects/test-cross-facet.js +2 -1
- package/test/virtual-objects/test-empty-data.js +2 -1
- package/test/virtual-objects/test-facets.js +2 -1
- package/test/virtual-objects/test-kind-changes.js +1 -1
- package/test/virtual-objects/test-reachable-vrefs.js +2 -2
- package/test/virtual-objects/test-rep-tostring.js +3 -2
- package/test/virtual-objects/test-retain-remotable.js +1 -1
- package/test/virtual-objects/test-state-shape.js +1 -1
- package/test/virtual-objects/test-virtualObjectGC.js +1 -1
- package/test/virtual-objects/test-virtualObjectManager.js +1 -5
- package/test/virtual-objects/test-vo-real-gc.js +1 -1
- package/test/virtual-objects/test-weakcollections-vref-handling.js +2 -1
- package/src/vatDataTypes.d.ts +0 -230
- package/src/vatDataTypes.js +0 -2
- package/tools/fakeCollectionManager.js +0 -44
- package/tools/fakeVirtualObjectManager.js +0 -60
- package/tools/fakeVirtualSupport.js +0 -375
- package/tools/prepare-test-env.js +0 -13
- package/tools/setup-vat-data.js +0 -54
- package/tools/vo-test-harness.js +0 -143
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prepare Agoric SwingSet vat global environment for testing.
|
|
3
|
-
*
|
|
4
|
-
* Installs Hardened JS (and does lockdown), plus adds mocks for virtual objects
|
|
5
|
-
* and stores.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import '@agoric/internal/src/install-ses-debug.js';
|
|
9
|
-
|
|
10
|
-
import { reincarnate } from './setup-vat-data.js';
|
|
11
|
-
|
|
12
|
-
// Install the VatData globals.
|
|
13
|
-
reincarnate();
|
package/tools/setup-vat-data.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
/* global globalThis */
|
|
3
|
-
// This file produces the globalThis.VatData property outside of a running
|
|
4
|
-
// SwingSet so that it can be used by '@agoric/vat-data' (which only *consumes*
|
|
5
|
-
// `globalThis.VatData`) in code under test.
|
|
6
|
-
import { makeFakeVirtualStuff } from './fakeVirtualSupport.js';
|
|
7
|
-
|
|
8
|
-
const { WeakMap, WeakSet } = globalThis;
|
|
9
|
-
|
|
10
|
-
/** @type {ReturnType<makeFakeVirtualStuff>} */
|
|
11
|
-
let fakeVomKit;
|
|
12
|
-
|
|
13
|
-
globalThis.VatData = harden({
|
|
14
|
-
defineKind: (...args) => fakeVomKit.vom.defineKind(...args),
|
|
15
|
-
defineKindMulti: (...args) => fakeVomKit.vom.defineKindMulti(...args),
|
|
16
|
-
defineDurableKind: (...args) => fakeVomKit.vom.defineDurableKind(...args),
|
|
17
|
-
defineDurableKindMulti: (...args) =>
|
|
18
|
-
fakeVomKit.vom.defineDurableKindMulti(...args),
|
|
19
|
-
makeKindHandle: (...args) => fakeVomKit.vom.makeKindHandle(...args),
|
|
20
|
-
canBeDurable: (...args) => fakeVomKit.vom.canBeDurable(...args),
|
|
21
|
-
providePromiseWatcher: (...args) =>
|
|
22
|
-
fakeVomKit.wpm.providePromiseWatcher(...args),
|
|
23
|
-
watchPromise: (...args) => fakeVomKit.wpm.watchPromise(...args),
|
|
24
|
-
makeScalarBigMapStore: (...args) =>
|
|
25
|
-
fakeVomKit.cm.makeScalarBigMapStore(...args),
|
|
26
|
-
makeScalarBigWeakMapStore: (...args) =>
|
|
27
|
-
fakeVomKit.cm.makeScalarBigWeakMapStore(...args),
|
|
28
|
-
makeScalarBigSetStore: (...args) =>
|
|
29
|
-
fakeVomKit.cm.makeScalarBigSetStore(...args),
|
|
30
|
-
makeScalarBigWeakSetStore: (...args) =>
|
|
31
|
-
fakeVomKit.cm.makeScalarBigWeakSetStore(...args),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
export const reincarnate = (options = {}) => {
|
|
35
|
-
const { fakeStore = new Map(), fakeVomKit: fvk } = options;
|
|
36
|
-
|
|
37
|
-
if (options.fakeVomKit) {
|
|
38
|
-
fvk.vom.flushStateCache();
|
|
39
|
-
fvk.cm.flushSchemaCache();
|
|
40
|
-
fvk.vrm.flushIDCounters();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
fakeVomKit = makeFakeVirtualStuff({
|
|
44
|
-
...options,
|
|
45
|
-
fakeStore,
|
|
46
|
-
WeakMap,
|
|
47
|
-
WeakSet,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
globalThis.WeakMap = fakeVomKit.vom.VirtualObjectAwareWeakMap;
|
|
51
|
-
globalThis.WeakSet = fakeVomKit.vom.VirtualObjectAwareWeakSet;
|
|
52
|
-
|
|
53
|
-
return { ...options, fakeStore, fakeVomKit };
|
|
54
|
-
};
|
package/tools/vo-test-harness.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { Far } from '@endo/marshal';
|
|
2
|
-
import { setupTestLiveslots } from '../test/liveslots-helpers.js';
|
|
3
|
-
|
|
4
|
-
// This file contains a test harness for virtual objects. runVOTest()
|
|
5
|
-
// is to to help verify that a VO can be garbage collected and then
|
|
6
|
-
// reloaded from persistent storage while maintaining functionality.
|
|
7
|
-
|
|
8
|
-
// Testing VO swapping with runVOTest:
|
|
9
|
-
//
|
|
10
|
-
// Step 1: import the necessary harness paraphernalia
|
|
11
|
-
//
|
|
12
|
-
// import { test, runVOTest } from '@agoric/swingset-vat/tools/vo-test-harness.js';
|
|
13
|
-
//
|
|
14
|
-
// `test` is the regular Ava test object that you'd normally import from
|
|
15
|
-
// `@agoric/swingset-vat/tools/prepare-test-env-ava.js`. The test harness will
|
|
16
|
-
// import it for you, since it needs to set up some test things itself.
|
|
17
|
-
//
|
|
18
|
-
// Step 2: write three functions that you will pass to the test harness
|
|
19
|
-
//
|
|
20
|
-
// `prepare(VatData)` should perform any necessary environmental setup that the
|
|
21
|
-
// virtual object kind under test will require. In particular, this includes
|
|
22
|
-
// executing any necessary `defineKind` or `defineDurableKind` calls to
|
|
23
|
-
// establish the VO itself. The `VatData` parameter is a regular `VatData`
|
|
24
|
-
// object that can be used to obtain functions like `defineKind`.
|
|
25
|
-
//
|
|
26
|
-
// `makeTestObject()` should create and return an instance of the VO to be tested.
|
|
27
|
-
//
|
|
28
|
-
// `testTestObject(obj, phase)` should execute whatever actual testing and test
|
|
29
|
-
// assertions you care to perform to verify your VO kind. `obj` will be a
|
|
30
|
-
// reference to an in-memory representative of the virtual object being tested
|
|
31
|
-
// and `phase` will be a string, either 'before' or 'after', indicating whether
|
|
32
|
-
// this instance of the object is before or after having been swapped out of
|
|
33
|
-
// memory and then reloaded. A correctly functioning VO should, among other
|
|
34
|
-
// things, behave exactly the same in both cases.
|
|
35
|
-
//
|
|
36
|
-
// Step 3: write an Ava test that invokes the test harness
|
|
37
|
-
//
|
|
38
|
-
// The outer portion of this should be a conventional Ava test written in the
|
|
39
|
-
// conventional way, e.g.:
|
|
40
|
-
//
|
|
41
|
-
// test('test name', async t => {
|
|
42
|
-
// ...your test here...
|
|
43
|
-
// });
|
|
44
|
-
//
|
|
45
|
-
// The body of your test most likely will enclose the three functions described
|
|
46
|
-
// above, since your `testTestObject` function (and possibly the others,
|
|
47
|
-
// depending on how you code things) will need access to the `t` object in order
|
|
48
|
-
// to execute test assertions. Then, from inside your test invoke:
|
|
49
|
-
//
|
|
50
|
-
// await runVOTest(t, prepare, makeTestObject, testTestObject);
|
|
51
|
-
//
|
|
52
|
-
// This will:
|
|
53
|
-
// 1 - execute the `prepare` function
|
|
54
|
-
// 2 - create a test object instance via `makeTestObject`
|
|
55
|
-
// 3 - run `testTestObject` on the test object (this is the 'before' phase)
|
|
56
|
-
// 4 - drop all in-memory references to the test object and force a GC pass
|
|
57
|
-
// 5 - run `testTestObject` on the test object *again* (this is the 'after' phase)
|
|
58
|
-
//
|
|
59
|
-
// The key thing that the test harness provides for you is step 4, which
|
|
60
|
-
// packages up some awkward boilerplate that's a bit of mysterious if you're not
|
|
61
|
-
// already pretty familiar with how the VO GC mechanism works (or perhaps even
|
|
62
|
-
// if you are).
|
|
63
|
-
//
|
|
64
|
-
// Note: It is critical that none of your own code retain any in-memory
|
|
65
|
-
// references to the test object beyond step 3. However, another key service
|
|
66
|
-
// that the test harness provides is to detect if you did this and if so fail
|
|
67
|
-
// the test. One use of the test harness is to verify that you aren't
|
|
68
|
-
// accidentally holding such references when you didn't mean to.
|
|
69
|
-
//
|
|
70
|
-
// The SwingSet test `vo-test-harness/test-vo-test-harness.js` is a test of the
|
|
71
|
-
// VO test harness itself, but can be used as a simple example of how to set
|
|
72
|
-
// things up.
|
|
73
|
-
|
|
74
|
-
export async function runVOTest(t, prepare, makeTestObject, testTestObject) {
|
|
75
|
-
function buildRootObject(vatPowers) {
|
|
76
|
-
const { VatData } = vatPowers;
|
|
77
|
-
const { defineKind } = VatData;
|
|
78
|
-
|
|
79
|
-
const freeChecker = new WeakSet();
|
|
80
|
-
|
|
81
|
-
const makeSlug = defineKind('slug', label => ({ label }), {
|
|
82
|
-
getLabel: ({ state }) => state.label,
|
|
83
|
-
});
|
|
84
|
-
const cacheDisplacer = makeSlug('cacheDisplacer');
|
|
85
|
-
|
|
86
|
-
const makeHolder = defineKind('holder', (held = null) => ({ held }), {
|
|
87
|
-
setValue: ({ state }, value) => {
|
|
88
|
-
state.held = value;
|
|
89
|
-
},
|
|
90
|
-
getValue: ({ state }) => state.held,
|
|
91
|
-
});
|
|
92
|
-
const holder = makeHolder();
|
|
93
|
-
|
|
94
|
-
let held = null;
|
|
95
|
-
|
|
96
|
-
prepare(VatData);
|
|
97
|
-
|
|
98
|
-
function displaceCache() {
|
|
99
|
-
return cacheDisplacer.getLabel();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return Far('root', {
|
|
103
|
-
makeAndHold() {
|
|
104
|
-
held = makeTestObject();
|
|
105
|
-
freeChecker.add(held);
|
|
106
|
-
displaceCache();
|
|
107
|
-
},
|
|
108
|
-
storeHeld() {
|
|
109
|
-
holder.setValue(held);
|
|
110
|
-
displaceCache();
|
|
111
|
-
},
|
|
112
|
-
dropHeld() {
|
|
113
|
-
held = null;
|
|
114
|
-
displaceCache();
|
|
115
|
-
},
|
|
116
|
-
fetchAndHold() {
|
|
117
|
-
held = holder.getValue();
|
|
118
|
-
t.falsy(
|
|
119
|
-
freeChecker.has(held),
|
|
120
|
-
'somebody continues to hold test object',
|
|
121
|
-
);
|
|
122
|
-
displaceCache();
|
|
123
|
-
},
|
|
124
|
-
testHeld(phase) {
|
|
125
|
-
testTestObject(held, phase);
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const { dispatchMessage } = await setupTestLiveslots(
|
|
131
|
-
t,
|
|
132
|
-
buildRootObject,
|
|
133
|
-
'bob',
|
|
134
|
-
{ forceGC: true, skipLogging: true },
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
await dispatchMessage('makeAndHold');
|
|
138
|
-
await dispatchMessage('testHeld', 'before');
|
|
139
|
-
await dispatchMessage('storeHeld');
|
|
140
|
-
await dispatchMessage('dropHeld');
|
|
141
|
-
await dispatchMessage('fetchAndHold');
|
|
142
|
-
await dispatchMessage('testHeld', 'after');
|
|
143
|
-
}
|