Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keep alive when dispatch fails with 401 #551

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dispatch/Dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Dispatch {
private dispatchTimerId: number | undefined;
private buildClient: ClientBuilder;
private config: Config;
private disableCodes = ['401', '403', '404'];
private disableCodes = ['403', '404'];

constructor(
region: string,
Expand Down
30 changes: 0 additions & 30 deletions src/dispatch/__tests__/Dispatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,36 +479,6 @@ describe('Dispatch tests', () => {
expect((dispatch as unknown as any).enabled).toBe(true);
});

test('when a fetch request is rejected with 401 then dispatch is disabled', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we need reverse of this unit test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not scalable for every status code to have a separate unit test. In the future, we should consolidate them into either "keep alive" or "disable".

// Init
(DataPlaneClient as any).mockImplementationOnce(() => ({
sendFetch: () => Promise.reject(new Error('401'))
}));

const eventCache: EventCache =
Utils.createDefaultEventCacheWithEvents();

const dispatch = new Dispatch(
Utils.AWS_RUM_REGION,
Utils.AWS_RUM_ENDPOINT,
eventCache,
{
...DEFAULT_CONFIG,
...{ dispatchInterval: Utils.AUTO_DISPATCH_OFF, retries: 0 }
}
);
dispatch.setAwsCredentials(Utils.createAwsCredentials());

// Run
eventCache.recordEvent('com.amazon.rum.event1', {});

// Assert
await expect(dispatch.dispatchFetch()).rejects.toEqual(
new Error('401')
);
expect((dispatch as unknown as any).enabled).toBe(false);
});

test('when a fetch request is rejected with 403 then dispatch is disabled', async () => {
// Init
(DataPlaneClient as any).mockImplementationOnce(() => ({
Expand Down
Loading