chore(event-bus): event bus error handling (#10085)
This commit is contained in:
@@ -16,9 +16,9 @@ jest.mock("bullmq")
|
||||
jest.mock("ioredis")
|
||||
|
||||
const loggerMock = {
|
||||
info: jest.fn().mockReturnValue(console.log),
|
||||
warn: jest.fn().mockReturnValue(console.log),
|
||||
error: jest.fn().mockReturnValue(console.log),
|
||||
info: jest.fn().mockImplementation(console.log),
|
||||
warn: jest.fn().mockImplementation(console.warn),
|
||||
error: jest.fn().mockImplementation(console.error),
|
||||
} as unknown as Logger
|
||||
|
||||
const redisMock = {
|
||||
@@ -376,7 +376,7 @@ describe("RedisEventBusService", () => {
|
||||
})
|
||||
eventBus.subscribe("eventName", () => {
|
||||
test.push("fail1")
|
||||
return Promise.reject("fail1")
|
||||
throw new Error("fail1")
|
||||
})
|
||||
eventBus.subscribe("eventName", () => {
|
||||
test.push("hi2")
|
||||
@@ -399,15 +399,21 @@ describe("RedisEventBusService", () => {
|
||||
"Processing eventName which has 4 subscribers"
|
||||
)
|
||||
|
||||
expect(loggerMock.warn).toHaveBeenCalledTimes(3)
|
||||
expect(loggerMock.warn).toHaveBeenCalledWith(
|
||||
"An error occurred while processing eventName: fail1"
|
||||
)
|
||||
expect(loggerMock.warn).toHaveBeenCalledWith(
|
||||
"An error occurred while processing eventName: fail2"
|
||||
expect(loggerMock.warn).toHaveBeenCalledTimes(5)
|
||||
expect(loggerMock.warn).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
"An error occurred while processing eventName:"
|
||||
)
|
||||
expect(loggerMock.warn).toHaveBeenNthCalledWith(2, new Error("fail1"))
|
||||
|
||||
expect(loggerMock.warn).toHaveBeenCalledWith(
|
||||
expect(loggerMock.warn).toHaveBeenNthCalledWith(
|
||||
3,
|
||||
"An error occurred while processing eventName:"
|
||||
)
|
||||
expect(loggerMock.warn).toHaveBeenNthCalledWith(4, "fail2")
|
||||
|
||||
expect(loggerMock.warn).toHaveBeenNthCalledWith(
|
||||
5,
|
||||
"One or more subscribers of eventName failed. Retrying is not configured. Use 'attempts' option when emitting events."
|
||||
)
|
||||
|
||||
@@ -439,10 +445,11 @@ describe("RedisEventBusService", () => {
|
||||
} as any)
|
||||
.catch((error) => void 0)
|
||||
|
||||
expect(loggerMock.warn).toHaveBeenCalledTimes(1)
|
||||
expect(loggerMock.warn).toHaveBeenCalledTimes(2)
|
||||
expect(loggerMock.warn).toHaveBeenCalledWith(
|
||||
"An error occurred while processing eventName: fail1"
|
||||
"An error occurred while processing eventName:"
|
||||
)
|
||||
expect(loggerMock.warn).toHaveBeenCalledWith("fail1")
|
||||
|
||||
expect(loggerMock.info).toHaveBeenCalledTimes(2)
|
||||
expect(loggerMock.info).toHaveBeenCalledWith(
|
||||
@@ -478,10 +485,12 @@ describe("RedisEventBusService", () => {
|
||||
} as any)
|
||||
.catch((err) => void 0)
|
||||
|
||||
expect(loggerMock.warn).toHaveBeenCalledTimes(2)
|
||||
expect(loggerMock.warn).toHaveBeenCalledTimes(3)
|
||||
expect(loggerMock.warn).toHaveBeenCalledWith(
|
||||
"An error occurred while processing eventName: fail1"
|
||||
"An error occurred while processing eventName:"
|
||||
)
|
||||
expect(loggerMock.warn).toHaveBeenCalledWith("fail1")
|
||||
|
||||
expect(loggerMock.warn).toHaveBeenCalledWith(
|
||||
"One or more subscribers of eventName failed. Retrying..."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user