Skip to content

Commit 091e989

Browse files
committed
update to latest, small clean-ups
1 parent 4100da7 commit 091e989

9 files changed

Lines changed: 23 additions & 13 deletions

File tree

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export {
8787
MongoWriteConcernError,
8888
WriteConcernErrorResult
8989
} from './error';
90-
export { TokenBucket } from './token_bucket';
9190
export {
9291
AbstractCursor,
9392
// Actual driver classes exported

src/operations/execute_operation.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,6 @@ async function executeOperationWithRetries<
251251
: 2
252252
: 1;
253253

254-
const shouldRetry =
255-
(operation.hasAspect(Aspect.READ_OPERATION) && topology.s.options.retryReads) ||
256-
((operation.hasAspect(Aspect.WRITE_OPERATION) || operation instanceof RunCommandOperation) &&
257-
topology.s.options.retryWrites);
258-
259254
let error: MongoError | null = null;
260255

261256
for (let attempt = 0; attempt < maxAttempts; attempt++) {

src/operations/operation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export abstract class AbstractOperation<TResult = any> {
6666
/** Specifies the time an operation will run until it throws a timeout error. */
6767
timeoutMS?: number;
6868

69-
/** @internal Used by commitTransaction to share the retry budget across two executeOperatin calls. */
69+
/** @internal Used by commitTransaction to share the retry budget across two executeOperation calls. */
7070
maxAttempts?: number;
7171

7272
/** @internal Tracks how many attempts were made in the last executeOperation call. */

src/sdam/topology.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { type Abortable, TypedEventEmitter } from '../mongo_types';
3535
import { ReadPreference, type ReadPreferenceLike } from '../read_preference';
3636
import type { ClientSession } from '../sessions';
3737
import { Timeout, TimeoutContext, TimeoutError } from '../timeout';
38-
import { TokenBucket } from '../token_bucket';
38+
import { INITIAL_TOKEN_BUCKET_SIZE, TokenBucket } from '../token_bucket';
3939
import type { Transaction } from '../transactions';
4040
import {
4141
addAbortListener,
@@ -213,7 +213,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
213213
hello?: Document;
214214
_type?: string;
215215

216-
tokenBucket = new TokenBucket(1000);
216+
tokenBucket = new TokenBucket(INITIAL_TOKEN_BUCKET_SIZE);
217217

218218
client!: MongoClient;
219219

src/sessions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,9 +1254,9 @@ export function updateSessionFromResponse(session: ClientSession, document: Mong
12541254
session.transaction.transition(TxnState.TRANSACTION_IN_PROGRESS);
12551255
} else {
12561256
const error = new MongoServerError(document.toObject());
1257-
const isBackpressureError = error.hasErrorLabel(MongoErrorLabel.RetryableError);
1257+
const isRetryableError = error.hasErrorLabel(MongoErrorLabel.RetryableError);
12581258

1259-
if (!isBackpressureError) {
1259+
if (!isRetryableError) {
12601260
session.transaction.transition(TxnState.TRANSACTION_IN_PROGRESS);
12611261
}
12621262
}

sync.sh

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22

3-
cp ~/dev/specifications/source/client-backpressure/tests/* ~/dev/node-mongodb-native/test/spec/client-backpressure
4-
cp ~/dev/specifications/source/transactions/tests/unified/backpressure* ~/dev/node-mongodb-native/test/spec/transactions/unified/
3+
cp ~/code/specifications/source/client-backpressure/tests/* ~/code/node-mongodb-native/test/spec/client-backpressure
4+
cp ~/code/specifications/source/transactions/tests/unified/backpressure* ~/code/node-mongodb-native/test/spec/transactions/unified/

test/integration/client-backpressure/client-backpressure.prose.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('Client Backpressure (Prose)', function () {
1616
});
1717

1818
afterEach(async function () {
19+
sinon.restore();
1920
await client.close();
2021
await clearFailPoint(this.configuration);
2122
});

test/integration/mongodb-handshake/mongodb-handshake.prose.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import * as sinon from 'sinon';
55
import {
66
type ClientMetadata,
77
Connection,
8+
type Document,
89
type DriverInfo,
910
getFAASEnv,
11+
type HandshakeDocument,
1012
Int32,
1113
isDriverInfoEqual,
1214
LEGACY_HELLO_COMMAND,

test/spec/client-backpressure/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,21 @@ Drivers should test that retries do not occur immediately when a SystemOverloade
5050
5. Execute step 3 again.
5151

5252
6. Compare the two time between the two runs.
53+
5354
```python
5455
assertTrue(with_backoff_time - no_backoff_time >= 2.1)
5556
```
57+
5658
The sum of 5 backoffs is 3.1 seconds. There is a 1-second window to account for potential variance between the two
5759
runs.
60+
61+
#### Test 2: Token Bucket Capacity is Enforced
62+
63+
Drivers should test that retry token buckets are created at their maximum capacity and that that capacity is enforced.
64+
65+
1. Let `client` be a `MongoClient`.
66+
2. Assert that the client's retry token bucket is at full capacity and that the capacity is
67+
`DEFAULT_RETRY_TOKEN_CAPACITY`.
68+
3. Using `client`, execute a successful `ping` command.
69+
4. Assert that the successful command did not increase the number of tokens in the bucket above
70+
`DEFAULT_RETRY_TOKEN_CAPACITY`.

0 commit comments

Comments
 (0)