无法为茉莉花设置超时

时间:2016-01-07 21:09:46

标签: javascript node.js jasmine

我已尝试this answer中的所有解决方案,但它们都不适用于我。

我正在使用jasmine v2.3.2jasmine-core v2.3.4

当我做这个测试时:

jasmine.DEFAULT_TIMEOUT_INTERVAL= 999999;

describe('tests content controller', function(){
//...

    fit('/content should return 200',function(done){
        request(app)
        .get('/content?type=script')
        .set('Authorization', "bearer " + requestor.token)
        .set('Accept', 'application/json')
        .expect(200)
        .end(function (err, res) {
            if (err) done.fail(err);
            expect(res.statusCode).toBe(200);
            console.log('got here');
            console.log(jasmine.DEFAULT_TIMEOUT_INTERVAL); //prints 30000
            done();
        })
    },999999);

我在控制台上看到请求只花了3000毫秒。我甚至看到了got here日志。

显示超时的日志打印出30000而非999999,就像我期望的那样。

我的测试失败了:

Message:
    Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
  Stack:
    Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
        at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
1 spec, 1 failure
Finished in 33.069 seconds

有一些初始设置导致大部分~30秒延迟。应用程序必须连接到多个数据库并运行beforeAll中的describe函数。

我怎样才能防止茉莉花这样超时呢?

1 个答案:

答案 0 :(得分:7)

尝试在let store = inMemoryStoreCoordinator() let mainContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType) mainContext.persistentStoreCoordinator = store let childContext = NSManagedObjectContext(concurrencyType: .PrivateQueueConcurrencyType) childContext.parentContext = mainContext let q = NSOperationQueue() let group = dispatch_group_create() q.addOperationWithBlock { dispatch_group_enter(group) childContext.performBlock { try! childContext.save() dispatch_group_leave(group) } } dispatch_group_wait(group, DISPATCH_TIME_FOREVER) 中设置jasmine.DEFAULT_TIMEOUT_INTERVAL,因为每个beforeAll块都会重置超时间隔:

it

另外,请记住setTimeout使用32位整数来存储幕后延迟,因此超过此值的整数值将导致溢出。看这篇文章: Infinite jasmine timeout

相关问题