Skip to content

Commit 31eaa52

Browse files
committed
Fix stale test branch clean up
1 parent c009a3a commit 31eaa52

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

test/utility/edgedb-setup.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,18 @@ export const ephemeralEdgeDB = async () => {
2727
async function dropStale(db: Client) {
2828
const branches = await db.query<string>('select sys::Database.name');
2929

30-
const stale = branches.flatMap((name) => {
30+
const stale = branches.filter((name) => {
3131
if (!name.startsWith('test_')) {
32-
return [];
32+
return false;
3333
}
3434
const ts = Number(name.slice(5));
3535
if (isNaN(ts)) {
36-
return [];
36+
return false;
3737
}
3838
const createdAt = DateTime.fromMillis(ts);
39-
return createdAt.diffNow().as('hours') > 4 ? name : [];
40-
});
41-
if (stale.length === 0) {
42-
return;
43-
}
44-
await db.execute('drop branch array_unpack(<array<string>>$branches)', {
45-
branches: stale,
39+
// more than 1 hour old
40+
return createdAt.diffNow().as('hours') < -1;
4641
});
42+
43+
await Promise.all(stale.map((branch) => db.execute(`drop branch ${branch}`)));
4744
}

0 commit comments

Comments
 (0)