update smartipc internal code

This commit is contained in:
2017-03-03 20:52:23 +01:00
parent 05cbbda941
commit a16a66f1f6
19 changed files with 634 additions and 109 deletions

View File

@@ -1,4 +1,5 @@
import 'typings-test'
import { expect } from 'smartchai'
import * as smartipc from '../dist/index'
@@ -6,41 +7,48 @@ let testThreadFunction: smartipc.ThreadFunction
let testThread: smartipc.Thread
let testPool: smartipc.Pool
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))
})
testThreadFunction.send('https://google.com').then(message => {
console.log(message)
testThreadFunction.kill()
})
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))
})
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()
})
testThreadFunction.send('https://google.com').then(message => {
console.log(message)
testThreadFunction.kill()
})
})
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')
})
it('should not spawn when nothing is sent', function () {
smartipc.setWorkerBasePath(__dirname)
let testThread = new smartipc.Thread('child.js')
})
it('should run in a Pool', function() {
let testPool = new smartipc.Pool()
let testThread = new smartipc.Thread('child.js')
testThread.assignToPool(testPool)
testThread.send('what').then(message => {
console.log(message)
testThread.send('another').then(message => {
console.log(message)
testThread.assignedPool.pool.killAll()
})
})
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()
})
})
})
it('should once', function () {
let testThread = new smartipc.Thread('child.js')
return testThread.sendOnce('what').then(message => {
expect(message).to.equal('what')
})
})
})