chai-http 和 async.each,抛出 "Timeout of 2000ms exceeded..."
chai-http and async.each, throwing "Timeout of 2000ms exceeded..."
我有一个简单的 chai-http 测试,我尝试使用 async.each 测试几个 URL,但是当请求超过 2 秒时,我得到了错误。
it("it should GET the required images", (done) => {
async.each(get_data, function(item, cb){
chai
.request(item.server_url.S)
.get('/'+ item.endpoint.S + '?' + item.incoming.S)
.end(function(err, res) {
if(err) console.error(err);
expect(err).to.be.null;
expect(res).to.have.status(200);
cb();
});
}, function(err){
if(err) console.log(err);
done();
});
});
我正在调用 "done",我认为是正确的,但我一直收到错误消息,我做错了什么?即使没有异步,也显示错误,只是简单的 chai 请求,只有一个请求...所以很确定不是异步问题,但我使用 chaiHttp 不好。
我也试过用"then/catch"代替"end",但结果是一样的。
我有一个类似的问题,在相同的测试脚本中但使用数据库,如果查询花费超过 2 秒,它会中断...同样的错误,也使用 "done":
before((done) => {
// runs before all tests in this block
const params = {
TableName: "mytable"
};
mydb.scan(params, (err, records) => {
if(err) console.log(err);
for(let i = 0; i < records.Items.length; i++){
//...some ifs, nothing async
}
done();
});
});
如果您的测试时间超过 2000 毫秒,请考虑延长测试超时时间可能会解决您的问题
it("it should GET the required images", (done) => {
this.timeout(5000);
//...
在 this.timeout()
方法中给出完成测试所需的时间
it('it should solve the timeout issue of a test in test level', function(done) {
this.timeout(10000);
done();
});
我有一个简单的 chai-http 测试,我尝试使用 async.each 测试几个 URL,但是当请求超过 2 秒时,我得到了错误。
it("it should GET the required images", (done) => {
async.each(get_data, function(item, cb){
chai
.request(item.server_url.S)
.get('/'+ item.endpoint.S + '?' + item.incoming.S)
.end(function(err, res) {
if(err) console.error(err);
expect(err).to.be.null;
expect(res).to.have.status(200);
cb();
});
}, function(err){
if(err) console.log(err);
done();
});
});
我正在调用 "done",我认为是正确的,但我一直收到错误消息,我做错了什么?即使没有异步,也显示错误,只是简单的 chai 请求,只有一个请求...所以很确定不是异步问题,但我使用 chaiHttp 不好。
我也试过用"then/catch"代替"end",但结果是一样的。
我有一个类似的问题,在相同的测试脚本中但使用数据库,如果查询花费超过 2 秒,它会中断...同样的错误,也使用 "done":
before((done) => {
// runs before all tests in this block
const params = {
TableName: "mytable"
};
mydb.scan(params, (err, records) => {
if(err) console.log(err);
for(let i = 0; i < records.Items.length; i++){
//...some ifs, nothing async
}
done();
});
});
如果您的测试时间超过 2000 毫秒,请考虑延长测试超时时间可能会解决您的问题
it("it should GET the required images", (done) => {
this.timeout(5000);
//...
在 this.timeout()
方法中给出完成测试所需的时间
it('it should solve the timeout issue of a test in test level', function(done) {
this.timeout(10000);
done();
});