-
Notifications
You must be signed in to change notification settings - Fork 233
/
Copy pathtest-activityhash-vs-start.js
134 lines (114 loc) · 4.03 KB
/
test-activityhash-vs-start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// eslint-disable-next-line import/order
import { test } from '../tools/prepare-test-env-ava.js';
// eslint-disable-next-line import/order
import { initSwingStore, getAllState, setAllState } from '@agoric/swing-store';
import { initializeSwingset, makeSwingsetController } from '../src/index.js';
import { buildTimer } from '../src/devices/timer/timer.js';
const TimerSrc = new URL(
'../src/devices/timer/device-timer.js',
import.meta.url,
).pathname;
// all tests that are sensitive to GC timing (which means anything that
// exercises transcript replay or looks at activityHash) need to use
// test.serial or config.defaultManagerType='xsnap', until we figure out why
// gcAndFinalize sometimes doesn't work (details in #3240 and #4617)
test.serial('restarting kernel does not change activityhash', async t => {
const sourceSpec = new URL('vat-empty-setup.js', import.meta.url).pathname;
const config = {
bootstrap: 'bootstrap',
vats: {
bootstrap: {
sourceSpec,
creationOptions: {
enableSetup: true,
},
},
},
devices: {
timer: {
sourceSpec: TimerSrc,
},
},
};
const timer1 = buildTimer();
const deviceEndowments1 = {
timer: { ...timer1.endowments },
};
const ks1 = initSwingStore().kernelStorage;
// console.log(`--c1 build`);
await initializeSwingset(config, [], ks1);
const c1 = await makeSwingsetController(ks1, deviceEndowments1);
c1.pinVatRoot('bootstrap');
// console.log(`--c1 poll1`);
timer1.poll(1);
// console.log(`--c1 run1`);
await c1.run();
// console.log(`--c1 getAllState`);
const state = getAllState(ks1);
// console.log(`ah: ${c1.getActivityhash()}`);
// console.log(`--c1 poll1`);
timer1.poll(2);
// console.log(`--c1 run2`);
await c1.run();
// console.log(`--c1 dummy()`);
c1.queueToVatRoot('bootstrap', 'dummy', []);
// console.log(`--c1 run3`);
await c1.run();
const c1ah = c1.getActivityhash();
await c1.shutdown();
// console.log(`--c1 shutdown`);
// a kernel restart is loading a new kernel from the same state
const timer2 = buildTimer();
const deviceEndowments2 = {
timer: { ...timer2.endowments },
};
const ks2 = initSwingStore().kernelStorage;
setAllState(ks2, state);
// console.log(`--c2 build`);
const c2 = await makeSwingsetController(ks2, deviceEndowments2);
// console.log(`ah: ${c2.getActivityhash()}`);
// console.log(`--c2 poll1`);
timer2.poll(2);
// console.log(`--c2 run2`);
await c2.run();
// console.log(`--c2 dummy()`);
c2.queueToVatRoot('bootstrap', 'dummy', []);
// console.log(`--c2 run3`);
await c2.run();
const c2ah = c2.getActivityhash();
await c2.shutdown();
t.is(c1ah, c2ah);
});
test.serial('comms initialize is deterministic', async t => {
// bug #3726: comms was calling vatstoreGet('initialize') and
// vatstoreSet('meta.o+0') during the first message after process restart,
// which makes it a nondeterministic function of the input events.
const sourceSpec = new URL('vat-activityhash-comms.js', import.meta.url)
.pathname;
const config = {};
config.bootstrap = 'bootstrap';
config.vats = { bootstrap: { sourceSpec } };
const ks1 = initSwingStore().kernelStorage;
await initializeSwingset(config, [], ks1);
const c1 = await makeSwingsetController(ks1, {});
c1.pinVatRoot('bootstrap');
// the bootstrap message will cause comms to initialize itself
await c1.run();
const state = getAllState(ks1);
// but the second message should not
c1.queueToVatRoot('bootstrap', 'addRemote', ['remote2']);
await c1.run();
const c1ah = c1.getActivityhash();
await c1.shutdown();
// a kernel restart is loading a new kernel from the same state
const ks2 = initSwingStore().kernelStorage;
setAllState(ks2, state);
const c2 = await makeSwingsetController(ks2, {});
// the "am I already initialized?" check must be identical to the
// non-restarted version
c2.queueToVatRoot('bootstrap', 'addRemote', ['remote2']);
await c2.run();
const c2ah = c2.getActivityhash();
await c2.shutdown();
t.is(c1ah, c2ah);
});