Effect CommunityEC
Effect Community3y ago
6 replies
andrewwong

Unit testing effect retry with TestClock in Deno

I am new to Effect and I am still learning it.
I am trying to unit test an effect retry in a pipe with TestClock in Deno.
The pipeline retries after a rate limit with a 1-minute delay. I would like to verify the retry is happening in the unit test, but mocking the response to trigger a retry takes 1 minute for the test to be completed. I am wondering if there is a way to reduce the time.


The pipeline:

const retryPolicy = Schedule.addDelay(
  Schedule.recurs(3),
  () => "1 minutes",
)

export const fetchEffect = (url: string, headers?: Record<string, string>) =>
  Effect.retry(
    HttpClient.pipe(
      Effect.flatMap((httpClient) => httpClient.fetch(url, { headers })),
      Effect.flatMap((response) =>
        response.ok
          ? Effect.succeed(response)
          : Effect.fail(new ResponseNotOkError())
      ),
    ),
    retryPolicy,
  )
Was this page helpful?