smartspawn/test/test.ts

55 lines
1.6 KiB
TypeScript
Raw Normal View History

import 'typings-test'
2017-03-03 19:52:23 +00:00
import { expect } from 'smartchai'
import * as smartipc from '../dist/index'
2017-01-29 19:50:36 +00:00
let testThreadFunction: smartipc.ThreadFunction
let testThread: smartipc.Thread
2017-01-29 22:41:26 +00:00
let testPool: smartipc.Pool
2017-03-03 19:52:23 +00:00
describe('smartipc', function () {
it('should create an instance of ThreadFunction', function () {
testThreadFunction = new smartipc.ThreadFunction((input, done) => {
let url = require('url')
done(url.parse(input))
2017-01-29 19:50:36 +00:00
})
2017-03-03 19:52:23 +00:00
testThreadFunction.send('https://google.com').then(message => {
console.log(message)
testThreadFunction.kill()
})
2017-03-03 19:52:23 +00:00
})
it('should create an instance of Thread', function () {
smartipc.setWorkerBasePath(__dirname)
testThread = new smartipc.Thread('child.js')
testThread.send('https://google.com').then(message => {
console.log(message)
testThread.kill()
})
})
it('should not spawn when nothing is sent', function () {
smartipc.setWorkerBasePath(__dirname)
let testThread = new smartipc.Thread('child.js')
})
2017-01-29 22:41:26 +00:00
2017-03-03 19:52:23 +00:00
it('should run in a Pool', function () {
let testPool = new smartipc.Pool()
let testThread = new smartipc.Thread('child.js')
testThread.assignToPool(testPool)
return testThread.send('what').then(message => {
console.log(message)
return testThread.send('another').then(message => {
console.log(message)
testThread.assignedPool.pool.killAll()
})
2017-01-29 22:41:26 +00:00
})
2017-03-03 19:52:23 +00:00
})
2017-01-29 22:41:26 +00:00
2017-03-03 19:52:23 +00:00
it('should once', function () {
let testThread = new smartipc.Thread('child.js')
return testThread.sendOnce('what').then(message => {
expect(message).to.equal('what')
2017-01-29 22:41:26 +00:00
})
2017-03-03 19:52:23 +00:00
})
})