-
Notifications
You must be signed in to change notification settings - Fork 1.8k
refactor(NODE-4633): executeOperation to use maybeCallback #3421
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
Conversation
f2c0ad2
to
e3d3a1b
Compare
src/operations/execute_operation.ts
Outdated
} | ||
|
||
const assertTopology = async (client: MongoClient) => { | ||
const { topology } = client; |
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.
related - function names should describe what the function does and assertTopology
isn't descriptive of what this function does. This function:
- connects the client
- asserts the topology is connected
- returns the topology
At the least, can we use a better name? connectClientAndAssertTopology
? That's a mouthful, so I'd probably do the following (just organizational preference)
- rename the function
connectIfNotConnected
or something like this and make it return void so that the function - move the
if (topology == null)
check to a regular if check outside the function
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 renamed and improved the control flow here, keeping the assertion in here though seems like an acceptable approach because it's really unreachable to have a nullish topology after connect.
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 think we should move away from the naming convention maybe<something>
because it's not particularly descriptive and after v5, we won't have need for maybeCallback
anymore.
maybe even just autoConnect
would be better but we could also just move this code back inline - it's only used in once place and isn't terribly complicated so I see no problem with having it inline
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.
Inlined
src/operations/execute_operation.ts
Outdated
} | ||
client.s.options[Symbol.for('@@mdb.skipPingOnConnect')] = true; | ||
await client.connect(); | ||
delete client.s.options[Symbol.for('@@mdb.skipPingOnConnect')]; |
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 think we need to put this in a finally
so that we remove this regardless of whether or not connect fails (that's also the old behavior).
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.
done!
src/operations/execute_operation.ts
Outdated
} | ||
|
||
const assertTopology = async (client: MongoClient) => { | ||
const { topology } = client; |
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 think we should move away from the naming convention maybe<something>
because it's not particularly descriptive and after v5, we won't have need for maybeCallback
anymore.
maybe even just autoConnect
would be better but we could also just move this code back inline - it's only used in once place and isn't terribly complicated so I see no problem with having it inline
218eb8f
to
0148f5e
Compare
Description
NODE-4633
What is changing?
package-lock.json
andpackage.json
src/bulk/common.ts
src/collection.ts
andsrc/operations/rename.ts
andsrc/operations/stats.ts
andsrc/operations/delete.ts
src/operations/command.ts
src/operations/execute_operation.ts
executeOperation
nearly empty to just call a new TBD named async function was intentional to avoid causing renames across tons of files, but we can do a follow up if we want to do that.Perhaps we don't need to run serverSelection twice?(session support check)src/operations/operation.ts
src/sdam/server.ts
noResponse
was causing endSessions to ALWAYS throw, which we squash, but it prevented executeOperation from retrying. Fixed.src/sdam/topology.ts
test/integration/crud/bulk.test.ts
insertMany
here async/await makes this always fail now. fixed!test/integration/crud/maxTimeMS.test.ts
insertMany
here async/await makes this always fail now. fixed!test/integration/server-selection/operation_count.test.ts
test/integration/sessions/sessions.spec.prose.test.ts
andtest/integration/sessions/sessions.test.ts
What is the motivation for this change?
async await is easier to reason about, error wise, ordering wise, and forces consistent execution.
Double check the following
npm run check:lint
script<type>(NODE-xxxx)<!>: <description>