-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(NODE-3442): AsyncIterator has incorrect return type #2916
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
const { expect } = require('chai'); | ||
const Sinon = require('sinon'); | ||
const { Promise: BluebirdPromise } = require('bluebird'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I brought in bluebird because our current test just did There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SGTM, I think it's a good idea to test bluebird anyway, since it's the most likely alternative promise library people would use. |
||
|
||
describe('Cursor Async Iterator Tests', function () { | ||
context('default promise library', function () { | ||
|
@@ -87,11 +88,12 @@ describe('Cursor Async Iterator Tests', function () { | |
context('custom promise library', () => { | ||
let client, collection, promiseSpy; | ||
before(async function () { | ||
class CustomPromise extends Promise {} | ||
promiseSpy = Sinon.spy(CustomPromise.prototype, 'then'); | ||
client = this.configuration.newClient({}, { promiseLibrary: CustomPromise }); | ||
promiseSpy = Sinon.spy(BluebirdPromise.prototype, 'then'); | ||
client = this.configuration.newClient({}, { promiseLibrary: BluebirdPromise }); | ||
|
||
await client.connect(); | ||
const connectPromise = client.connect(); | ||
expect(connectPromise).to.be.instanceOf(BluebirdPromise); | ||
await connectPromise; | ||
const docs = Array.from({ length: 1 }).map((_, index) => ({ foo: index, bar: 1 })); | ||
|
||
collection = client.db(this.configuration.db).collection('async_cursor_tests'); | ||
|
@@ -121,5 +123,19 @@ describe('Cursor Async Iterator Tests', function () { | |
expect(countBeforeIteration).to.not.equal(promiseSpy.callCount); | ||
expect(promiseSpy.called).to.equal(true); | ||
}); | ||
|
||
it('should properly use custom promise manual iteration', async function () { | ||
const cursor = collection.find(); | ||
|
||
const iterator = cursor[Symbol.asyncIterator](); | ||
let isDone; | ||
do { | ||
const promiseFromIterator = iterator.next(); | ||
expect(promiseFromIterator).to.be.instanceOf(BluebirdPromise); | ||
const { done, value } = await promiseFromIterator; | ||
if (done) expect(value).to.be.a('undefined'); | ||
isDone = done; | ||
} while (!isDone); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,9 +28,8 @@ describe('executeLegacyOperation', function () { | |
expect(caughtError).to.equal(expectedError); | ||
}); | ||
|
||
it('should reject promise with errors on throw errors, and rethrow error', function (done) { | ||
it('should reject promise with errors on throw errors, and rethrow error', function () { | ||
const expectedError = new Error('THIS IS AN ERROR'); | ||
let callbackError; | ||
|
||
const topology = { | ||
logicalSessionTimeoutMinutes: null | ||
|
@@ -39,18 +38,10 @@ describe('executeLegacyOperation', function () { | |
throw expectedError; | ||
}; | ||
|
||
const callback = err => (callbackError = err); | ||
const options = { skipSessions: true }; | ||
|
||
executeLegacyOperation(topology, operation, [{}, null], options).then(null, callback); | ||
|
||
setTimeout(() => { | ||
try { | ||
expect(callbackError).to.equal(expectedError); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
return executeLegacyOperation(topology, operation, [{}, null], options).then(null, err => { | ||
expect(err).to.equal(expectedError); | ||
Comment on lines
+43
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was failing on the first commit I pushed, might have been flaky and I coulda tried a rerun but changing this to not rely on a setTimeout seems like a quick cleanup win. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleaning up flaky tests is always good in my book! 👍 |
||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can totally ternary this, thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ternary was nice and succinct, do you prefer it this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spread it out for debugging but just now thought I can clean it up, changed it, looks v neat now :)