diff --git a/packages/eventual-send/test/test-await-no-deep-stacks.js b/packages/eventual-send/test/test-await-no-deep-stacks.js new file mode 100644 index 0000000000..951d66307d --- /dev/null +++ b/packages/eventual-send/test/test-await-no-deep-stacks.js @@ -0,0 +1,46 @@ +// This file is not very useful as an +// automated test. Rather, its purpose is just to run it to see what a +// deep stack looks like. + +import { test } from './prepare-test-env-ava.js'; + +test('no-deep-stacks then', t => { + let r; + const p = new Promise(res => (r = res)); + const q = (async () => assert.equal(await ((await p) + 1), 22))(); + r(33); + return (async () => { + try { + await q; + } catch (reason) { + t.assert(reason instanceof Error); + console.log('expected failure', reason); + } + })(); +}); + +/* +prepare-test-env-ava sets the `"stackFiltering"` option to `lockdown` to +`"verbose"`. For expository purposes, if the `"stackFiltering"` option to +`lockdown` is set to `"concise"` you should see something like the +following. What you should actually see with `"verbose"` is like this, but with +much extraneous information --- infrastructure stack frames and longer file +paths. See +https://github.com/endojs/endo/blob/master/packages/ses/lockdown-options.md + +``` +$ ava test/test-await-no-deep-stacks.js + +expected failure (RangeError#1) +RangeError#1: Expected 34 is same as 22 + at packages/eventual-send/test/test-await-no-deep-stacks.js:11:33 + at async packages/eventual-send/test/test-await-no-deep-stacks.js:15:7 +``` + +If you're in a shell or IDE that supports it, try clicking (or command-clicking +or something) on the file paths for test-await-no-deep-stacks.js You should see +one invocation and one await together in one stack as if they occurred in the +same turn. No other turns are visible. Compare with +test-deep-send.js or test-deep-stacks.js to see the debugging advantage of using +eventual-send (`E`) or `E.when` instead. +*/ diff --git a/packages/eventual-send/test/test-deep-send.js b/packages/eventual-send/test/test-deep-send.js index 4ab8ac39b9..27868e2a28 100644 --- a/packages/eventual-send/test/test-deep-send.js +++ b/packages/eventual-send/test/test-deep-send.js @@ -1,4 +1,4 @@ -// This file does not start with "test-" because it is useful as an +// This file is not very useful as an // automated test. Rather, its purpose is just to run it to see what a // deep stack looks like. @@ -28,3 +28,38 @@ test('deep-stacks E', t => { console.log('expected failure', reason); }); }); + +/* +prepare-test-env-ava sets the `"stackFiltering"` option to `lockdown` to +`"verbose"`. For expository purposes, if the `"stackFiltering"` option to +`lockdown` is set to `"concise"` you should see something like the +following. What you should actually see with `"verbose"` is like this, but with +much extraneous information --- infrastructure stack frames and longer file +paths. See +https://github.com/endojs/endo/blob/master/packages/ses/lockdown-options.md + +``` +$ ava test/test-deep-send.js + +expected failure (Error#1) +Error#1: Wut? + at Object.bar (packages/eventual-send/test/test-deep-send.js:13:21) + +Error#1 ERROR_NOTE: Thrown from: (Error#2) : 2 . 0 +Error#1 ERROR_NOTE: Rejection from: (Error#3) : 1 . 1 +Nested 2 errors under Error#1 + Error#2: Event: 1.1 + at Object.foo (packages/eventual-send/test/test-deep-send.js:17:28) + + Error#2 ERROR_NOTE: Caused by: (Error#3) + Nested error under Error#2 + Error#3: Event: 0.1 + at Object.test (packages/eventual-send/test/test-deep-send.js:21:22) + at packages/eventual-send/test/test-deep-send.js:25:19 + at async Promise.all (index 0) +``` + +If you're in a shell or IDE that supports it, try clicking (or command-clicking +or something) on the file paths for test-deep-send.js You should see that there +are four invocations that were spread over three turns. +*/ diff --git a/packages/eventual-send/test/test-deep-stacks.js b/packages/eventual-send/test/test-deep-stacks.js index b596e8491c..61484b5aa1 100644 --- a/packages/eventual-send/test/test-deep-stacks.js +++ b/packages/eventual-send/test/test-deep-stacks.js @@ -1,4 +1,4 @@ -// This file does not start with "test-" because it is useful as an +// This file is not very useful as an // automated test. Rather, its purpose is just to run it to see what a // deep stack looks like. @@ -16,3 +16,37 @@ test('deep-stacks when', t => { console.log('expected failure', reason); }); }); + +/* +prepare-test-env-ava sets the `"stackFiltering"` option to `lockdown` to +`"verbose"`. For expository purposes, if the `"stackFiltering"` option to +`lockdown` is set to `"concise"` you should see something like the +following. What you should actually see with `"verbose"` is like this, but with +much extraneous information --- infrastructure stack frames and longer file +paths. See +https://github.com/endojs/endo/blob/master/packages/ses/lockdown-options.md + +``` +$ ava test/test-deep-stacks.js + +expected failure (RangeError#1) +RangeError#1: Expected 34 is same as 22 + at packages/eventual-send/test/test-deep-stacks.js:13:57 + +RangeError#1 ERROR_NOTE: Thrown from: (Error#2) : 2 . 0 +RangeError#1 ERROR_NOTE: Rejection from: (Error#3) : 1 . 1 +Nested 2 errors under RangeError#1 + Error#2: Event: 1.1 + at packages/eventual-send/test/test-deep-stacks.js:13:31 + + Error#2 ERROR_NOTE: Caused by: (Error#3) + Nested error under Error#2 + Error#3: Event: 0.1 + at packages/eventual-send/test/test-deep-stacks.js:13:15 + at async Promise.all (index 0) +``` + +If you're in a shell or IDE that supports it, try clicking (or command-clicking +or something) on the file paths for test-deep-stacks.js You should see that there +are three invocations that were spread over three turns. +*/ diff --git a/packages/eventual-send/test/test-then-no-deep-stacks.js b/packages/eventual-send/test/test-then-no-deep-stacks.js new file mode 100644 index 0000000000..021d8fba6d --- /dev/null +++ b/packages/eventual-send/test/test-then-no-deep-stacks.js @@ -0,0 +1,42 @@ +// This file is not very useful as an +// automated test. Rather, its purpose is just to run it to see what a +// deep stack looks like. + +import { test } from './prepare-test-env-ava.js'; + +test('no-deep-stacks then', t => { + let r; + const p = new Promise(res => (r = res)); + const q = p.then(v1 => + Promise.resolve(v1 + 1).then(v2 => assert.equal(v2, 22)), + ); + r(33); + return q.catch(reason => { + t.assert(reason instanceof Error); + console.log('expected failure', reason); + }); +}); + +/* +prepare-test-env-ava sets the `"stackFiltering"` option to `lockdown` to +`"verbose"`. For expository purposes, if the `"stackFiltering"` option to +`lockdown` is set to `"concise"` you should see something like the +following. What you should actually see with `"verbose"` is like this, but with +much extraneous information --- infrastructure stack frames and longer file +paths. See +https://github.com/endojs/endo/blob/master/packages/ses/lockdown-options.md + +``` +$ ava test/test-then-no-deep-stacks.js + +expected failure (RangeError#1) +RangeError#1: Expected 34 is same as 22 + at packages/eventual-send/test/test-then-no-deep-stacks.js:12:47 +``` + +If you're in a shell or IDE that supports it, try clicking (or command-clicking +or something) on the file path for test-then-no-deep-stacks.js You should see +only the last invocation with its stack from that one last turn. Compare with +test-deep-send.js or test-deep-stacks.js to see the debugging advantage of using +eventual-send (`E`) or `E.when` instead. +*/