This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(retryable-writes): add mongos support for retryable writes
NODE-1105
- Loading branch information
Showing
3 changed files
with
113 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
var expect = require('chai').expect, | ||
Mongos = require('../../../../lib/topologies/mongos'), | ||
mock = require('../../../mock'), | ||
MongosFixture = require('../common').MongosFixture, | ||
ClientSession = require('../../../../lib/sessions').ClientSession, | ||
ServerSessionPool = require('../../../../lib/sessions').ServerSessionPool; | ||
|
||
const test = new MongosFixture(); | ||
describe('Retryable Writes (Mongos)', function() { | ||
afterEach(() => mock.cleanup()); | ||
beforeEach(() => test.setup({ ismaster: mock.DEFAULT_ISMASTER_36 })); | ||
|
||
it('should add `txnNumber` to write commands where `retryWrites` is true', { | ||
metadata: { requires: { topology: ['single'] } }, | ||
test: function(done) { | ||
const topology = new Mongos(test.servers.map(server => server.address()), { | ||
connectionTimeout: 3000, | ||
socketTimeout: 0, | ||
haInterval: 10000, | ||
localThresholdMS: 500, | ||
size: 1 | ||
}); | ||
|
||
const sessionPool = new ServerSessionPool(topology); | ||
const session = new ClientSession(topology, sessionPool); | ||
|
||
let command = null; | ||
const messageHandler = () => { | ||
return request => { | ||
const doc = request.document; | ||
if (doc.ismaster) { | ||
request.reply(test.defaultFields); | ||
} else if (doc.insert) { | ||
command = doc; | ||
request.reply({ ok: 1 }); | ||
} | ||
}; | ||
}; | ||
|
||
test.servers[0].setMessageHandler(messageHandler('MONGOS1')); | ||
test.servers[1].setMessageHandler(messageHandler('MONGOS2')); | ||
|
||
topology.once('fullsetup', function() { | ||
topology.insert('test.test', [{ a: 1 }], { retryWrites: true, session: session }, function( | ||
err | ||
) { | ||
expect(err).to.not.exist; | ||
expect(command).to.have.property('txnNumber'); | ||
expect(command.txnNumber).to.eql(1); | ||
|
||
topology.destroy(); | ||
done(); | ||
}); | ||
}); | ||
|
||
topology.on('error', done); | ||
topology.connect(); | ||
} | ||
}); | ||
}); |