Leo Gall
Leo Gall

Reputation: 23

Memory leak when testing Supabase edge functions

I'm currently writing e2e-Tests for my edge functions. But unfortunately, they throw a weird error. Does anyone know why and how to solve it?

const posthog = initPosthog();
  const featureFlagPayload = (await posthog.getFeatureFlagPayload(
    "conversations",
    user.id
  )) as { max_output_tokens_per_day: number };
  const maxOutputTokensPerDay =
    await featureFlagPayload?.max_output_tokens_per_day;

  await supabase
    .from("daily_token_budgets")
    .update({
      output_tokens: maxOutputTokensPerDay! + 1,
    })
    .eq("date", date.toISOString().split("T")[0]);

  const { error } = await supabase.functions.invoke(
    "send_conversation_message",
    {
      body: {
        query: query1,
        timezone: "Berlin",
      },
    }
  );

  assertFalse(error === null);

  await posthog.shutdown();
Leaks detected:
  - A fetch response body was created during the test, but not consumed during the test. Consume or close the response body `ReadableStream`, e.g `await resp.text()` or `await resp.body.cancel()`.

If I comment out the lines where I update my Supabase entry, it doesn't throw the error (but only if I remove the assert of course, so that's not an options).

Upvotes: 0

Views: 15

Answers (0)

Related Questions