Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(core): add wait for notifications service #4430

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { randomUserId } from "./random"

import { NotificationsServiceUnreachableServerError } from "@/domain/notifications"

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

import { sleep } from "@/utils"

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
Loading