Skip to content

Commit

Permalink
test(core): add wait for notifications service
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed May 6, 2024
1 parent f8a88a1 commit 6039a0a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/api/test/helpers/shared.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import { NotificationsServiceUnreachableServerError } from "@/domain/notifications"

import { NotificationsService } from "@/services/notifications"

import { sleep } from "@/utils"

import { randomUserId } from "./random"

export const waitFor = async (f: () => Promise<unknown>) => {
let res
while (!(res = await f())) await sleep(500)
return res
}

// Note: this is to fix flakiness with notifications service health check. This waiting
// should eventually happen in the tiltfile somehow.
export const waitForNotificationsService = () =>
waitFor(async () => {
const res = await NotificationsService().getUserNotificationSettings(randomUserId())
return !(res instanceof NotificationsServiceUnreachableServerError)
})
2 changes: 2 additions & 0 deletions core/api/test/integration/scenarios/hedge-arbitrage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
randomPhone,
randomUserId,
resetLegacyIntegrationLnds,
waitForNotificationsService,
} from "test/helpers"

class ZeroAmountForUsdRecipientError extends Error {}
Expand Down Expand Up @@ -65,6 +66,7 @@ beforeAll(async () => {
await loadBitcoindWallet("outside")
await resetLegacyIntegrationLnds()
await bootstrapLndNodes()
await waitForNotificationsService()
})

afterAll(async () => {
Expand Down
6 changes: 6 additions & 0 deletions core/api/test/integration/services/notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { toSats } from "@/domain/bitcoin"

import { NotificationsService } from "@/services/notifications"

import { waitForNotificationsService } from "test/helpers"

beforeAll(async () => {
await waitForNotificationsService()
})

describe("NotificationsService", () => {
describe("sendTransaction", () => {
it("should send a notification", async () => {
Expand Down

0 comments on commit 6039a0a

Please sign in to comment.