Skip to content

Commit

Permalink
fix unit test to account for jitter
Browse files Browse the repository at this point in the history
  • Loading branch information
anitarua committed Aug 21, 2024
1 parent e02ed7e commit 6fbdcb9
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions packages/client-sdk-nodejs/test/unit/storage-retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,54 +90,54 @@ describe('storage configuration', () => {
details: 'deadline exceeded',
metadata: new Metadata(),
};
expect(
testRetryStrategy
.determineWhenToRetryRequest({
grpcStatus: testGrpcStatusDeadlineExceeded,
grpcRequest: testClientRequest as ClientMethodDefinition<
unknown,
unknown
>,
attemptNumber: 1,
})
?.valueOf()
).toEqual(100); // will retry after 100ms
const whenToRetryDeadlineExceeded =
testRetryStrategy.determineWhenToRetryRequest({
grpcStatus: testGrpcStatusDeadlineExceeded,
grpcRequest: testClientRequest as ClientMethodDefinition<
unknown,
unknown
>,
attemptNumber: 1,
});
// should retry after 100ms +/- 10% jitter
expect(whenToRetryDeadlineExceeded).toBeGreaterThanOrEqual(90);
expect(whenToRetryDeadlineExceeded).toBeLessThanOrEqual(110);

const testGrpcStatusInternalError = {
code: Status.INTERNAL,
details: 'internal server error',
metadata: new Metadata(),
};
expect(
testRetryStrategy
.determineWhenToRetryRequest({
grpcStatus: testGrpcStatusInternalError,
grpcRequest: testClientRequest as ClientMethodDefinition<
unknown,
unknown
>,
attemptNumber: 1,
})
?.valueOf()
).toEqual(100); // will retry after 100ms
const whenToRetryInternalError =
testRetryStrategy.determineWhenToRetryRequest({
grpcStatus: testGrpcStatusInternalError,
grpcRequest: testClientRequest as ClientMethodDefinition<
unknown,
unknown
>,
attemptNumber: 1,
});
// should retry after 100ms +/- 10% jitter
expect(whenToRetryInternalError).toBeGreaterThanOrEqual(90);
expect(whenToRetryInternalError).toBeLessThanOrEqual(110);

const testGrpcStatusUnavailable = {
code: Status.UNAVAILABLE,
details: 'server unavailable',
metadata: new Metadata(),
};
expect(
testRetryStrategy
.determineWhenToRetryRequest({
grpcStatus: testGrpcStatusUnavailable,
grpcRequest: testClientRequest as ClientMethodDefinition<
unknown,
unknown
>,
attemptNumber: 1,
})
?.valueOf()
).toEqual(100); // will retry after 100ms
const whenToRetryUnavailable =
testRetryStrategy.determineWhenToRetryRequest({
grpcStatus: testGrpcStatusUnavailable,
grpcRequest: testClientRequest as ClientMethodDefinition<
unknown,
unknown
>,
attemptNumber: 1,
});
// should retry after 100ms +/- 10% jitter
expect(whenToRetryUnavailable).toBeGreaterThanOrEqual(90);
expect(whenToRetryUnavailable).toBeLessThanOrEqual(110);

const testGrpcStatusCancelled = {
code: Status.CANCELLED,
Expand Down

0 comments on commit 6fbdcb9

Please sign in to comment.