From eb2c7ff6c6b9c3298298cd6febefe33d78653c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=93=E3=81=8B=E3=82=8A?= <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sat, 4 Jul 2026 11:21:23 +0900 Subject: [PATCH] =?UTF-8?q?fix(backend/test):=20follow-up=20of=20#17654=20?= =?UTF-8?q?(waitFor=E3=82=92=E4=BB=96=E3=81=AEe2e=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=81=AB=E3=82=82=E5=B1=95=E9=96=8B)=20(#17659)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test(backend): block.ts等のfanout timeline反映待ちレースを修正する (tiramiss-community/endolphin#112) Co-authored-by: おさむのひと <46447427+samunohito@users.noreply.github.com> --- packages/backend/test/e2e/api-visibility.ts | 24 +++++---- packages/backend/test/e2e/block.ts | 20 +++++--- packages/backend/test/e2e/endpoints.ts | 16 +++--- packages/backend/test/e2e/mute.ts | 32 +++++++----- packages/backend/test/e2e/renote-mute.ts | 54 ++++++++++----------- packages/backend/test/e2e/user-notes.ts | 26 +++++----- 6 files changed, 97 insertions(+), 75 deletions(-) diff --git a/packages/backend/test/e2e/api-visibility.ts b/packages/backend/test/e2e/api-visibility.ts index 4f244c0cce..8bfca077ba 100644 --- a/packages/backend/test/e2e/api-visibility.ts +++ b/packages/backend/test/e2e/api-visibility.ts @@ -6,10 +6,12 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; -import { describe, beforeAll, beforeEach, test } from 'vitest'; +import { describe, beforeAll, beforeEach, test, vi } from 'vitest'; import { UserToken, api, post, signup } from '../utils.js'; import type * as misskey from 'misskey-js'; +const waitForPushToTlOptions = { timeout: 3000, interval: 25 }; + describe('API visibility', () => { describe('Note visibility', () => { //#region vars @@ -409,10 +411,12 @@ describe('API visibility', () => { //#region HTL test('[HTL] public-post が 自分が見れる', async () => { - const res = await api('notes/timeline', { limit: 100 }, alice); - assert.strictEqual(res.status, 200); - const notes = res.body.filter(n => n.id === pub.id); - assert.strictEqual(notes[0].text, 'x'); + await vi.waitFor(async () => { + const res = await api('notes/timeline', { limit: 100 }, alice); + assert.strictEqual(res.status, 200); + const notes = res.body.filter(n => n.id === pub.id); + assert.strictEqual(notes[0].text, 'x'); + }, waitForPushToTlOptions); }); test('[HTL] public-post が 非フォロワーから見れない', async () => { @@ -423,10 +427,12 @@ describe('API visibility', () => { }); test('[HTL] followers-post が フォロワーから見れる', async () => { - const res = await api('notes/timeline', { limit: 100 }, follower); - assert.strictEqual(res.status, 200); - const notes = res.body.filter(n => n.id === fol.id); - assert.strictEqual(notes[0].text, 'x'); + await vi.waitFor(async () => { + const res = await api('notes/timeline', { limit: 100 }, follower); + assert.strictEqual(res.status, 200); + const notes = res.body.filter(n => n.id === fol.id); + assert.strictEqual(notes[0].text, 'x'); + }, waitForPushToTlOptions); }); //#endregion diff --git a/packages/backend/test/e2e/block.ts b/packages/backend/test/e2e/block.ts index 9ef4dd8be9..86e27b461e 100644 --- a/packages/backend/test/e2e/block.ts +++ b/packages/backend/test/e2e/block.ts @@ -6,10 +6,12 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; -import { describe, beforeAll, test } from 'vitest'; +import { describe, beforeAll, test, vi } from 'vitest'; import { api, castAsError, post, signup } from '../utils.js'; import type * as misskey from 'misskey-js'; +const waitForPushToTlOptions = { timeout: 3000, interval: 25 }; + describe('Block', () => { // alice blocks bob let alice: misskey.entities.SignupResponse; @@ -75,13 +77,15 @@ describe('Block', () => { const bobNote = await post(bob, { text: 'hi' }); const carolNote = await post(carol, { text: 'hi' }); - const res = await api('notes/local-timeline', {}, bob); - const body = res.body as misskey.entities.Note[]; + await vi.waitFor(async () => { + const res = await api('notes/local-timeline', {}, bob); + const body = res.body as misskey.entities.Note[]; - assert.strictEqual(res.status, 200); - assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(body.some(note => note.id === aliceNote.id), false); - assert.strictEqual(body.some(note => note.id === bobNote.id), true); - assert.strictEqual(body.some(note => note.id === carolNote.id), true); + assert.strictEqual(res.status, 200); + assert.strictEqual(Array.isArray(res.body), true); + assert.strictEqual(body.some(note => note.id === aliceNote.id), false); + assert.strictEqual(body.some(note => note.id === bobNote.id), true); + assert.strictEqual(body.some(note => note.id === carolNote.id), true); + }, waitForPushToTlOptions); }); }); diff --git a/packages/backend/test/e2e/endpoints.ts b/packages/backend/test/e2e/endpoints.ts index 09198384c4..402836ca47 100644 --- a/packages/backend/test/e2e/endpoints.ts +++ b/packages/backend/test/e2e/endpoints.ts @@ -6,7 +6,7 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; -import { describe, beforeAll, test, expect } from 'vitest'; +import { describe, beforeAll, test, expect, vi } from 'vitest'; // node-fetch only supports it's own Blob yet // https://github.com/node-fetch/node-fetch/pull/1664 import { Blob } from 'node-fetch'; @@ -14,6 +14,8 @@ import { api, castAsError, initTestDb, post, role, signup, simpleGet, uploadFile import type * as misskey from 'misskey-js'; import { MiUser } from '@/models/_.js'; +const waitForPushToTlOptions = { timeout: 3000, interval: 25 }; + describe('Endpoints', () => { let alice: misskey.entities.SignupResponse; let bob: misskey.entities.SignupResponse; @@ -1149,12 +1151,14 @@ describe('Endpoints', () => { visibility: 'followers', }); - const res = await api('notes/timeline', {}, dave); + await vi.waitFor(async () => { + const res = await api('notes/timeline', {}, dave); - assert.strictEqual(res.status, 200); - assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.length, 1); - assert.strictEqual(res.body[0].id, carolPost.id); + assert.strictEqual(res.status, 200); + assert.strictEqual(Array.isArray(res.body), true); + assert.strictEqual(res.body.length, 1); + assert.strictEqual(res.body[0].id, carolPost.id); + }, waitForPushToTlOptions); }); }); diff --git a/packages/backend/test/e2e/mute.ts b/packages/backend/test/e2e/mute.ts index f5cc875e7c..c579c52a2b 100644 --- a/packages/backend/test/e2e/mute.ts +++ b/packages/backend/test/e2e/mute.ts @@ -6,10 +6,12 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; -import { beforeAll, describe, test } from 'vitest'; +import { beforeAll, describe, test, vi } from 'vitest'; import { api, post, react, signup, waitFire } from '../utils.js'; import type * as misskey from 'misskey-js'; +const waitForPushToTlOptions = { timeout: 3000, interval: 25 }; + describe('Mute', () => { // alice mutes carol let alice: misskey.entities.SignupResponse; @@ -67,13 +69,15 @@ describe('Mute', () => { const bobNote = await post(bob, { text: 'hi' }); const carolNote = await post(carol, { text: 'hi' }); - const res = await api('notes/local-timeline', {}, alice); + await vi.waitFor(async () => { + const res = await api('notes/local-timeline', {}, alice); - assert.strictEqual(res.status, 200); - assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.some(note => note.id === aliceNote.id), true); - assert.strictEqual(res.body.some(note => note.id === bobNote.id), true); - assert.strictEqual(res.body.some(note => note.id === carolNote.id), false); + assert.strictEqual(res.status, 200); + assert.strictEqual(Array.isArray(res.body), true); + assert.strictEqual(res.body.some(note => note.id === aliceNote.id), true); + assert.strictEqual(res.body.some(note => note.id === bobNote.id), true); + assert.strictEqual(res.body.some(note => note.id === carolNote.id), false); + }, waitForPushToTlOptions); }); test('タイムラインにミュートしているユーザーの投稿のRenoteが含まれない', async () => { @@ -83,13 +87,15 @@ describe('Mute', () => { renoteId: carolNote.id, }); - const res = await api('notes/local-timeline', {}, alice); + await vi.waitFor(async () => { + const res = await api('notes/local-timeline', {}, alice); - assert.strictEqual(res.status, 200); - assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.some(note => note.id === aliceNote.id), true); - assert.strictEqual(res.body.some(note => note.id === bobNote.id), false); - assert.strictEqual(res.body.some(note => note.id === carolNote.id), false); + assert.strictEqual(res.status, 200); + assert.strictEqual(Array.isArray(res.body), true); + assert.strictEqual(res.body.some(note => note.id === aliceNote.id), true); + assert.strictEqual(res.body.some(note => note.id === bobNote.id), false); + assert.strictEqual(res.body.some(note => note.id === carolNote.id), false); + }, waitForPushToTlOptions); }); }); diff --git a/packages/backend/test/e2e/renote-mute.ts b/packages/backend/test/e2e/renote-mute.ts index 785c9dff8b..555d7c2a20 100644 --- a/packages/backend/test/e2e/renote-mute.ts +++ b/packages/backend/test/e2e/renote-mute.ts @@ -6,11 +6,12 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; -import { beforeAll, describe, test } from 'vitest'; -import { setTimeout } from 'node:timers/promises'; +import { beforeAll, describe, test, vi } from 'vitest'; import { api, post, signup, waitFire } from '../utils.js'; import type * as misskey from 'misskey-js'; +const waitForPushToTlOptions = { timeout: 3000, interval: 25 }; + describe('Renote Mute', () => { // alice mutes carol let alice: misskey.entities.SignupResponse; @@ -36,16 +37,15 @@ describe('Renote Mute', () => { const carolRenote = await post(carol, { renoteId: bobNote.id }); const carolNote = await post(carol, { text: 'hi' }); - // redisに追加されるのを待つ - await setTimeout(100); + await vi.waitFor(async () => { + const res = await api('notes/local-timeline', {}, alice); - const res = await api('notes/local-timeline', {}, alice); - - assert.strictEqual(res.status, 200); - assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.some(note => note.id === bobNote.id), true); - assert.strictEqual(res.body.some(note => note.id === carolRenote.id), false); - assert.strictEqual(res.body.some(note => note.id === carolNote.id), true); + assert.strictEqual(res.status, 200); + assert.strictEqual(Array.isArray(res.body), true); + assert.strictEqual(res.body.some(note => note.id === bobNote.id), true); + assert.strictEqual(res.body.some(note => note.id === carolRenote.id), false); + assert.strictEqual(res.body.some(note => note.id === carolNote.id), true); + }, waitForPushToTlOptions); }); test('タイムラインにリノートミュートしているユーザーの引用が含まれる', async () => { @@ -53,16 +53,15 @@ describe('Renote Mute', () => { const carolRenote = await post(carol, { renoteId: bobNote.id, text: 'kore' }); const carolNote = await post(carol, { text: 'hi' }); - // redisに追加されるのを待つ - await setTimeout(100); + await vi.waitFor(async () => { + const res = await api('notes/local-timeline', {}, alice); - const res = await api('notes/local-timeline', {}, alice); - - assert.strictEqual(res.status, 200); - assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.some(note => note.id === bobNote.id), true); - assert.strictEqual(res.body.some(note => note.id === carolRenote.id), true); - assert.strictEqual(res.body.some(note => note.id === carolNote.id), true); + assert.strictEqual(res.status, 200); + assert.strictEqual(Array.isArray(res.body), true); + assert.strictEqual(res.body.some(note => note.id === bobNote.id), true); + assert.strictEqual(res.body.some(note => note.id === carolRenote.id), true); + assert.strictEqual(res.body.some(note => note.id === carolNote.id), true); + }, waitForPushToTlOptions); }); // #12956 @@ -70,15 +69,14 @@ describe('Renote Mute', () => { const carolNote = await post(carol, { text: 'hi' }); const bobRenote = await post(bob, { renoteId: carolNote.id }); - // redisに追加されるのを待つ - await setTimeout(100); + await vi.waitFor(async () => { + const res = await api('notes/local-timeline', {}, alice); - const res = await api('notes/local-timeline', {}, alice); - - assert.strictEqual(res.status, 200); - assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.some(note => note.id === carolNote.id), true); - assert.strictEqual(res.body.some(note => note.id === bobRenote.id), true); + assert.strictEqual(res.status, 200); + assert.strictEqual(Array.isArray(res.body), true); + assert.strictEqual(res.body.some(note => note.id === carolNote.id), true); + assert.strictEqual(res.body.some(note => note.id === bobRenote.id), true); + }, waitForPushToTlOptions); }); test('ストリームにリノートミュートしているユーザーのリノートが流れない', async () => { diff --git a/packages/backend/test/e2e/user-notes.ts b/packages/backend/test/e2e/user-notes.ts index 2f89ac54ce..c6fabca05f 100644 --- a/packages/backend/test/e2e/user-notes.ts +++ b/packages/backend/test/e2e/user-notes.ts @@ -6,10 +6,12 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; -import { beforeAll, describe, test } from 'vitest'; +import { beforeAll, describe, test, vi } from 'vitest'; import { api, post, signup, uploadUrl } from '../utils.js'; import type * as misskey from 'misskey-js'; +const waitForPushToTlOptions = { timeout: 3000, interval: 25 }; + describe('users/notes', () => { let alice: misskey.entities.SignupResponse; let jpgNote: misskey.entities.Note; @@ -32,16 +34,18 @@ describe('users/notes', () => { }, 1000 * 60 * 2); test('withFiles', async () => { - const res = await api('users/notes', { - userId: alice.id, - withFiles: true, - }, alice); + await vi.waitFor(async () => { + const res = await api('users/notes', { + userId: alice.id, + withFiles: true, + }, alice); - assert.strictEqual(res.status, 200); - assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.length, 3); - assert.strictEqual(res.body.some((note: any) => note.id === jpgNote.id), true); - assert.strictEqual(res.body.some((note: any) => note.id === pngNote.id), true); - assert.strictEqual(res.body.some((note: any) => note.id === jpgPngNote.id), true); + assert.strictEqual(res.status, 200); + assert.strictEqual(Array.isArray(res.body), true); + assert.strictEqual(res.body.length, 3); + assert.strictEqual(res.body.some((note: any) => note.id === jpgNote.id), true); + assert.strictEqual(res.body.some((note: any) => note.id === pngNote.id), true); + assert.strictEqual(res.body.some((note: any) => note.id === jpgPngNote.id), true); + }, waitForPushToTlOptions); }); });