-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible async problem #21
Comments
@jamestalmage Ah, Good catch! Thank you for sharing your thought! import assert from 'power-assert';
const tests = [];
function test (name, body) {
tests.push({
name,
body
});
}
function later (millis, value) {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(`captured [${value}]`);
resolve(value);
}, millis);
});
};
test('testA', async () => {
const val1 = 'a1';
const val2 = 'a2';
const delay1 = 1000;
const delay2 = 6000;
try {
assert.equal(await later(delay1, val1), await later(delay2, val2));
} catch (e) {
console.log(e.message);
} finally {
console.log(`done [testA]`);
}
});
test('testB', async () => {
const val3 = 'b1';
const val4 = 'b2';
const delay3 = 2000;
const delay4 = 3000;
try {
assert.equal(await later(delay3, val3), await later(delay4, val4));
} catch (e) {
console.log(e.message);
} finally {
console.log(`done [testB]`);
}
});
for (let {name, body} of tests) {
console.log(`running [${name}]`);
body();
} Produces power-assert output that is totally broken.
I'll fix this problem in this issue |
Thanks @twada, I meant to write that test and verify this. Could we maybe introduce a runtime helper? I think Babel 6 now includes an easy way to do that (from what I have browsed of the source. t.is(await foo(), await bar()); var __powerAssertRuntime = require(...); // once at the top of the file.
// create a unique name - I think Babel might have a tool for this.
const capt_1 = new __powerAssertRuntime.Capture();
const capt_2 = new __powerAssertRuntime.Capture();
t.is(await capt_1._expr(capt_1._capt(foo(), {powerAssertContext:...})), await capt_2._... ) |
@jamestalmage Yeah, I'm thinking about introducing runtime helper too. This is my thought but I'll make prototypes of both. |
Now that we support async functions, is the fact that this is in a closure going to be a problem?
I am near certain the answer is yes!
Look at this code:
Now, assume both following sequence of events:
a
startsa
halts as itawait
s the resolution ofpromiseA1()
b
startsb
halts as itawait
s the resolution ofpromiseB1()
promiseA1()
resolves, and testa
resumes.a
halts as itawait
s the resolution ofpromiseA2()
promiseB1()
resolves, and testb
resumes.b
halts as itawait
s the resolution ofpromiseB2()
promiseB2()
resolves, and testb
resumes.b
endspromiseA2()
resolves, and testa
resumes.It seems like
events
is going to be corrupted by step12
.I think AVA is going to need to create a new enhanced assert object for each run.
@twada - thoughts?
The text was updated successfully, but these errors were encountered: