Skip to content

Commit 53b05ef

Browse files
committed
test(eventual-send): port agoric #2885 to endo
1 parent 0ab46f7 commit 53b05ef

File tree

4 files changed

+161
-2
lines changed

4 files changed

+161
-2
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This file is not very useful as an
2+
// automated test. Rather, its purpose is just to run it to see what a
3+
// deep stack looks like.
4+
5+
// eslint-disable-next-line import/no-extraneous-dependencies
6+
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava';
7+
8+
test('no-deep-stacks then', t => {
9+
let r;
10+
const p = new Promise(res => (r = res));
11+
const q = (async () => assert.equal(await ((await p) + 1), 22))();
12+
r(33);
13+
return (async () => {
14+
try {
15+
await q;
16+
} catch (reason) {
17+
t.assert(reason instanceof Error);
18+
console.log('expected failure', reason);
19+
}
20+
})();
21+
});
22+
23+
/*
24+
prepare-test-env-ava sets the `"stackFiltering"` option to `lockdown` to
25+
`"verbose"`. For expository purposes, if the `"stackFiltering"` option to
26+
`lockdown` is set to `"concise"` you should see something like the
27+
following. What you should actually see with `"verbose"` is like this, but with
28+
much extraneous information --- infrastructure stack frames and longer file
29+
paths. See
30+
https://github.com/endojs/endo/blob/master/packages/ses/lockdown-options.md
31+
32+
```
33+
$ ava test/test-await-no-deep-stacks.js
34+
35+
expected failure (RangeError#1)
36+
RangeError#1: Expected 34 is same as 22
37+
at packages/eventual-send/test/test-await-no-deep-stacks.js:11:33
38+
at async packages/eventual-send/test/test-await-no-deep-stacks.js:15:7
39+
```
40+
41+
If you're in a shell or IDE that supports it, try clicking (or command-clicking
42+
or something) on the file paths for test-await-no-deep-stacks.js You should see
43+
one invocation and one await together in one stack as if they occurred in the
44+
same turn. No other turns are visible. Compare with
45+
test-deep-send.js or test-deep-stacks.js to see the debugging advantage of using
46+
eventual-send (`E`) or `E.when` instead.
47+
*/

packages/eventual-send/test/test-deep-send.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file does not start with "test-" because it is useful as an
1+
// This file is not very useful as an
22
// automated test. Rather, its purpose is just to run it to see what a
33
// deep stack looks like.
44

@@ -28,3 +28,38 @@ test('deep-stacks E', t => {
2828
console.log('expected failure', reason);
2929
});
3030
});
31+
32+
/*
33+
prepare-test-env-ava sets the `"stackFiltering"` option to `lockdown` to
34+
`"verbose"`. For expository purposes, if the `"stackFiltering"` option to
35+
`lockdown` is set to `"concise"` you should see something like the
36+
following. What you should actually see with `"verbose"` is like this, but with
37+
much extraneous information --- infrastructure stack frames and longer file
38+
paths. See
39+
https://github.com/endojs/endo/blob/master/packages/ses/lockdown-options.md
40+
41+
```
42+
$ ava test/test-deep-send.js
43+
44+
expected failure (Error#1)
45+
Error#1: Wut?
46+
at Object.bar (packages/eventual-send/test/test-deep-send.js:13:21)
47+
48+
Error#1 ERROR_NOTE: Thrown from: (Error#2) : 2 . 0
49+
Error#1 ERROR_NOTE: Rejection from: (Error#3) : 1 . 1
50+
Nested 2 errors under Error#1
51+
Error#2: Event: 1.1
52+
at Object.foo (packages/eventual-send/test/test-deep-send.js:17:28)
53+
54+
Error#2 ERROR_NOTE: Caused by: (Error#3)
55+
Nested error under Error#2
56+
Error#3: Event: 0.1
57+
at Object.test (packages/eventual-send/test/test-deep-send.js:21:22)
58+
at packages/eventual-send/test/test-deep-send.js:25:19
59+
at async Promise.all (index 0)
60+
```
61+
62+
If you're in a shell or IDE that supports it, try clicking (or command-clicking
63+
or something) on the file paths for test-deep-send.js You should see that there
64+
are four invocations that were spread over three turns.
65+
*/

packages/eventual-send/test/test-deep-stacks.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file does not start with "test-" because it is useful as an
1+
// This file is not very useful as an
22
// automated test. Rather, its purpose is just to run it to see what a
33
// deep stack looks like.
44

@@ -16,3 +16,37 @@ test('deep-stacks when', t => {
1616
console.log('expected failure', reason);
1717
});
1818
});
19+
20+
/*
21+
prepare-test-env-ava sets the `"stackFiltering"` option to `lockdown` to
22+
`"verbose"`. For expository purposes, if the `"stackFiltering"` option to
23+
`lockdown` is set to `"concise"` you should see something like the
24+
following. What you should actually see with `"verbose"` is like this, but with
25+
much extraneous information --- infrastructure stack frames and longer file
26+
paths. See
27+
https://github.com/endojs/endo/blob/master/packages/ses/lockdown-options.md
28+
29+
```
30+
$ ava test/test-deep-stacks.js
31+
32+
expected failure (RangeError#1)
33+
RangeError#1: Expected 34 is same as 22
34+
at packages/eventual-send/test/test-deep-stacks.js:13:57
35+
36+
RangeError#1 ERROR_NOTE: Thrown from: (Error#2) : 2 . 0
37+
RangeError#1 ERROR_NOTE: Rejection from: (Error#3) : 1 . 1
38+
Nested 2 errors under RangeError#1
39+
Error#2: Event: 1.1
40+
at packages/eventual-send/test/test-deep-stacks.js:13:31
41+
42+
Error#2 ERROR_NOTE: Caused by: (Error#3)
43+
Nested error under Error#2
44+
Error#3: Event: 0.1
45+
at packages/eventual-send/test/test-deep-stacks.js:13:15
46+
at async Promise.all (index 0)
47+
```
48+
49+
If you're in a shell or IDE that supports it, try clicking (or command-clicking
50+
or something) on the file paths for test-deep-stacks.js You should see that there
51+
are three invocations that were spread over three turns.
52+
*/
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// This file is not very useful as an
2+
// automated test. Rather, its purpose is just to run it to see what a
3+
// deep stack looks like.
4+
5+
// eslint-disable-next-line import/no-extraneous-dependencies
6+
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava';
7+
8+
test('no-deep-stacks then', t => {
9+
let r;
10+
const p = new Promise(res => (r = res));
11+
const q = p.then(v1 =>
12+
Promise.resolve(v1 + 1).then(v2 => assert.equal(v2, 22)),
13+
);
14+
r(33);
15+
return q.catch(reason => {
16+
t.assert(reason instanceof Error);
17+
console.log('expected failure', reason);
18+
});
19+
});
20+
21+
/*
22+
prepare-test-env-ava sets the `"stackFiltering"` option to `lockdown` to
23+
`"verbose"`. For expository purposes, if the `"stackFiltering"` option to
24+
`lockdown` is set to `"concise"` you should see something like the
25+
following. What you should actually see with `"verbose"` is like this, but with
26+
much extraneous information --- infrastructure stack frames and longer file
27+
paths. See
28+
https://github.com/endojs/endo/blob/master/packages/ses/lockdown-options.md
29+
30+
```
31+
$ ava test/test-then-no-deep-stacks.js
32+
33+
expected failure (RangeError#1)
34+
RangeError#1: Expected 34 is same as 22
35+
at packages/eventual-send/test/test-then-no-deep-stacks.js:12:47
36+
```
37+
38+
If you're in a shell or IDE that supports it, try clicking (or command-clicking
39+
or something) on the file path for test-then-no-deep-stacks.js You should see
40+
only the last invocation with its stack from that one last turn. Compare with
41+
test-deep-send.js or test-deep-stacks.js to see the debugging advantage of using
42+
eventual-send (`E`) or `E.when` instead.
43+
*/

0 commit comments

Comments
 (0)