Created
March 1, 2016 20:46
-
-
Save andywer/8486bc916ff22c1f6d7d to your computer and use it in GitHub Desktop.
Functional test spec for threads.js pool (reproducing #12)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import expect from 'expect.js'; | |
import { Pool } from '../../lib/'; | |
describe('Pool (functional test)', () => { | |
const pool = new Pool(); | |
const jobs = [], promises = []; | |
const handler = (input, done) => { | |
done(input); | |
}; | |
pool.run(handler); | |
it('can send data and run promisified', () => { | |
for (let i = 0; i < 10; i++) { | |
const job = pool.send(i); | |
if (jobs.indexOf(job) > -1) { | |
throw new Error('pool.send() returns the same job twice'); | |
} | |
jobs.push(job); | |
promises.push(job.promise()); | |
} | |
}); | |
it('responds as expected', done => { | |
Promise | |
.all(promises) | |
.then(responses => { | |
expect(responses.sort()).to.eql([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]); | |
done(); | |
}) | |
.catch(error => { | |
done(error); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment