Skip to content

Commit 7532198

Browse files
committed
fix: E2E DB cleanup を drop から deleteMany に変更
コレクション drop はサーバーのインメモリ状態と不整合を起こし、 直後の /me 呼び出しが 401 を返すフレーキーテストの原因になっていた。 deleteMany でドキュメントのみクリアし、コレクション構造を保持する。
1 parent 601b37a commit 7532198

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

tests/e2e/support/hooks.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,13 @@ BeforeAll(async function () {
4242
});
4343

4444
Before(async function (this: GdbWorld) {
45-
// DB cleanup for scenario isolation — drop collections to bypass server caching
45+
// DB cleanup for scenario isolation — delete documents but preserve collections/indexes
46+
// to avoid server-side inconsistencies caused by full collection drops
4647
const db = mongoClient.db();
4748
const collections = await db.listCollections().toArray();
4849
for (const c of collections) {
4950
if (!c.name.startsWith("system.")) {
50-
await db.collection(c.name).drop().catch((err: Error & { code?: number }) => {
51-
if (err.code !== 26 && !err.message.includes("ns not found")) {
52-
console.warn(`Warning: failed to drop collection ${c.name}: ${err.message}`);
53-
}
54-
});
51+
await db.collection(c.name).deleteMany({});
5552
}
5653
}
5754

0 commit comments

Comments
 (0)