Mockgoose测试失败导致MongoError:拓扑已破坏 [英] Tests failing with Mockgoose cause MongoError: topology was destroyed

查看:87
本文介绍了Mockgoose测试失败导致MongoError:拓扑已破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mockgoose/Mongoose(使用Mocha/Chai作为测试套件)进行一系列测试.

I'm running a series of tests with Mockgoose/Mongoose (using Mocha/Chai as the test suite).

如果我的一项测试碰巧失败(即由于.should.be.deep.equal()失败),则所有后续测试均失败,并显示消息MongoError: topology was destroyed

If one of my tests happens to fail (ie. due to a failed .should.be.deep.equal()), all of the subsequent tests fail with the message MongoError: topology was destroyed

以下是一些相关的摘要:

Here's some relevant snippets:

mockgoose(mongoose);

before(function(done) {
    mongoose.connect('mongodb://fake.test/TestingDB', function(err) {
        done(err);
    }); 
});

afterEach(function(done) {
    mockgoose.reset();
    done();
});

// Test Cases
describe('Testing the functions that deal with users and locations:', function() {
    // Test Setup
    var req

    beforeEach(function(done) {
        req = {};
        mockgoose.reset();
        done();
    });

    beforeEach(function(done) {
        sensors.create(testData.deviceData, function(err, model) {
            if (err) {console.log(err)};
            done();
        });
    });
    //tests start here

这是我得到的错误的示例:

And here's an example of the errors I get:

1) Testing functions that use the Furnace collections Testing furnaceOn function Should produce some output:
   Uncaught TypeError: Cannot read property 'should' of undefined
    at C:\Users\Zachary Jacobi\Development\webapp\tests\unit\dbFunctionMockTests.js:417:11
    at Query.<anonymous> (C:\Users\Zachary Jacobi\Development\webapp\lib\dbFunctions.js:499:3)
    at C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\kareem\index.js:177:19
    at C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\kareem\index.js:109:16

2) Testing functions that use the Furnace collections "before each" hook for "Should produce the same results as the mock up from testData":
   MongoError: topology was destroyed
    at Server.insert (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:951:49)
    at Server.insert (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\mongodb\lib\server.js:324:17)
    at executeBatch (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\mongodb\lib\bulk\unordered.js:436:23)
    at executeBatches (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\mongodb\lib\bulk\unordered.js:457:5)
    at UnorderedBulkOperation.execute (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\mongodb\lib\bulk\unordered.js:515:44)
    at bulkWrite (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\mongodb\lib\collection.js:582:8)
    at Collection.insertMany (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\mongodb\lib\collection.js:477:44)
    at Collection.insert (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\mongodb\lib\collection.js:753:15)
    at NativeCollection.(anonymous function) [as insert] (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:136:28)
    at model.Model.$__handleSave (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\lib\model.js:130:21)
    at model.Model.$__save (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\lib\model.js:189:9)
    at model.Model.save (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\lib\model.js:282:17)
    at model._done (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\hooks-fixed\hooks.js:101:24)
    at _next (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\hooks-fixed\hooks.js:64:28)
    at fnWrapper (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\hooks-fixed\hooks.js:186:18)
    at model.Object.defineProperty.value.fn (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\lib\schema.js:250:9)
    at _next (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\hooks-fixed\hooks.js:62:30)
    at fnWrapper (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\node_modules\hooks-fixed\hooks.js:186:18)
    at C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\lib\schema.js:233:13
    at complete (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\lib\document.js:1131:5)
    at C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\lib\document.js:1157:20
    at Mixed.SchemaType.doValidate (C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\lib\schematype.js:654:22)
    at C:\Users\Zachary Jacobi\Development\webapp\node_modules\mongoose\lib\document.js:1153:9

有人知道是什么原因造成的,我该怎么做才能解决?当一个失败的测试导致所有后续测试都失败时,很难确定实际上有多少测试失败.

Does anyone know what is causing this and what I can do to fix it? It's making it difficult to determine how many tests are actually failing when one failed test causes all subsequent ones to fail.

推荐答案

更新到Mockgoose 5.3.0和Mongoose 4.2.9解决了此问题.

Updating to Mockgoose 5.3.0 and Mongoose 4.2.9 solves this problem.

我对原因的最佳猜测是在测试失败的同时运行的beforeEach mockgoose.reset()导致重置失败并且模拟的数据库陷入不良状态.

My best guess as to the cause was the beforeEach mockgoose.reset() running at the same time as tests were failing, causing the reset to fail and the mocked database to get stuck in a bad state.

这篇关于Mockgoose测试失败导致MongoError:拓扑已破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆