Skip to content
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

Added test for strange exception swallowing origamitower/folktale#163 #164

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 45 additions & 15 deletions test/source/specs/base/concurrency/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const eq = function(that) {
return this._state.equals(that._state);
}


describe('Data.Task', () => {

describe('Conversions', () => {
Expand Down Expand Up @@ -168,7 +167,7 @@ describe('Data.Task', () => {
$ASSERT(v1 == 1);

await b.or(a).run().promise().catch(v => $ASSERT(v == 2));


const v2 = await a.or(c).run().promise();
$ASSERT(v2 == 1);
Expand Down Expand Up @@ -335,8 +334,8 @@ describe('Data.Task', () => {
r.cleanup(() => clearTimeout(timer));
});
const result = await Task.do(function *() {
const a = yield delay(10);
const b = yield delay(11);
const a = yield delay(10);
const b = yield delay(11);
const c = yield Task.of(5);
return Task.of(a + b + c + 4);
}).run().promise();
Expand All @@ -352,7 +351,7 @@ describe('Data.Task', () => {
$ASSERT(exception == 5);
})
$ASSERT(exceptionThrown[0] == true);

const resultCancel = await Task.do(function *() {
const a = yield Task.task(r => r.cancel());
return Task.of(a);
Expand All @@ -363,7 +362,7 @@ describe('Data.Task', () => {

const multipleCallsResults = [];
const multipleCallsTask = await Task.do(function *() {
const a = yield delay(10);
const a = yield delay(10);
return Task.of(a);
});
multipleCallsResults[0] = await multipleCallsTask.run().promise();
Expand All @@ -386,14 +385,14 @@ describe('Data.Task', () => {
});

it('Always invokes cleanup after the task resolves', async () => {
let stack = [];
let stack = [];

let d = new Deferred();
Task.task(r => {
Task.task(r => {
stack.push(1);
r.cleanup(() => {
stack.push(2);
d.resolve(2)
d.resolve(2)
});
r.resolve(1)
}).run();
Expand All @@ -402,7 +401,7 @@ describe('Data.Task', () => {

stack = [];
d = new Deferred();
Task.task(r => {
Task.task(r => {
stack.push(3);
r.cleanup(() => {
stack.push(4);
Expand All @@ -415,7 +414,7 @@ describe('Data.Task', () => {

stack = [];
d = new Deferred();
Task.task(r => {
Task.task(r => {
stack.push(5);
r.cleanup(() => {
stack.push(6);
Expand All @@ -427,10 +426,10 @@ describe('Data.Task', () => {
});

it('Invokes onCancelled callbacks if the task is cancelled', async () => {
let stack = [];
let stack = [];

let d = new Deferred();
Task.task(r => {
Task.task(r => {
stack.push(1);
r.cleanup(() => {
stack.push(2);
Expand All @@ -447,7 +446,7 @@ describe('Data.Task', () => {

stack = [];
d = new Deferred();
Task.task(r => {
Task.task(r => {
stack.push(3);
r.cleanup(() => {
stack.push(4);
Expand All @@ -464,7 +463,7 @@ describe('Data.Task', () => {

stack = [];
d = new Deferred();
Task.task(r => {
Task.task(r => {
stack.push(5);
stack.push(r.isCancelled);
r.cleanup(() => {
Expand Down Expand Up @@ -539,6 +538,37 @@ describe('Data.Task', () => {
ex.cancel();
return ex.promise().catch(v => $ASSERT(Cancelled.hasInstance(v)));
});

it('Deals with exception', async () => {
let Result = undefined;

try {
let ex = await Task.of('a')
.map((() => false ? Result.a : Result.b))
.run()
.promise();
// Should have thrown a TypeError by then
$ASSERT(false)
} catch (e) {
$ASSERT(e instanceof TypeError);
}
});

it('Deals with exception corner cases', async () => {
let Result = require('folktale').validation;
try {
let ex = await Task.of('a')
.map((() => false ? Result.a : Result.b))
.run()
.promise();
// Should have thrown a TypeError by then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this one expected to throw a TypeError here?

$ASSERT(false)
// But throws an AssertionError instead
} catch (e) {
$ASSERT(e instanceof TypeError);
}
});

});

describe('#future()', () => {
Expand Down