-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…3914) Co-authored-by: Durran Jordan <durran@gmail.com>
- Loading branch information
1 parent
2ffcc73
commit 7ace88d
Showing
4 changed files
with
59 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
test/integration/retryable-writes/non-server-retryable_writes.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { expect } from 'chai'; | ||
import * as sinon from 'sinon'; | ||
|
||
import { | ||
type Collection, | ||
type MongoClient, | ||
MongoWriteConcernError, | ||
PoolClearedError, | ||
Server | ||
} from '../../mongodb'; | ||
|
||
describe('Non Server Retryable Writes', function () { | ||
let client: MongoClient; | ||
let collection: Collection<{ _id: 1 }>; | ||
|
||
beforeEach(async function () { | ||
client = this.configuration.newClient({ monitorCommands: true, retryWrites: true }); | ||
await client | ||
.db() | ||
.collection('retryReturnsOriginal') | ||
.drop() | ||
.catch(() => null); | ||
collection = client.db().collection('retryReturnsOriginal'); | ||
}); | ||
|
||
afterEach(async function () { | ||
sinon.restore(); | ||
await client.close(); | ||
}); | ||
|
||
it( | ||
'returns the original error with a PoolRequstedRetry label after encountering a WriteConcernError', | ||
{ requires: { topology: 'replicaset', mongodb: '>=4.2.9' } }, | ||
async () => { | ||
const serverCommandStub = sinon.stub(Server.prototype, 'command'); | ||
serverCommandStub.onCall(0).yieldsRight(new PoolClearedError('error')); | ||
serverCommandStub | ||
.onCall(1) | ||
.yieldsRight( | ||
new MongoWriteConcernError({ errorLabels: ['NoWritesPerformed'], errorCode: 10107 }, {}) | ||
); | ||
|
||
const insertResult = await collection.insertOne({ _id: 1 }).catch(error => error); | ||
sinon.restore(); | ||
|
||
expect(insertResult.errorLabels).to.be.deep.equal(['PoolRequstedRetry']); | ||
} | ||
); | ||
}); |