Conversation
3d7afc1 to
b23030b
Compare
test/test_mongo_middleware.js
Outdated
| @@ -233,7 +241,6 @@ describe('mongo db middleware', function() { | |||
| expect(request.options.testOptions).to.equal('yes'); | |||
| expect(request.query._id).to.equal('test1'); | |||
| next(); | |||
| done(); | |||
| }); | |||
|
|
|||
| var snapshot = {type: 'json0', id: 'test1', v: 1, data: {foo: 'bar'}}; | |||
| @@ -242,6 +249,8 @@ describe('mongo db middleware', function() { | |||
| db.getSnapshot('testcollection', 'test1', null, {testOptions: 'yes'}, function(err, doc) { | |||
| if (err) return done(err); | |||
| expect(doc).to.exist; | |||
| expect(middlewareEntranceCount).to.equal(1); | |||
| done(); | |||
There was a problem hiding this comment.
I’m not certain why this wasn’t visible earlier, but this PR:
introduced a migration to Promises.
When Promise.then is invoked, its callback is scheduled on the microtask queue. As a result, the db.getSnapshot call is deferred and executed after the current synchronous execution completes. This effectively allows it to proceed independently of the initial call stack.
Because of this change in execution order, the middleware can complete before db.getSnapshot has finished executing, which explains the errors we are getting with new mongodb version. Have no idea why it worked before...
1) mongo db middleware
beforeOverwrite
has the expected properties on the request object:
MongoClientClosedError: Operation interrupted because client was closed (and Mocha's done() called multiple times)
at ConnectionPool.closeCheckedOutConnections (node_modules/mongodb7/lib/cmap/connection_pool.js:315:26)
at Server.closeCheckedOutConnections (node_modules/mongodb7/lib/sdam/server.js:125:26)
at Topology.closeCheckedOutConnections (node_modules/mongodb7/lib/sdam/topology.js:242:27)
at MongoClient._close (node_modules/mongodb7/lib/mongo_client.js:342:24)
at MongoClient.close (node_modules/mongodb7/lib/mongo_client.js:325:35)
at /home/runner/work/sharedb-mongo/sharedb-mongo/index.js:32:391
at /home/runner/work/sharedb-mongo/sharedb-mongo/index.js:27:1325
For example here:
Lines 249 to 252 in fdda9b3
There was a problem hiding this comment.
Ugh I do wish we were generally more resilient to tearing down tests while ShareDB is still working. It's so fiddly manually waiting for everything to finish all the time.
b23030b to
fdda9b3
Compare
No description provided.