Closed haaohao closed 5 years ago
@haaohao Can you show me the code in test/initial.test.js? It's possible you are tearing down the mongodb server before it has finished operating - otherwise it might be a bug in this library or the tmp library (a dependency of mongomem).
import test from 'ava'; import { MongoDBServer as server } from '../src';
let tmpServer = null;
test.before('setup mongo server', async t => { server.debug = true; tmpServer = await server.start(); });
test('random mongod server is started once', async t => { server.tearDown(); t.pass(); });
2 I hava a another question is for my new project witch use the 'mongomem', it is about the model's schema definition, why i use the same 'domainName', can create it twice in the db, where 'domainName' is defined to 'unique : true', the code is as below, do you have any suggetion?
let mongoose = require('mongoose'); let mem = require('mongomem');
// MongoDBServer.debug = true; let MongoDBServer = mem.MongoDBServer; MongoDBServer.debug = true; let serverHasStarted = MongoDBServer.start();
let getMongooseMock =async()=>{ const mongooseInstance = new mongoose.Mongoose(); await serverHasStarted;
// MongoDBServer.getConnectionString() returns a new UUID4 on every call. // This allows you to get a unique database whilst utilising one in-memory server. let db = await MongoDBServer.getConnectionString(); await mongooseInstance.connect(db, {promiseLibrary: Promise});
'use strict';
require('../../app/modules/domainComponent/domain-model'); let helper = require('./helper'); let test = require('ava'); let rewire = require('rewire');
let mongooseInstance; let mockDomainModule; test.before('before test', async t => { mongooseInstance = await helper.getMongooseMock(); mockDomainModule = mongooseInstance.model('Domain'); });
Hi @haaohao
I know it has been a very long time since I replied to you, so my apologies for that. 😔
Off-topic: I've cleaned up your comment quite a bit - GitHub uses a flavour of Markdown - part of the reason I didn't get around to replying to you was due to the horrible formatting of your message. If you try to use Markdown more effectively you will probably get more replies, as I spent a bit of effort grok'ing your message.
If you are still having this issue - can you check if the MongoDB process is still running in your task manager after that test? I use MacOS myself so it's possible this is due to how Windows works.
For the second question, if you haven't come up with a solution to this can you repost it as clearly as possible as a new issue - it's best to keep things single-threaded so that conversations are easy to manage and reference for anyone coming after you.
Thanks, Connor
Hi. I'm trying to run the test, use 'ava' command, but when call method 'server.tmpFile.removeCallback();', it throw a error as below: [Error: EBUSY: resource busy or locked, unlink 'C:\Users\LIJO9\AppData\Local\Temp\mongomem-268688a5fvz9AA6ck\mongod .lock']
I don't know why the .lock file can not be deleted, do you have any suggestion? Thanks a lot.