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

refactor(ChangeStream): use maybePromise for close, improve tests #2343

Merged
merged 29 commits into from May 6, 2020

Conversation

emadum
Copy link
Contributor

@emadum emadum commented May 3, 2020

Description

NODE-2598

What changed?

  • Refactor close to use maybePromise helper
  • Ensure explicitly closed change streams don't process further changes
  • Fix broken mid-close tests by delaying the final write
  • Add waitForStarted helper to tests where appropriate to reduce flakiness

Are there any files to ignore?

@emadum emadum changed the title refactor: use maybePromise for ChangeStream.close refactor(ChangeStream): use maybePromise for close May 3, 2020
lib/change_stream.js Outdated Show resolved Hide resolved
lib/change_stream.js Outdated Show resolved Hide resolved
lib/change_stream.js Outdated Show resolved Hide resolved
lib/change_stream.js Outdated Show resolved Hide resolved
test/functional/change_stream.test.js Outdated Show resolved Hide resolved
lib/change_stream.js Outdated Show resolved Hide resolved
lib/change_stream.js Show resolved Hide resolved
lib/change_stream.js Outdated Show resolved Hide resolved
@emadum emadum requested a review from mbroadst May 4, 2020 12:09
@emadum emadum requested review from reggi and mbroadst and removed request for reggi and mbroadst May 4, 2020 12:32
@@ -2609,34 +2619,24 @@ describe('Change Streams', function() {
describe('tryNext', function() {
Copy link
Contributor Author

@emadum emadum May 5, 2020

Choose a reason for hiding this comment

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

I oddly started getting an error in the tryNext tests:

MongoError: cannot open $changeStream for non-existent database: test

Possibly related to deleting my test_data and switching mongo versions, then running that describe block with .only.

I thought it would be more robust to use a specifically named database and drop it after each test, to ensure weird behavior doesn't carry over between tests.

To that purpose I created the withTempDb helper that wraps withClient to create and drop the specified database. This refactor made above error go away.

@emadum emadum changed the title refactor(ChangeStream): use maybePromise for close refactor(ChangeStream): use maybePromise for close, improve tests May 5, 2020
@emadum emadum requested review from mbroadst and reggi May 5, 2020 15:19
@@ -37,7 +38,11 @@ function triggerResumableError(changeStream, onCursorClosed) {
* @param {function} callback
*/
function waitForStarted(changeStream, callback) {
const timeout = setTimeout(() => {
throw new Error('Change stream never started');
}, 2000);
Copy link
Contributor Author

@emadum emadum May 5, 2020

Choose a reason for hiding this comment

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

This shouldn't do anything. I'm just concerned some tests are timing out after 60s because for some reason waitForStarted never triggers. If that's the case, this will at least fail a lot sooner, and more importantly we'll know for sure whether this is the root cause of test flakiness.

// if the arity is 1 then this a callback for `more`
if (arguments.length === 1) {
if (err instanceof Error) {
Copy link
Member

Choose a reason for hiding this comment

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

in what case is an error returned here? When I look at where more is emitted in change_stream.js, the errors are always handled. This would seem to imply the getMore callback was called with err, err or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops I think I should remove this now, I was just trying to track down an issue but it's no longer necessary.

test/functional/change_stream.test.js Outdated Show resolved Hide resolved
test/functional/shared.js Show resolved Hide resolved
Copy link
Contributor

@reggi reggi left a comment

Choose a reason for hiding this comment

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

LGTM

@emadum emadum merged commit 1e3b4c9 into 3.5 May 6, 2020
@emadum emadum deleted the change-stream-close-maybepromise branch May 6, 2020 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants