| 1 | import * as AWS from "@/AWS"; |
| 2 | import { ScheduleGroup } from "@/AWS/Scheduler"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "@/Test/Alchemy"; |
| 5 | import * as Data from "effect/Data"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: AWS.providers() }); |
| 10 | |
| 11 | class ScheduleGroupNotListed extends Data.TaggedError( |
| 12 | "ScheduleGroupNotListed", |
| 13 | ) {} |
| 14 | |
| 15 | test.provider( |
| 16 | "list enumerates the deployed schedule group", |
| 17 | (stack) => |
| 18 | Effect.gen(function* () { |
| 19 | yield* stack.destroy(); |
| 20 | |
| 21 | const deployed = yield* stack.deploy( |
| 22 | Effect.gen(function* () { |
| 23 | return yield* ScheduleGroup("ListScheduleGroup", {}); |
| 24 | }), |
| 25 | ); |
| 26 | |
| 27 | const provider = yield* Provider.findProvider(ScheduleGroup); |
| 28 | |
| 29 | // EventBridge Scheduler is eventually consistent: a freshly-created group |
| 30 | // may not appear in listScheduleGroups immediately. Retry the list |
| 31 | // assertion on a bounded schedule. |
| 32 | yield* Effect.gen(function* () { |
| 33 | const all = yield* provider.list(); |
| 34 | if ( |
| 35 | !all.some((g) => g.scheduleGroupArn === deployed.scheduleGroupArn) |
| 36 | ) { |
| 37 | return yield* Effect.fail(new ScheduleGroupNotListed()); |
| 38 | } |
| 39 | }).pipe( |
| 40 | Effect.retry({ |
| 41 | while: (e) => e._tag === "ScheduleGroupNotListed", |
| 42 | schedule: Schedule.max([ |
| 43 | Schedule.fixed("3 seconds"), |
| 44 | Schedule.recurs(20), |
| 45 | ]), |
| 46 | }), |
| 47 | ); |
| 48 | |
| 49 | yield* stack.destroy(); |
| 50 | }), |
| 51 | { |
| 52 | tags: ["provider:aws", "provider:aws:scheduler", "live"], |
| 53 | timeout: 120_000, |
| 54 | }, |
| 55 | ); |