ivy
ivy2w ago

Supabase Client Causing Resourse Leak During Integration Tests

I have a node project that we are working on porting over to deno for various unrelated reasons. The transition is going relitively smoothly, except for our integration tests. I keep ketting resourse leak issues stemming from a supabase client. As far as i know supabase clients close by themselves, since theres no close method on the client, please not testdata was omitted due to length
import { SupabaseClient } from "jsr:@supabase/supabase-js";
import { SpotifyUserPlaying, MockUserPlaying } from "../../src/music/UserPlaying.ts";
import { Client, Player } from "npm:spotify-api.js@latest";

import { expect } from "jsr:@std/expect";

Deno.test("User Playing Tests", async (t: Deno.TestContext) => {

console.log("test env", Deno.env.get("SB_URL_TEST"))
const supabase: SupabaseClient<any, "test", any> = new SupabaseClient(
Deno.env.get("SB_URL_TEST") as string,
Deno.env.get("ANON") as string,
{ db: { schema: "test" } }
);
const { data, error } = await supabase.auth.signUp({
email: "test1@example.com",
password: "password",
});
if (error) throw error;

const userId = data.user?.id || "";
await t.step("MockUserPlaying init method", async () => {
const mockUserPlaying = new MockUserPlaying(supabase, userId, testData1);
await expect(mockUserPlaying.init()).resolves.not.toThrow();
});

await supabase.auth.admin.deleteUser(userId);
});
import { SupabaseClient } from "jsr:@supabase/supabase-js";
import { SpotifyUserPlaying, MockUserPlaying } from "../../src/music/UserPlaying.ts";
import { Client, Player } from "npm:spotify-api.js@latest";

import { expect } from "jsr:@std/expect";

Deno.test("User Playing Tests", async (t: Deno.TestContext) => {

console.log("test env", Deno.env.get("SB_URL_TEST"))
const supabase: SupabaseClient<any, "test", any> = new SupabaseClient(
Deno.env.get("SB_URL_TEST") as string,
Deno.env.get("ANON") as string,
{ db: { schema: "test" } }
);
const { data, error } = await supabase.auth.signUp({
email: "test1@example.com",
password: "password",
});
if (error) throw error;

const userId = data.user?.id || "";
await t.step("MockUserPlaying init method", async () => {
const mockUserPlaying = new MockUserPlaying(supabase, userId, testData1);
await expect(mockUserPlaying.init()).resolves.not.toThrow();
});

await supabase.auth.admin.deleteUser(userId);
});
here is the error with trace-leaks
Playing Tests => ./tests/music/UserPlaying.test.ts:8:6
error: Leaks detected:
- An interval was started in this test, but never completed. This is often caused by not calling `clearInterval`. The operation was started here:
at Object.queueUserTimer (ext:core/01_core.js:793:9)
at setInterval (ext:deno_web/02_timers.js:93:15)
at Timeout.<computed> (ext:deno_node/internal/timers.mjs:71:7)
at new Timeout (ext:deno_node/internal/timers.mjs:57:37)
at setInterval (node:timers:37:10)
at SupabaseAuthClient._startAutoRefresh
Playing Tests => ./tests/music/UserPlaying.test.ts:8:6
error: Leaks detected:
- An interval was started in this test, but never completed. This is often caused by not calling `clearInterval`. The operation was started here:
at Object.queueUserTimer (ext:core/01_core.js:793:9)
at setInterval (ext:deno_web/02_timers.js:93:15)
at Timeout.<computed> (ext:deno_node/internal/timers.mjs:71:7)
at new Timeout (ext:deno_node/internal/timers.mjs:57:37)
at setInterval (node:timers:37:10)
at SupabaseAuthClient._startAutoRefresh
thanks
2 Replies
louislam
louislam2w ago
You can trace leaks: deno test --trace-leaks
ivy
ivyOP2w ago
thats how i know its the supabase client the solution was to put the creation of supabase outside the test

Did you find this page helpful?