-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(NODE-3521): update session support checks #3151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a0dfc5b
fix(NODE-3521): remove session support checks
durran 0f8cd6e
fix(NODE-3521): remove extra server selection
durran ef6894d
Revert "fix(NODE-3521): remove extra server selection"
durran b0ca0b6
Revert "fix(NODE-3521): remove session support checks"
durran d3e2109
fix(NODE-3521): properly check session check
durran ddc4d24
test(NODE-3521): add next tests for session
durran dc62173
chore(NODE-3521): find/agg cursor session always there
durran 5839dae
test(NODE-3521): fix cursor server selection tests
durran 68365bf
Update test/unit/cursor/aggregation_cursor.test.js
durran dd594f6
Update test/unit/cursor/aggregation_cursor.test.js
durran 05ad2d2
Update test/unit/cursor/find_cursor.test.js
durran 8ec9ca0
fix(NODE-3521): lint errors
durran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,135 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
durran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const mock = require('../../tools/mongodb-mock/index'); | ||
const { Topology } = require('../../../src/sdam/topology'); | ||
const { Long } = require('bson'); | ||
const { MongoDBNamespace, isHello } = require('../../../src/utils'); | ||
const { AggregationCursor } = require('../../../src/cursor/aggregation_cursor'); | ||
|
||
const test = {}; | ||
describe('Aggregation Cursor', function () { | ||
describe('#next', function () { | ||
afterEach(function () { | ||
mock.cleanup(); | ||
}); | ||
beforeEach(function () { | ||
durran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return mock.createServer().then(mockServer => { | ||
test.server = mockServer; | ||
}); | ||
}); | ||
|
||
context('when there is a data bearing server', function () { | ||
beforeEach(function () { | ||
test.server.setMessageHandler(request => { | ||
const doc = request.document; | ||
if (isHello(doc)) { | ||
request.reply(mock.HELLO); | ||
} else if (doc.aggregate) { | ||
request.reply({ | ||
cursor: { | ||
id: Long.fromNumber(1), | ||
ns: 'test.test', | ||
firstBatch: [{ _id: 1, name: 'test' }] | ||
}, | ||
ok: 1 | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
it('sets the session on the cursor', function (done) { | ||
const topology = new Topology(test.server.hostAddress()); | ||
const cursor = new AggregationCursor( | ||
topology, | ||
MongoDBNamespace.fromString('test.test'), | ||
[], | ||
{} | ||
); | ||
topology.connect(function () { | ||
cursor.next(function () { | ||
expect(cursor.session).to.exist; | ||
topology.close(done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
context('when there is no data bearing server', function () { | ||
beforeEach(function () { | ||
test.server.setMessageHandler(request => { | ||
const doc = request.document; | ||
if (isHello(doc)) { | ||
request.reply({ errmsg: 'network error' }); | ||
} else if (doc.aggregate) { | ||
request.reply({ | ||
cursor: { | ||
id: Long.fromNumber(1), | ||
ns: 'test.test', | ||
firstBatch: [{ _id: 1, name: 'test' }] | ||
}, | ||
ok: 1 | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
it('does not set the session on the cursor', function (done) { | ||
const topology = new Topology(test.server.hostAddress(), { | ||
serverSelectionTimeoutMS: 1000 | ||
}); | ||
const cursor = new AggregationCursor( | ||
topology, | ||
MongoDBNamespace.fromString('test.test'), | ||
[], | ||
{} | ||
); | ||
topology.connect(function () { | ||
cursor.next(function () { | ||
expect(cursor.session).to.not.exist; | ||
topology.close(done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
context('when a data bearing server becomes available', function () { | ||
beforeEach(function () { | ||
let helloCalls = 0; | ||
test.server.setMessageHandler(request => { | ||
const doc = request.document; | ||
if (isHello(doc)) { | ||
request.reply(helloCalls > 0 ? { errmsg: 'network error' } : mock.HELLO); | ||
dariakp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else if (doc.aggregate) { | ||
request.reply({ | ||
cursor: { | ||
id: Long.fromNumber(1), | ||
ns: 'test.test', | ||
firstBatch: [{ _id: 1, name: 'test' }] | ||
}, | ||
ok: 1 | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
it('sets the session on the cursor', function (done) { | ||
const topology = new Topology(test.server.hostAddress(), { | ||
serverSelectionTimeoutMS: 1000 | ||
}); | ||
const cursor = new AggregationCursor( | ||
topology, | ||
MongoDBNamespace.fromString('test.test'), | ||
[], | ||
{} | ||
); | ||
topology.connect(function () { | ||
cursor.next(function () { | ||
expect(cursor.session).to.exist; | ||
topology.close(done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.