From b9daa73fedebea4c1b8d2db41aea2f8c853e29b4 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 12 Sep 2024 20:46:30 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Patrick Jungermann Signed-off-by: Patrik Oldsberg --- plugins/events-backend/src/service/EventsPlugin.test.ts | 8 ++++---- .../src/service/hub/DatabaseEventBusStore.ts | 2 +- .../src/service/hub/createEventBusRouter.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/events-backend/src/service/EventsPlugin.test.ts b/plugins/events-backend/src/service/EventsPlugin.test.ts index 18b994bff9..0cfb68eb05 100644 --- a/plugins/events-backend/src/service/EventsPlugin.test.ts +++ b/plugins/events-backend/src/service/EventsPlugin.test.ts @@ -233,7 +233,7 @@ describe('eventsPlugin', () => { events: [{ topic: 'test', payload: { n: 1 } }], }); - // Two clients for subscriber 2, only one gets the event + // Two clients for subscriber 2, only one gets the event const res1 = helper.readEvents('tester-2'); const res2 = helper.readEvents('tester-2'); @@ -261,7 +261,7 @@ describe('eventsPlugin', () => { ); it.each(databases.eachSupportedId())( - 'should should not notify subscribers that have already consumed the event, %p', + 'should not notify subscribers that have already consumed the event, %p', async databaseId => { const backend = await startTestBackend({ features: [eventsPlugin(), await mockKnexFactory(databaseId)], @@ -296,7 +296,7 @@ describe('eventsPlugin', () => { await helper.readEvents('tester-1').expect(200, { events: [{ topic: 'test', payload: { for: 'tester-1' } }], }); - // Single client for subscriber 1 gets the event + // Single client for subscriber 2 gets the event await helper.readEvents('tester-2').expect(200, { events: [{ topic: 'test', payload: { for: 'tester-2' } }], }); @@ -316,7 +316,7 @@ describe('eventsPlugin', () => { // 2 subscribers await helper.subscribe('tester', ['test']).expect(201); - // A single event for each subscriber, that should not be sent to the other one + // A sequence of events published one at a time for (let n = 0; n < 15; ++n) { await helper.publish('test', { n }).expect(201); } diff --git a/plugins/events-backend/src/service/hub/DatabaseEventBusStore.ts b/plugins/events-backend/src/service/hub/DatabaseEventBusStore.ts index 6694703a2e..c9e97e22b1 100644 --- a/plugins/events-backend/src/service/hub/DatabaseEventBusStore.ts +++ b/plugins/events-backend/src/service/hub/DatabaseEventBusStore.ts @@ -26,7 +26,7 @@ import { import { ForwardedError, NotFoundError } from '@backstage/errors'; import { HumanDuration, durationToMilliseconds } from '@backstage/types'; -const WINDOW_SIZE_DEFAULT = 10000; +const WINDOW_SIZE_DEFAULT = 10_000; const WINDOW_MIN_AGE_DEFAULT = { minutes: 10 }; const WINDOW_MAX_AGE_DEFAULT = { days: 1 }; diff --git a/plugins/events-backend/src/service/hub/createEventBusRouter.ts b/plugins/events-backend/src/service/hub/createEventBusRouter.ts index 2e1dc043db..a3ba7779b1 100644 --- a/plugins/events-backend/src/service/hub/createEventBusRouter.ts +++ b/plugins/events-backend/src/service/hub/createEventBusRouter.ts @@ -203,14 +203,14 @@ export async function createEventBusRouter(options: { // By setting up the listener first we make sure we don't miss any events // that are published while reading. If an event is published we'll receive - // a notification, which depending on the outcome of the read we may ignore + // a notification, which we may ignore depending on the outcome of the read const listener = await store.setupListener(id, { signal: controller.signal, }); // By timing out requests we make sure they don't stall or that events get stuck. // For the caller there's no difference between a timeout and a - // notifications, either way they should try reading again. + // notification, either way they should try reading again. const timeout = setTimeout(() => { controller.abort(); }, notifyTimeoutMs);