Skip to content

Commit

Permalink
Fixed flaky circuitBreaker unit test. (#893)
Browse files Browse the repository at this point in the history
* Fixed flaky circuitBreaker unit test.

Signed-off-by: Theo Truong <theotr@amazon.com>
  • Loading branch information
nhtruong authored Oct 31, 2024
1 parent 46f3d96 commit 5f55f06
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions test/unit/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1037,27 +1037,13 @@ test('Content length too big (string)', (t) => {

test('Content length exceeds max heap limit', (t) => {
t.plan(4);
const percentage = 0.8;
const HEAP_SIZE_LIMIT_WITH_BUFFER = Number(
require('v8').getHeapStatistics().heap_size_limit * percentage
);
const contentLength = buffer.constants.MAX_STRING_LENGTH - 1;
const percentage = 0.01;
const HEAP_SIZE_LIMIT = require('v8').getHeapStatistics().heap_size_limit;
const contentLength = Math.round(HEAP_SIZE_LIMIT * percentage + 1);
const memoryCircuitBreaker = {
enabled: true,
maxPercentage: percentage,
};
// Simulate allocation of bytes
const memoryAllocations = [];
while (process.memoryUsage().heapUsed + contentLength <= HEAP_SIZE_LIMIT_WITH_BUFFER) {
const allocation = 50 * 1024 * 1024; // 50MB
const numbers = allocation / 8;
const arr = [];
arr.length = numbers;
for (let i = 0; i < numbers; i++) {
arr[i] = i;
}
memoryAllocations.push(arr);
}

class MockConnection extends Connection {
request(params, callback) {
Expand Down

0 comments on commit 5f55f06

Please sign in to comment.