Skip to content

Commit

Permalink
fix: Retries to content client failed because of a wrong url
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinszuchet committed Jan 24, 2025
1 parent eebe2ad commit 029b38a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion processor/src/adapters/badge-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function createBadgeContext({
return (attempt: number): Promise<T> => {
if (attempt > 1 && catalystServers.length > 0) {
const [catalystServerUrl] = catalystServers.splice(attempt % catalystServers.length, 1)
contentClientToUse = getContentClientOrDefault(catalystServerUrl)
contentClientToUse = getContentClientOrDefault(`${catalystServerUrl}/content`)
}

return executeClientRequest(contentClientToUse)
Expand Down
20 changes: 10 additions & 10 deletions processor/test/unit/adapters/badge-context.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jest.mock('../../../src/utils/timer', () => ({
sleep: jest.fn()
}))

const LOAD_BALANCER_URL = 'http://catalyst-server.com'
const CATALYST_CONTENT_URL_LOADBALANCER = 'http://catalyst-server.com/content'

describe('Badge Context', () => {
let badgeContext: IBadgeContext
Expand All @@ -40,9 +40,9 @@ describe('Badge Context', () => {
const { fetch, config } = await getMockedComponents()
badgeContext = await createBadgeContext({
fetch,
config: { ...config, requireString: jest.fn().mockReturnValueOnce(LOAD_BALANCER_URL) }
config: { ...config, requireString: jest.fn().mockReturnValueOnce(CATALYST_CONTENT_URL_LOADBALANCER) }
})
contentClientMock = createContentClient({ fetcher: fetch, url: LOAD_BALANCER_URL })
contentClientMock = createContentClient({ fetcher: fetch, url: CATALYST_CONTENT_URL_LOADBALANCER })
})

afterEach(() => {
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('Badge Context', () => {
beforeEach(() => {
entityId = 'some-entity-id'
entity = { id: entityId }
customContentServer = 'http://custom-content-server.com'
customContentServer = 'http://custom-content-server.com/content'
})

it('should fetch entity by ID with retries and default values', async () => {
Expand Down Expand Up @@ -133,9 +133,9 @@ describe('Badge Context', () => {

await badgeContext.getEntityById(entityId)

expectContentClientToHaveBeenCalledWithUrl(LOAD_BALANCER_URL)
expectContentClientToHaveBeenCalledWithUrl('http://catalyst-server-3.com')
expectContentClientToHaveBeenCalledWithUrl('http://catalyst-server-2.com')
expectContentClientToHaveBeenCalledWithUrl(CATALYST_CONTENT_URL_LOADBALANCER)
expectContentClientToHaveBeenCalledWithUrl('http://catalyst-server-3.com/content')
expectContentClientToHaveBeenCalledWithUrl('http://catalyst-server-2.com/content')

expect(contentClientMock.fetchEntityById).toHaveBeenCalledTimes(3)
})
Expand Down Expand Up @@ -214,9 +214,9 @@ describe('Badge Context', () => {

await badgeContext.getEntitiesByPointers(pointers)

expectContentClientToHaveBeenCalledWithUrl(LOAD_BALANCER_URL)
expectContentClientToHaveBeenCalledWithUrl('http://catalyst-server-3.com')
expectContentClientToHaveBeenCalledWithUrl('http://catalyst-server-2.com')
expectContentClientToHaveBeenCalledWithUrl(CATALYST_CONTENT_URL_LOADBALANCER)
expectContentClientToHaveBeenCalledWithUrl('http://catalyst-server-3.com/content')
expectContentClientToHaveBeenCalledWithUrl('http://catalyst-server-2.com/content')

expect(contentClientMock.fetchEntitiesByPointers).toHaveBeenCalledTimes(3)
})
Expand Down

0 comments on commit 029b38a

Please sign in to comment.