-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat(NODE-6403): Add CSOT support to client bulk write #4261
Changes from all commits
1b0d628
d22db74
69d99c2
473b8d6
5f34f43
b92ddc1
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 |
---|---|---|
|
@@ -21,7 +21,8 @@ import { | |
promiseWithResolvers, | ||
squashError | ||
} from '../../mongodb'; | ||
import { type FailPoint } from '../../tools/utils'; | ||
import { type FailPoint, makeMultiBatchWrite } from '../../tools/utils'; | ||
import { filterForCommands } from '../shared'; | ||
|
||
// TODO(NODE-5824): Implement CSOT prose tests | ||
describe('CSOT spec prose tests', function () { | ||
|
@@ -1183,9 +1184,9 @@ describe('CSOT spec prose tests', function () { | |
}); | ||
}); | ||
|
||
describe.skip( | ||
describe( | ||
'11. Multi-batch bulkWrites', | ||
{ requires: { mongodb: '>=8.0', serverless: 'forbid' } }, | ||
{ requires: { mongodb: '>=8.0', serverless: 'forbid', topology: 'single' } }, | ||
function () { | ||
/** | ||
* ### 11. Multi-batch bulkWrites | ||
|
@@ -1245,9 +1246,6 @@ describe('CSOT spec prose tests', function () { | |
} | ||
}; | ||
|
||
let maxBsonObjectSize: number; | ||
let maxMessageSizeBytes: number; | ||
|
||
beforeEach(async function () { | ||
await internalClient | ||
.db('db') | ||
|
@@ -1256,29 +1254,20 @@ describe('CSOT spec prose tests', function () { | |
.catch(() => null); | ||
await internalClient.db('admin').command(failpoint); | ||
|
||
const hello = await internalClient.db('admin').command({ hello: 1 }); | ||
maxBsonObjectSize = hello.maxBsonObjectSize; | ||
maxMessageSizeBytes = hello.maxMessageSizeBytes; | ||
|
||
client = this.configuration.newClient({ timeoutMS: 2000, monitorCommands: true }); | ||
}); | ||
|
||
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 prose test incorporates changes from mongodb/specifications#1672. 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.
where are we providing that value? 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. ah in the |
||
it.skip('performs two bulkWrites which fail to complete before 2000 ms', async function () { | ||
it('performs two bulkWrites which fail to complete before 2000 ms', async function () { | ||
const writes = []; | ||
client.on('commandStarted', ev => writes.push(ev)); | ||
client.on('commandStarted', filterForCommands('bulkWrite', writes)); | ||
nbbeeken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const length = maxMessageSizeBytes / maxBsonObjectSize + 1; | ||
const models = Array.from({ length }, () => ({ | ||
namespace: 'db.coll', | ||
name: 'insertOne' as const, | ||
document: { a: 'b'.repeat(maxBsonObjectSize - 500) } | ||
})); | ||
const models = await makeMultiBatchWrite(this.configuration); | ||
|
||
const error = await client.bulkWrite(models).catch(error => error); | ||
|
||
expect(error, error.stack).to.be.instanceOf(MongoOperationTimeoutError); | ||
expect(writes.map(ev => ev.commandName)).to.deep.equal(['bulkWrite', 'bulkWrite']); | ||
}).skipReason = 'TODO(NODE-6403): client.bulkWrite is implemented in a follow up'; | ||
expect(writes).to.have.lengthOf(2); | ||
}); | ||
} | ||
); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -279,12 +279,16 @@ describe('CSOT driver tests', metadata, () => { | |
.stub(Connection.prototype, 'readMany') | ||
.callsFake(async function* (...args) { | ||
const realIterator = readManyStub.wrappedMethod.call(this, ...args); | ||
const cmd = commandSpy.lastCall.args.at(1); | ||
if ('giveMeWriteErrors' in cmd) { | ||
await realIterator.next().catch(() => null); // dismiss response | ||
yield { parse: () => writeErrorsReply }; | ||
} else { | ||
yield (await realIterator.next()).value; | ||
try { | ||
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. With the change on onData, we need to be sure we call |
||
const cmd = commandSpy.lastCall.args.at(1); | ||
if ('giveMeWriteErrors' in cmd) { | ||
await realIterator.next().catch(() => null); // dismiss response | ||
yield { parse: () => writeErrorsReply }; | ||
} else { | ||
yield (await realIterator.next()).value; | ||
} | ||
} finally { | ||
realIterator.return(); | ||
} | ||
}); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { Collection, type Db, type MongoClient } from '../../mongodb'; | ||
import { Collection, type Db, type MongoClient, ObjectId } from '../../mongodb'; | ||
|
||
describe('Collection Management and Db Management', function () { | ||
let client: MongoClient; | ||
|
@@ -16,7 +16,7 @@ describe('Collection Management and Db Management', function () { | |
}); | ||
|
||
it('returns a collection object after calling createCollection', async function () { | ||
const collection = await db.createCollection('collection'); | ||
const collection = await db.createCollection(new ObjectId().toHexString()); | ||
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 ran the test suite twice and this failed the second time - I can remove this if we want but this guarantees we never create the same collection twice. 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. These tests should be more responsible about their side effects, like: |
||
expect(collection).to.be.instanceOf(Collection); | ||
}); | ||
|
||
|
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.
This was the cause of the hanging test suites - some CSOT tests spawn huge timeouts that we never clean up.