Skip to content
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

test(cursor): ensure that we properly kill cursors #1610

Merged
merged 1 commit into from
Dec 11, 2017
Merged

Conversation

daprahamian
Copy link
Contributor

Added a test to make sure we properly kill cursors

Fixes NODE-1214

Copy link
Member

@mbroadst mbroadst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few comments

const cursor = collection.find({});

// Iterate cursor past first element
return cursor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get keeping the promise chain one level deeper so you can maintain access to the client variable, but it looks like right about here we can keep the chain just at the level of the collection.insert(docs) above - starting to look a little callback hellish :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I take it back, you're using the cursor as well, disregard

let cleanup = () => {};
let caughtError = undefined;

return (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the intent in wrapping all of it in parentheses?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier did that automatically :(


// Kill cursor
return new Promise((resolve, reject) => {
cursor.kill((err, response) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, but can't we make this very short? cursor.kill((err, r) => err ? reject(err) : resolve(r))

.then(() => {
// Confirm that cursorId is non-zero
let id = cursor.cursorState.cursorId;
if (typeof id !== 'number') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you find a case where the id is not a Long? Seems like maybe we can cut this extra code?

Added a test to make sure we properly kill cursors

Fixes NODE-1214
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants