-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set to empty string if error is null or undefined
- Loading branch information
1 parent
d50088e
commit 661c1e1
Showing
7 changed files
with
306 additions
and
305 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
module.exports = { | ||
production:{ | ||
gearman:{ | ||
servers:[{"host":"127.0.0.1"}] | ||
production:{ | ||
gearman:{ | ||
servers:[{'host':'127.0.0.1'}] | ||
}, | ||
retry:3, | ||
mongodb:'mongodb://10.252.25.62:27017/gearman' | ||
}, | ||
retry:3, | ||
mongodb:"mongodb://10.252.25.62:27017/gearman" | ||
}, | ||
development:{ | ||
gearman:{ | ||
servers:[{"host":"192.168.98.116"}] | ||
}, | ||
retry:3, | ||
mongodb:"mongodb://192.168.98.116:27017/gearman" | ||
} | ||
} | ||
development:{ | ||
gearman:{ | ||
servers:[{'host':'192.168.98.116'}] | ||
}, | ||
retry:3, | ||
mongodb:'mongodb://192.168.98.116:27017/gearman' | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,104 @@ | ||
|
||
"use strict" | ||
'use strict'; | ||
|
||
const path = require('path') | ||
const path = require('path'); | ||
process.chdir(path.join(process.cwd(),'tests')); | ||
|
||
const should = require('should') | ||
const sinon = require('sinon') | ||
require('should-sinon') | ||
const App = require('./lib/client.js') | ||
const bottleneck = require('mof-bottleneck') | ||
const request = require('mof-request') | ||
const cheerio = require('mof-cheerio') | ||
const iconv = require('mof-iconv') | ||
const co = require('co') | ||
const should = require('should'); | ||
const sinon = require('sinon'); | ||
require('should-sinon'); | ||
const App = require('./lib/client.js'); | ||
const bottleneck = require('mof-bottleneck'); | ||
const request = require('mof-request'); | ||
const cheerio = require('mof-cheerio'); | ||
const iconv = require('mof-iconv'); | ||
const co = require('co'); | ||
|
||
describe('Test worker in floodesh', ()=>{ | ||
const Worker = require('../worker'); | ||
let worker; | ||
beforeEach(() => { | ||
|
||
}); | ||
|
||
it('should load config file', ()=>{ | ||
worker = new Worker(); | ||
should.exist(worker.config.logBaseDir); | ||
should.exist(worker.config.retry); | ||
should.exist(worker.config.gearman); | ||
should.exist(worker.config.logger); | ||
should.exist(worker.config.mongodb); | ||
worker.exit(); | ||
}); | ||
|
||
it("should new a worker", ()=> { | ||
worker = new Worker(); | ||
worker.should.be.an.instanceOf(Worker); | ||
}); | ||
|
||
it('should retry when time out', done=>{ | ||
worker = new Worker(); | ||
let getError = ()=>{ | ||
let e = new Error(); | ||
e.code = 'ETIMEDOUT'; | ||
return e; | ||
}; | ||
|
||
worker.use((ctx, next)=>{ | ||
should.exist(ctx.opt); | ||
console.log("middleware: %j", ctx.opt); | ||
should.exist(ctx.opt.retries); | ||
|
||
return next(); | ||
const Worker = require('../worker'); | ||
let worker; | ||
beforeEach(() => { | ||
|
||
}); | ||
worker.use(co.wrap(request())); | ||
// worker.use((ctx, next)=>{ | ||
// let e = getError(); | ||
// throw e; | ||
// return next(); | ||
// }); | ||
|
||
worker.on('complete', ctx=> { | ||
process.nextTick(()=>{ | ||
should.exist(ctx); | ||
|
||
it('should load config file', ()=>{ | ||
worker = new Worker(); | ||
should.exist(worker.config.logBaseDir); | ||
should.exist(worker.config.retry); | ||
should.exist(worker.config.gearman); | ||
should.exist(worker.config.logger); | ||
should.exist(worker.config.mongodb); | ||
worker.exit(); | ||
done(); | ||
}); | ||
}); | ||
|
||
let job = {workComplete:function(){},reportException:function(){}}; | ||
let ctx = {opt:{uri:"http://www.baidu.com"}, app:{},request:{}, response:{},resourceList:{},job:job}; | ||
worker.jobs.add(job); | ||
worker.emit("error",getError(),ctx); | ||
}); | ||
|
||
it('should emit complete even if one of middlewares do not call next', done=>{ | ||
worker = new Worker(); | ||
let number=[]; | ||
worker.use((ctx, next)=>{ | ||
number.push(2); | ||
return next(); | ||
it('should new a worker', ()=> { | ||
worker = new Worker(); | ||
worker.should.be.an.instanceOf(Worker); | ||
}); | ||
|
||
worker.use((ctx, next)=>{ | ||
should.exist(ctx); | ||
should.exist(next); | ||
it('should retry when time out', done=>{ | ||
worker = new Worker(); | ||
let getError = ()=>{ | ||
let e = new Error(); | ||
e.code = 'ETIMEDOUT'; | ||
return e; | ||
}; | ||
|
||
worker.use((ctx, next)=>{ | ||
should.exist(ctx.opt); | ||
console.log('middleware: %j', ctx.opt); | ||
should.exist(ctx.opt.retries); | ||
|
||
return next(); | ||
}); | ||
worker.use(co.wrap(request())); | ||
|
||
worker.on('complete', ctx=> { | ||
process.nextTick(()=>{ | ||
should.exist(ctx); | ||
worker.exit(); | ||
done(); | ||
}); | ||
}); | ||
|
||
let job = {workComplete:function(){},reportError:function(){},reportWarning:function(){}}; | ||
let ctx = {opt:{uri:'http://www.baidu.com'}, app:{},request:{}, response:{},resourceList:{},job:job}; | ||
worker.jobs.add(job); | ||
worker.emit('error',getError(),ctx); | ||
}); | ||
|
||
worker.use((ctx, next)=>{ | ||
number.push(3); | ||
return next(); | ||
}); | ||
|
||
worker.on('complete',ctx=>{ | ||
number.should.eql([1,2]); | ||
process.nextTick(()=>{ | ||
should.exist(ctx); | ||
worker.exit(); | ||
done(); | ||
}); | ||
}); | ||
it('should emit complete even if one of middlewares do not call next', done=>{ | ||
worker = new Worker(); | ||
let number=[]; | ||
worker.use((ctx, next)=>{ | ||
number.push(2); | ||
return next(); | ||
}); | ||
|
||
worker.use((ctx, next)=>{ | ||
should.exist(ctx); | ||
should.exist(next); | ||
}); | ||
|
||
worker.use((ctx, next)=>{ | ||
number.push(3); | ||
return next(); | ||
}); | ||
|
||
worker.on('complete',ctx=>{ | ||
number.should.eql([1,2]); | ||
process.nextTick(()=>{ | ||
should.exist(ctx); | ||
worker.exit(); | ||
done(); | ||
}); | ||
}); | ||
|
||
let ctx = worker.enqueue({uri:"http://www.baidu.com"}); | ||
number.push(1); | ||
let ctx = worker.enqueue({uri:'http://www.baidu.com'}); | ||
number.push(1); | ||
|
||
ctx.func='home'; | ||
ctx.job = {workComplete:function(){}}; | ||
worker.jobs.add(ctx.job); | ||
}); | ||
ctx.func='home'; | ||
ctx.job = {workComplete:function(){}}; | ||
worker.jobs.add(ctx.job); | ||
}); | ||
}); |
Oops, something went wrong.