|
1 | 1 | import { expect } from 'chai'; |
2 | 2 | import * as sinon from 'sinon'; |
3 | 3 |
|
4 | | -import { type Collection, type MongoClient, MongoServerError } from '../../../src'; |
| 4 | +import { |
| 5 | + type Collection, |
| 6 | + INITIAL_TOKEN_BUCKET_SIZE, |
| 7 | + type MongoClient, |
| 8 | + MongoServerError |
| 9 | +} from '../../mongodb'; |
5 | 10 | import { clearFailPoint, configureFailPoint, measureDuration } from '../../tools/utils'; |
6 | 11 |
|
7 | 12 | describe('Client Backpressure (Prose)', function () { |
@@ -58,4 +63,19 @@ describe('Client Backpressure (Prose)', function () { |
58 | 63 | expect(durationBackoff - durationNoBackoff).to.be.within(3100 - 1000, 3100 + 1000); |
59 | 64 | } |
60 | 65 | ); |
| 66 | + |
| 67 | + it('Test 2: Token Bucket capacity is Enforced', async () => { |
| 68 | + // 1-2. Assert that the client's retry token bucket is at full capacity and that the capacity |
| 69 | + // is DEFAULT_RETRY_TOKEN_CAPACITY. |
| 70 | + const tokenBucket = client.topology.tokenBucket; |
| 71 | + expect(tokenBucket).to.have.property('budget', INITIAL_TOKEN_BUCKET_SIZE); |
| 72 | + expect(tokenBucket).to.have.property('capacity', INITIAL_TOKEN_BUCKET_SIZE); |
| 73 | + |
| 74 | + // 3. Execute a successful ping command. |
| 75 | + await client.db('admin').command({ ping: 1 }); |
| 76 | + |
| 77 | + // 4. Assert that the successful command did not increase the number of tokens in the bucket |
| 78 | + // above DEFAULT_RETRY_TOKEN_CAPACITY. |
| 79 | + expect(tokenBucket).to.have.property('budget').that.is.at.most(INITIAL_TOKEN_BUCKET_SIZE); |
| 80 | + }); |
61 | 81 | }); |
0 commit comments