Skip to content

Commit

Permalink
feat(telemetry): update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Beniamin Munteanu committed Mar 28, 2024
1 parent 2e5adf1 commit 04ee26a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 6 additions & 2 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { createIlpPaymentService } from './payment-method/ilp/service'
import { createSPSPRoutes } from './payment-method/ilp/spsp/routes'
import { createStreamCredentialsService } from './payment-method/ilp/stream-credentials/service'
import { createRatesService } from './rates/service'
import { createTelemetryService } from './telemetry/service'
import { TelemetryService, createTelemetryService } from './telemetry/service'
import { createWebhookService } from './webhook/service'

BigInt.prototype.toJSON = function () {
Expand Down Expand Up @@ -355,6 +355,10 @@ export function initIocContainer(

container.singleton('connectorApp', async (deps) => {
const config = await deps.use('config')
let telemetry: TelemetryService | undefined
if (config.enableTelemetry) {
telemetry = await deps.use('telemetry')
}
return await createConnectorService({
logger: await deps.use('logger'),
redis: await deps.use('redis'),
Expand All @@ -365,7 +369,7 @@ export function initIocContainer(
ratesService: await deps.use('ratesService'),
streamServer: await deps.use('streamServer'),
ilpAddress: config.ilpAddress,
telemetry: await deps.use('telemetry')
telemetry
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import assert from 'assert'
import { OutgoingAccount, ZeroCopyIlpPrepare } from '../..'
import { IlpResponse, OutgoingAccount, ZeroCopyIlpPrepare } from '../..'
import { IncomingAccountFactory, RafikiServicesFactory } from '../../factories'
import { createTelemetryMiddleware } from '../../middleware/telemetry'
import { createILPContext } from '../../utils'

import * as telemetry from '../../../../../../telemetry/transaction-amount'
import { IlpFulfill } from 'ilp-packet'

const incomingAccount = IncomingAccountFactory.build({ id: 'alice' })

Expand All @@ -28,7 +29,10 @@ const ctx = createILPContext({
incomingAccount: {
quote: 'exists'
}
}
},
response: {
fulfill: 'exists' as unknown as IlpFulfill
} as IlpResponse
})

jest.mock('../../../../../../telemetry/transaction-amount')
Expand Down Expand Up @@ -60,8 +64,8 @@ describe('Telemetry Middleware', function () {
ctx.services.telemetry = originalTelemetry
})

it('should call next without gathering telemetry when state is unfulfillable', async () => {
ctx.state.unfulfillable = true
it('should call next without gathering telemetry when outgoing payment is not yet completed (checked by the existance of response.fulfill)', async () => {
ctx.response.fulfill = undefined

const collectAmountSpy = jest.spyOn(telemetry, 'collectTelemetryAmount')

Expand Down

0 comments on commit 04ee26a

Please sign in to comment.