summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2022-07-03 20:54:54 +0900
committerGitHub <noreply@github.com>2022-07-03 20:54:54 +0900
commit034c5d792b47fbc4dda498c73adbdcac6b50c096 (patch)
treed95e0e1d7aad23d6f2ba2772dbbb339d8e7bb118
parent12.112.0-beta.16 (diff)
downloadmisskey-034c5d792b47fbc4dda498c73adbdcac6b50c096.tar.gz
misskey-034c5d792b47fbc4dda498c73adbdcac6b50c096.tar.bz2
misskey-034c5d792b47fbc4dda498c73adbdcac6b50c096.zip
fix: streamingテストおそい (#8912)
-rw-r--r--packages/backend/test/streaming.ts1143
-rw-r--r--packages/backend/test/utils.ts6
2 files changed, 395 insertions, 754 deletions
diff --git a/packages/backend/test/streaming.ts b/packages/backend/test/streaming.ts
index f080b71dd4..621d07f9c2 100644
--- a/packages/backend/test/streaming.ts
+++ b/packages/backend/test/streaming.ts
@@ -3,22 +3,12 @@ process.env.NODE_ENV = 'test';
import * as assert from 'assert';
import * as childProcess from 'child_process';
import { Following } from '../src/models/entities/following.js';
-import { connectStream, signup, request, post, startServer, shutdownServer, initTestDb } from './utils.js';
+import { connectStream, signup, api, post, startServer, shutdownServer, initTestDb, waitFire } from './utils.js';
describe('Streaming', () => {
let p: childProcess.ChildProcess;
let Followings: any;
- beforeEach(async () => {
- p = await startServer();
- const connection = await initTestDb(true);
- Followings = connection.getRepository(Following);
- });
-
- afterEach(async () => {
- await shutdownServer(p);
- });
-
const follow = async (follower: any, followee: any) => {
await Followings.save({
id: 'a',
@@ -34,871 +24,522 @@ describe('Streaming', () => {
});
};
- it('mention event', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- const ws = await connectStream(bob, 'main', ({ type, body }) => {
- if (type == 'mention') {
- assert.deepStrictEqual(body.userId, alice.id);
- ws.close();
- done();
- }
- });
-
- post(alice, {
- text: 'foo @bob bar',
- });
- }));
+ describe('Streaming', () => {
+ // Local users
+ let ayano: any;
+ let kyoko: any;
+ let chitose: any;
- it('renote event', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
- const bobNote = await post(bob, {
- text: 'foo',
- });
+ // Remote users
+ let akari: any;
+ let chinatsu: any;
- const ws = await connectStream(bob, 'main', ({ type, body }) => {
- if (type == 'renote') {
- assert.deepStrictEqual(body.renoteId, bobNote.id);
- ws.close();
- done();
- }
- });
+ let kyokoNote: any;
+ let list: any;
- post(alice, {
- renoteId: bobNote.id,
- });
- }));
+ before(async () => {
+ p = await startServer();
+ const connection = await initTestDb(true);
+ Followings = connection.getRepository(Following);
- describe('Home Timeline', () => {
- it('自分の投稿が流れる', () => new Promise(async done => {
- const post = {
- text: 'foo',
- };
+ ayano = await signup({ username: 'ayano' });
+ kyoko = await signup({ username: 'kyoko' });
+ chitose = await signup({ username: 'chitose' });
- const me = await signup();
+ akari = await signup({ username: 'akari', host: 'example.com' });
+ chinatsu = await signup({ username: 'chinatsu', host: 'example.com' });
- const ws = await connectStream(me, 'homeTimeline', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.text, post.text);
- ws.close();
- done();
- }
- });
+ kyokoNote = await post(kyoko, { text: 'foo' });
- request('/notes/create', post, me);
- }));
+ // Follow: ayano => kyoko
+ await api('following/create', { userId: kyoko.id }, ayano);
- it('フォローしているユーザーの投稿が流れる', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
+ // Follow: ayano => akari
+ await follow(ayano, akari);
- // Alice が Bob をフォロー
- await request('/following/create', {
- userId: bob.id,
- }, alice);
+ // List: chitose => ayano, kyoko
+ list = await api('users/lists/create', {
+ name: 'my list',
+ }, chitose).then(x => x.body);
- const ws = await connectStream(alice, 'homeTimeline', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.userId, bob.id);
- ws.close();
- done();
- }
- });
+ await api('users/lists/push', {
+ listId: list.id,
+ userId: ayano.id,
+ }, chitose);
- post(bob, {
- text: 'foo',
- });
- }));
+ await api('users/lists/push', {
+ listId: list.id,
+ userId: kyoko.id,
+ }, chitose);
+ });
- it('フォローしていないユーザーの投稿は流れない', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
+ after(async () => {
+ await shutdownServer(p);
+ });
- let fired = false;
+ describe('Events', () => {
+ it('mention event', async () => {
+ const fired = await waitFire(
+ kyoko, 'main', // kyoko:main
+ () => post(ayano, { text: 'foo @kyoko bar' }), // ayano mention => kyoko
+ msg => msg.type === 'mention' && msg.body.userId === ayano.id // wait ayano
+ );
- const ws = await connectStream(alice, 'homeTimeline', ({ type, body }) => {
- if (type == 'note') {
- fired = true;
- }
+ assert.strictEqual(fired, true);
});
- post(bob, {
- text: 'foo',
- });
+ it('renote event', async () => {
+ const fired = await waitFire(
+ kyoko, 'main', // kyoko:main
+ () => post(ayano, { renoteId: kyokoNote.id }), // ayano renote
+ msg => msg.type === 'renote' && msg.body.renoteId === kyokoNote.id // wait renote
+ );
- setTimeout(() => {
- assert.strictEqual(fired, false);
- ws.close();
- done();
- }, 3000);
- }));
-
- it('フォローしているユーザーのダイレクト投稿が流れる', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- // Alice が Bob をフォロー
- await request('/following/create', {
- userId: bob.id,
- }, alice);
-
- const ws = await connectStream(alice, 'homeTimeline', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.userId, bob.id);
- assert.deepStrictEqual(body.text, 'foo');
- ws.close();
- done();
- }
+ assert.strictEqual(fired, true);
});
+ });
- // Bob が Alice 宛てのダイレクト投稿
- post(bob, {
- text: 'foo',
- visibility: 'specified',
- visibleUserIds: [alice.id],
- });
- }));
-
- it('フォローしているユーザーでも自分が指定されていないダイレクト投稿は流れない', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
- const carol = await signup({ username: 'carol' });
+ describe('Home Timeline', () => {
+ it('自分の投稿が流れる', async () => {
+ const fired = await waitFire(
+ ayano, 'homeTimeline', // ayano:Home
+ () => api('notes/create', { text: 'foo' }, ayano), // ayano posts
+ msg => msg.type === 'note' && msg.body.text === 'foo'
+ );
- // Alice が Bob をフォロー
- await request('/following/create', {
- userId: bob.id,
- }, alice);
+ assert.strictEqual(fired, true);
+ });
- let fired = false;
+ it('フォローしているユーザーの投稿が流れる', async () => {
+ const fired = await waitFire(
+ ayano, 'homeTimeline', // ayano:home
+ () => api('notes/create', { text: 'foo' }, kyoko), // kyoko posts
+ msg => msg.type === 'note' && msg.body.userId === kyoko.id // wait kyoko
+ );
- const ws = await connectStream(alice, 'homeTimeline', ({ type, body }) => {
- if (type == 'note') {
- fired = true;
- }
+ assert.strictEqual(fired, true);
});
- // Bob が Carol 宛てのダイレクト投稿
- post(bob, {
- text: 'foo',
- visibility: 'specified',
- visibleUserIds: [carol.id],
- });
+ it('フォローしていないユーザーの投稿は流れない', async () => {
+ const fired = await waitFire(
+ kyoko, 'homeTimeline', // kyoko:home
+ () => api('notes/create', { text: 'foo' }, ayano), // ayano posts
+ msg => msg.type === 'note' && msg.body.userId === ayano.id // wait ayano
+ );
- setTimeout(() => {
assert.strictEqual(fired, false);
- ws.close();
- done();
- }, 3000);
- }));
- });
-
- describe('Local Timeline', () => {
- it('自分の投稿が流れる', () => new Promise(async done => {
- const me = await signup();
-
- const ws = await connectStream(me, 'localTimeline', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.userId, me.id);
- ws.close();
- done();
- }
});
- post(me, {
- text: 'foo',
+ it('フォローしているユーザーのダイレクト投稿が流れる', async () => {
+ const fired = await waitFire(
+ ayano, 'homeTimeline', // ayano:home
+ () => api('notes/create', { text: 'foo', visibility: 'specified', visibleUserIds: [ayano.id], }, kyoko), // kyoko dm => ayano
+ msg => msg.type === 'note' && msg.body.userId === kyoko.id // wait kyoko
+ );
+
+ assert.strictEqual(fired, true);
});
- }));
- it('フォローしていないローカルユーザーの投稿が流れる', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
+ it('フォローしているユーザーでも自分が指定されていないダイレクト投稿は流れない', async () => {
+ const fired = await waitFire(
+ ayano, 'homeTimeline', // ayano:home
+ () => api('notes/create', { text: 'foo', visibility: 'specified', visibleUserIds: [chitose.id], }, kyoko), // kyoko dm => chitose
+ msg => msg.type === 'note' && msg.body.userId === kyoko.id // wait kyoko
+ );
- const ws = await connectStream(alice, 'localTimeline', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.userId, bob.id);
- ws.close();
- done();
- }
+ assert.strictEqual(fired, false);
});
+ }); // Home
- post(bob, {
- text: 'foo',
- });
- }));
+ describe('Local Timeline', () => {
+ it('自分の投稿が流れる', async () => {
+ const fired = await waitFire(
+ ayano, 'localTimeline', // ayano:Local
+ () => api('notes/create', { text: 'foo' }, ayano), // ayano posts
+ msg => msg.type === 'note' && msg.body.text === 'foo'
+ );
- it('リモートユーザーの投稿は流れない', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob', host: 'example.com' });
+ assert.strictEqual(fired, true);
+ });
- let fired = false;
+ it('フォローしていないローカルユーザーの投稿が流れる', async () => {
+ const fired = await waitFire(
+ ayano, 'localTimeline', // ayano:Local
+ () => api('notes/create', { text: 'foo' }, chitose), // chitose posts
+ msg => msg.type === 'note' && msg.body.userId === chitose.id // wait chitose
+ );
- const ws = await connectStream(alice, 'localTimeline', ({ type, body }) => {
- if (type == 'note') {
- fired = true;
- }
+ assert.strictEqual(fired, true);
});
- post(bob, {
- text: 'foo',
- });
+ it('リモートユーザーの投稿は流れない', async () => {
+ const fired = await waitFire(
+ ayano, 'localTimeline', // ayano:Local
+ () => api('notes/create', { text: 'foo' }, chinatsu), // chinatsu posts
+ msg => msg.type === 'note' && msg.body.userId === chinatsu.id // wait chinatsu
+ );
- setTimeout(() => {
assert.strictEqual(fired, false);
- ws.close();
- done();
- }, 3000);
- }));
-
- it('フォローしてたとしてもリモートユーザーの投稿は流れない', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob', host: 'example.com' });
-
- // Alice が Bob をフォロー
- await request('/following/create', {
- userId: bob.id,
- }, alice);
-
- let fired = false;
-
- const ws = await connectStream(alice, 'localTimeline', ({ type, body }) => {
- if (type == 'note') {
- fired = true;
- }
});
- post(bob, {
- text: 'foo',
- });
+ it('フォローしてたとしてもリモートユーザーの投稿は流れない', async () => {
+ const fired = await waitFire(
+ ayano, 'localTimeline', // ayano:Local
+ () => api('notes/create', { text: 'foo' }, akari), // akari posts
+ msg => msg.type === 'note' && msg.body.userId === akari.id // wait akari
+ );
- setTimeout(() => {
assert.strictEqual(fired, false);
- ws.close();
- done();
- }, 3000);
- }));
-
- it('ホーム指定の投稿は流れない', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- let fired = false;
-
- const ws = await connectStream(alice, 'localTimeline', ({ type, body }) => {
- if (type == 'note') {
- fired = true;
- }
});
- // ホーム指定
- post(bob, {
- text: 'foo',
- visibility: 'home',
- });
+ it('ホーム指定の投稿は流れない', async () => {
+ const fired = await waitFire(
+ ayano, 'localTimeline', // ayano:Local
+ () => api('notes/create', { text: 'foo', visibility: 'home' }, kyoko), // kyoko home posts
+ msg => msg.type === 'note' && msg.body.userId === kyoko.id // wait kyoko
+ );
- setTimeout(() => {
assert.strictEqual(fired, false);
- ws.close();
- done();
- }, 3000);
- }));
-
- it('フォローしているローカルユーザーのダイレクト投稿は流れない', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- // Alice が Bob をフォロー
- await request('/following/create', {
- userId: bob.id,
- }, alice);
-
- let fired = false;
-
- const ws = await connectStream(alice, 'localTimeline', ({ type, body }) => {
- if (type == 'note') {
- fired = true;
- }
});
- // Bob が Alice 宛てのダイレクト投稿
- post(bob, {
- text: 'foo',
- visibility: 'specified',
- visibleUserIds: [alice.id],
- });
+ it('フォローしているローカルユーザーのダイレクト投稿は流れない', async () => {
+ const fired = await waitFire(
+ ayano, 'localTimeline', // ayano:Local
+ () => api('notes/create', { text: 'foo', visibility: 'specified', visibleUserIds: [ayano.id] }, kyoko), // kyoko DM => ayano
+ msg => msg.type === 'note' && msg.body.userId === kyoko.id // wait kyoko
+ );
- setTimeout(() => {
assert.strictEqual(fired, false);
- ws.close();
- done();
- }, 3000);
- }));
-
- it('フォローしていないローカルユーザーのフォロワー宛て投稿は流れない', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- let fired = false;
-
- const ws = await connectStream(alice, 'localTimeline', ({ type, body }) => {
- if (type == 'note') {
- fired = true;
- }
});
- // フォロワー宛て投稿
- post(bob, {
- text: 'foo',
- visibility: 'followers',
- });
+ it('フォローしていないローカルユーザーのフォロワー宛て投稿は流れない', async () => {
+ const fired = await waitFire(
+ ayano, 'localTimeline', // ayano:Local
+ () => api('notes/create', { text: 'foo', visibility: 'followers' }, chitose),
+ msg => msg.type === 'note' && msg.body.userId === chitose.id // wait chitose
+ );
- setTimeout(() => {
assert.strictEqual(fired, false);
- ws.close();
- done();
- }, 3000);
- }));
- });
-
- describe('Hybrid Timeline', () => {
- it('自分の投稿が流れる', () => new Promise(async done => {
- const me = await signup();
-
- const ws = await connectStream(me, 'hybridTimeline', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.userId, me.id);
- ws.close();
- done();
- }
});
+ });
- post(me, {
- text: 'foo',
- });
- }));
-
- it('フォローしていないローカルユーザーの投稿が流れる', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.userId, bob.id);
- ws.close();
- done();
- }
- });
+ describe('Hybrid Timeline', () => {
+ it('自分の投稿が流れる', async () => {
+ const fired = await waitFire(
+ ayano, 'hybridTimeline', // ayano:Hybrid
+ () => api('notes/create', { text: 'foo' }, ayano), // ayano posts
+ msg => msg.type === 'note' && msg.body.text === 'foo'
+ );
- post(bob, {
- text: 'foo',
+ assert.strictEqual(fired, true);
});
- }));
- it('フォローしているリモートユーザーの投稿が流れる', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob', host: 'example.com' });
+ it('フォローしていないローカルユーザーの投稿が流れる', async () => {
+ const fired = await waitFire(
+ ayano, 'hybridTimeline', // ayano:Hybrid
+ () => api('notes/create', { text: 'foo' }, chitose), // chitose posts
+ msg => msg.type === 'note' && msg.body.userId === chitose.id // wait chitose
+ );
- // Alice が Bob をフォロー
- await follow(alice, bob);
-
- const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.userId, bob.id);
- ws.close();
- done();
- }
+ assert.strictEqual(fired, true);
});
- post(bob, {
- text: 'foo',
- });
- }));
-
- it('フォローしていないリモートユーザーの投稿は流れない', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob', host: 'example.com' });
-
- let fired = false;
+ it('フォローしているリモートユーザーの投稿が流れる', async () => {
+ const fired = await waitFire(
+ ayano, 'hybridTimeline', // ayano:Hybrid
+ () => api('notes/create', { text: 'foo' }, akari), // akari posts
+ msg => msg.type === 'note' && msg.body.userId === akari.id // wait akari
+ );
- const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
- if (type == 'note') {
- fired = true;
- }
+ assert.strictEqual(fired, true);
});
- post(bob, {
- text: 'foo',
- });
+ it('フォローしていないリモートユーザーの投稿は流れない', async () => {
+ const fired = await waitFire(
+ ayano, 'hybridTimeline', // ayano:Hybrid
+ () => api('notes/create', { text: 'foo' }, chinatsu), // chinatsu posts
+ msg => msg.type === 'note' && msg.body.userId === chinatsu.id // wait chinatsu
+ );
- setTimeout(() => {
assert.strictEqual(fired, false);
- ws.close();
- done();
- }, 3000);
- }));
-
- it('フォローしているユーザーのダイレクト投稿が流れる', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- // Alice が Bob をフォロー
- await request('/following/create', {
- userId: bob.id,
- }, alice);
-
- const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.userId, bob.id);
- assert.deepStrictEqual(body.text, 'foo');
- ws.close();
- done();
- }
});
- // Bob が Alice 宛てのダイレクト投稿
- post(bob, {
- text: 'foo',
- visibility: 'specified',
- visibleUserIds: [alice.id],
- });
- }));
-
- it('フォローしているユーザーのホーム投稿が流れる', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- // Alice が Bob をフォロー
- await request('/following/create', {
- userId: bob.id,
- }, alice);
-
- const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.userId, bob.id);
- assert.deepStrictEqual(body.text, 'foo');
- ws.close();
- done();
- }
- });
+ it('フォローしているユーザーのダイレクト投稿が流れる', async () => {
+ const fired = await waitFire(
+ ayano, 'hybridTimeline', // ayano:Hybrid
+ () => api('notes/create', { text: 'foo', visibility: 'specified', visibleUserIds: [ayano.id] }, kyoko),
+ msg => msg.type === 'note' && msg.body.userId === kyoko.id // wait kyoko
+ );
- // ホーム投稿
- post(bob, {
- text: 'foo',
- visibility: 'home',
+ assert.strictEqual(fired, true);
});
- }));
-
- it('フォローしていないローカルユーザーのホーム投稿は流れない', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
- let fired = false;
+ it('フォローしているユーザーのホーム投稿が流れる', async () => {
+ const fired = await waitFire(
+ ayano, 'hybridTimeline', // ayano:Hybrid
+ () => api('notes/create', { text: 'foo', visibility: 'home' }, kyoko),
+ msg => msg.type === 'note' && msg.body.userId === kyoko.id // wait kyoko
+ );
- const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
- if (type == 'note') {
- fired = true;
- }
+ assert.strictEqual(fired, true);
});
- // ホーム投稿
- post(bob, {
- text: 'foo',
- visibility: 'home',
- });
+ it('フォローしていないローカルユーザーのホーム投稿は流れない', async () => {
+ const fired = await waitFire(
+ ayano, 'hybridTimeline', // ayano:Hybrid
+ () => api('notes/create', { text: 'foo', visibility: 'home' }, chitose),
+ msg => msg.type === 'note' && msg.body.userId === chitose.id
+ );
- setTimeout(() => {
assert.strictEqual(fired, false);
- ws.close();
- done();
- }, 3000);
- }));
-
- it('フォローしていないローカルユーザーのフォロワー宛て投稿は流れない', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- let fired = false;
-
- const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
- if (type == 'note') {
- fired = true;
- }
});
- // フォロワー宛て投稿
- post(bob, {
- text: 'foo',
- visibility: 'followers',
- });
+ it('フォローしていないローカルユーザーのフォロワー宛て投稿は流れない', () => async () => {
+ const fired = await waitFire(
+ ayano, 'hybridTimeline', // ayano:Hybrid
+ () => api('notes/create', { text: 'foo', visibility: 'followers' }, chitose),
+ msg => msg.type === 'note' && msg.body.userId === chitose.id
+ );
- setTimeout(() => {
assert.strictEqual(fired, false);
- ws.close();
- done();
- }, 3000);
- }));
- });
-
- describe('Global Timeline', () => {
- it('フォローしていないローカルユーザーの投稿が流れる', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- const ws = await connectStream(alice, 'globalTimeline', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.userId, bob.id);
- ws.close();
- done();
- }
- });
-
- post(bob, {
- text: 'foo',
});
- }));
-
- it('フォローしていないリモートユーザーの投稿が流れる', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob', host: 'example.com' });
+ });
- const ws = await connectStream(alice, 'globalTimeline', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.userId, bob.id);
- ws.close();
- done();
- }
- });
+ describe('Global Timeline', () => {
+ it('フォローしていないローカルユーザーの投稿が流れる', () => async () => {
+ const fired = await waitFire(
+ ayano, 'globalTimeline', // ayano:Global
+ () => api('notes/create', { text: 'foo' }, chitose), // chitose posts
+ msg => msg.type === 'note' && msg.body.userId === chitose.id // wait chitose
+ );
- post(bob, {
- text: 'foo',
+ assert.strictEqual(fired, true);
});
- }));
-
- it('ホーム投稿は流れない', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
- let fired = false;
+ it('フォローしていないリモートユーザーの投稿が流れる', () => async () => {
+ const fired = await waitFire(
+ ayano, 'globalTimeline', // ayano:Global
+ () => api('notes/create', { text: 'foo' }, chinatsu), // chinatsu posts
+ msg => msg.type === 'note' && msg.body.userId === chinatsu.id // wait chinatsu
+ );
- const ws = await connectStream(alice, 'globalTimeline', ({ type, body }) => {
- if (type == 'note') {
- fired = true;
- }
+ assert.strictEqual(fired, true);
});
- // ホーム投稿
- post(bob, {
- text: 'foo',
- visibility: 'home',
- });
+ it('ホーム投稿は流れない', () => async () => {
+ const fired = await waitFire(
+ ayano, 'globalTimeline', // ayano:Global
+ () => api('notes/create', { text: 'foo', visibility: 'home' }, kyoko), // kyoko posts
+ msg => msg.type === 'note' && msg.body.userId === kyoko.id // wait kyoko
+ );
- setTimeout(() => {
assert.strictEqual(fired, false);
- ws.close();
- done();
- }, 3000);
- }));
- });
-
- describe('UserList Timeline', () => {
- it('リストに入れているユーザーの投稿が流れる', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- // リスト作成
- const list = await request('/users/lists/create', {
- name: 'my list',
- }, alice).then(x => x.body);
-
- // Alice が Bob をリスイン
- await request('/users/lists/push', {
- listId: list.id,
- userId: bob.id,
- }, alice);
-
- const ws = await connectStream(alice, 'userList', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.userId, bob.id);
- ws.close();
- done();
- }
- }, {
- listId: list.id,
- });
-
- post(bob, {
- text: 'foo',
});
- }));
-
- it('リストに入れていないユーザーの投稿は流れない', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- // リスト作成
- const list = await request('/users/lists/create', {
- name: 'my list',
- }, alice).then(x => x.body);
+ });
- let fired = false;
+ describe('UserList Timeline', () => {
+ it('リストに入れているユーザーの投稿が流れる', () => async () => {
+ const fired = await waitFire(
+ chitose, 'userList',
+ () => api('notes/create', { text: 'foo' }, ayano),
+ msg => msg.type === 'note' && msg.body.userId === ayano.id,
+ { listId: list.id, }
+ );
- const ws = await connectStream(alice, 'userList', ({ type, body }) => {
- if (type == 'note') {
- fired = true;
- }
- }, {
- listId: list.id,
+ assert.strictEqual(fired, true);
});
- post(bob, {
- text: 'foo',
- });
+ it('リストに入れていないユーザーの投稿は流れない', () => async () => {
+ const fired = await waitFire(
+ chitose, 'userList',
+ () => api('notes/create', { text: 'foo' }, chinatsu),
+ msg => msg.type === 'note' && msg.body.userId === chinatsu.id,
+ { listId: list.id, }
+ );
- setTimeout(() => {
assert.strictEqual(fired, false);
- ws.close();
- done();
- }, 3000);
- }));
-
- // #4471
- it('リストに入れているユーザーのダイレクト投稿が流れる', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- // リスト作成
- const list = await request('/users/lists/create', {
- name: 'my list',
- }, alice).then(x => x.body);
-
- // Alice が Bob をリスイン
- await request('/users/lists/push', {
- listId: list.id,
- userId: bob.id,
- }, alice);
-
- const ws = await connectStream(alice, 'userList', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.userId, bob.id);
- assert.deepStrictEqual(body.text, 'foo');
- ws.close();
- done();
- }
- }, {
- listId: list.id,
- });
-
- // Bob が Alice 宛てのダイレクト投稿
- post(bob, {
- text: 'foo',
- visibility: 'specified',
- visibleUserIds: [alice.id],
});
- }));
-
- // #4335
- it('リストに入れているがフォローはしてないユーザーのフォロワー宛て投稿は流れない', () => new Promise(async done => {
- const alice = await signup({ username: 'alice' });
- const bob = await signup({ username: 'bob' });
-
- // リスト作成
- const list = await request('/users/lists/create', {
- name: 'my list',
- }, alice).then(x => x.body);
-
- // Alice が Bob をリスイン
- await request('/users/lists/push', {
- listId: list.id,
- userId: bob.id,
- }, alice);
- let fired = false;
+ // #4471
+ it('リストに入れているユーザーのダイレクト投稿が流れる', () => async () => {
+ const fired = await waitFire(
+ chitose, 'userList',
+ () => api('notes/create', { text: 'foo', visibility: 'specified', visibleUserIds: [chitose.id] }, ayano),
+ msg => msg.type === 'note' && msg.body.userId === ayano.id,
+ { listId: list.id, }
+ );
- const ws = await connectStream(alice, 'userList', ({ type, body }) => {
- if (type == 'note') {
- fired = true;
- }
- }, {
- listId: list.id,
+ assert.strictEqual(fired, true);
});
- // フォロワー宛て投稿
- post(bob, {
- text: 'foo',
- visibility: 'followers',
- });
+ // #4335
+ it('リストに入れているがフォローはしてないユーザーのフォロワー宛て投稿は流れない', () => async () => {
+ const fired = await waitFire(
+ chitose, 'userList',
+ () => api('notes/create', { text: 'foo', visibility: 'followers' }, kyoko),
+ msg => msg.type === 'note' && msg.body.userId === kyoko.id,
+ { listId: list.id, }
+ );
- setTimeout(() => {
assert.strictEqual(fired, false);
- ws.close();
- done();
- }, 3000);
- }));
- });
-
- describe('Hashtag Timeline', () => {
- it('指定したハッシュタグの投稿が流れる', () => new Promise(async done => {
- const me = await signup();
-
- const ws = await connectStream(me, 'hashtag', ({ type, body }) => {
- if (type == 'note') {
- assert.deepStrictEqual(body.text, '#foo');
- ws.close();
- done();
- }
- }, {
- q: [
- ['foo'],
- ],
- });
-
- post(me, {
- text: '#foo',
- });
- }));
-
- it('指定したハッシュタグの投稿が流れる (AND)', () => new Promise(async done => {
- const me = await signup();
-
- let fooCount = 0;
- let barCount = 0;
- let fooBarCount = 0;
-
- const ws = await connectStream(me, 'hashtag', ({ type, body }) => {
- if (type == 'note') {
- if (body.text === '#foo') fooCount++;
- if (body.text === '#bar') barCount++;
- if (body.text === '#foo #bar') fooBarCount++;
- }
- }, {
- q: [
- ['foo', 'bar'],
- ],
- });
-
- post(me, {
- text: '#foo',
- });
-
- post(me, {
- text: '#bar',
- });
-
- post(me, {
- text: '#foo #bar',
});
+ });
- setTimeout(() => {
- assert.strictEqual(fooCount, 0);
- assert.strictEqual(barCount, 0);
- assert.strictEqual(fooBarCount, 1);
- ws.close();
- done();
- }, 3000);
- }));
+ describe('Hashtag Timeline', () => {
+ it('指定したハッシュタグの投稿が流れる', () => new Promise<void>(async done => {
+ const ws = await connectStream(chitose, 'hashtag', ({ type, body }) => {
+ if (type == 'note') {
+ assert.deepStrictEqual(body.text, '#foo');
+ ws.close();
+ done();
+ }
+ }, {
+ q: [
+ ['foo'],
+ ],
+ });
- it('指定したハッシュタグの投稿が流れる (OR)', () => new Promise(async done => {
- const me = await signup();
+ post(chitose, {
+ text: '#foo',
+ });
+ }));
- let fooCount = 0;
- let barCount = 0;
- let fooBarCount = 0;
- let piyoCount = 0;
+ it('指定したハッシュタグの投稿が流れる (AND)', () => new Promise<void>(async done => {
+ let fooCount = 0;
+ let barCount = 0;
+ let fooBarCount = 0;
+
+ const ws = await connectStream(chitose, 'hashtag', ({ type, body }) => {
+ if (type == 'note') {
+ if (body.text === '#foo') fooCount++;
+ if (body.text === '#bar') barCount++;
+ if (body.text === '#foo #bar') fooBarCount++;
+ }
+ }, {
+ q: [
+ ['foo', 'bar'],
+ ],
+ });
+
+ post(chitose, {
+ text: '#foo',
+ });
+
+ post(chitose, {
+ text: '#bar',
+ });
+
+ post(chitose, {
+ text: '#foo #bar',
+ });
+
+ setTimeout(() => {
+ assert.strictEqual(fooCount, 0);
+ assert.strictEqual(barCount, 0);
+ assert.strictEqual(fooBarCount, 1);
+ ws.close();
+ done();
+ }, 3000);
+ }));
- const ws = await connectStream(me, 'hashtag', ({ type, body }) => {
- if (type == 'note') {
- if (body.text === '#foo') fooCount++;
- if (body.text === '#bar') barCount++;
- if (body.text === '#foo #bar') fooBarCount++;
- if (body.text === '#piyo') piyoCount++;
- }
- }, {
- q: [
- ['foo'],
- ['bar'],
- ],
- });
+ it('指定したハッシュタグの投稿が流れる (OR)', () => new Promise<void>(async done => {
+ let fooCount = 0;
+ let barCount = 0;
+ let fooBarCount = 0;
+ let piyoCount = 0;
- post(me, {
- text: '#foo',
- });
+ const ws = await connectStream(chitose, 'hashtag', ({ type, body }) => {
+ if (type == 'note') {
+ if (body.text === '#foo') fooCount++;
+ if (body.text === '#bar') barCount++;
+ if (body.text === '#foo #bar') fooBarCount++;
+ if (body.text === '#piyo') piyoCount++;
+ }
+ }, {
+ q: [
+ ['foo'],
+ ['bar'],
+ ],
+ });
- post(me, {
- text: '#bar',
- });
+ post(chitose, {
+ text: '#foo',
+ });
- post(me, {
- text: '#foo #bar',
- });
+ post(chitose, {
+ text: '#bar',
+ });
- post(me, {
- text: '#piyo',
- });
+ post(chitose, {
+ text: '#foo #bar',
+ });
- setTimeout(() => {
- assert.strictEqual(fooCount, 1);
- assert.strictEqual(barCount, 1);
- assert.strictEqual(fooBarCount, 1);
- assert.strictEqual(piyoCount, 0);
- ws.close();
- done();
- }, 3000);
- }));
+ post(chitose, {
+ text: '#piyo',
+ });
- it('指定したハッシュタグの投稿が流れる (AND + OR)', () => new Promise(async done => {
- const me = await signup();
+ setTimeout(() => {
+ assert.strictEqual(fooCount, 1);
+ assert.strictEqual(barCount, 1);
+ assert.strictEqual(fooBarCount, 1);
+ assert.strictEqual(piyoCount, 0);
+ ws.close();
+ done();
+ }, 3000);
+ }));
- let fooCount = 0;
- let barCount = 0;
- let fooBarCount = 0;
- let piyoCount = 0;
- let waaaCount = 0;
+ it('指定したハッシュタグの投稿が流れる (AND + OR)', () => new Promise<void>(async done => {
+ let fooCount = 0;
+ let barCount = 0;
+ let fooBarCount = 0;
+ let piyoCount = 0;
+ let waaaCount = 0;
- const ws = await connectStream(me, 'hashtag', ({ type, body }) => {
- if (type == 'note') {
- if (body.text === '#foo') fooCount++;
- if (body.text === '#bar') barCount++;
- if (body.text === '#foo #bar') fooBarCount++;
- if (body.text === '#piyo') piyoCount++;
- if (body.text === '#waaa') waaaCount++;
- }
- }, {
- q: [
- ['foo', 'bar'],
- ['piyo'],
- ],
- });
+ const ws = await connectStream(chitose, 'hashtag', ({ type, body }) => {
+ if (type == 'note') {
+ if (body.text === '#foo') fooCount++;
+ if (body.text === '#bar') barCount++;
+ if (body.text === '#foo #bar') fooBarCount++;
+ if (body.text === '#piyo') piyoCount++;
+ if (body.text === '#waaa') waaaCount++;
+ }
+ }, {
+ q: [
+ ['foo', 'bar'],
+ ['piyo'],
+ ],
+ });
- post(me, {
- text: '#foo',
- });
+ post(chitose, {
+ text: '#foo',
+ });
- post(me, {
- text: '#bar',
- });
+ post(chitose, {
+ text: '#bar',
+ });
- post(me, {
- text: '#foo #bar',
- });
+ post(chitose, {
+ text: '#foo #bar',
+ });
- post(me, {
- text: '#piyo',
- });
+ post(chitose, {
+ text: '#piyo',
+ });
- post(me, {
- text: '#waaa',
- });
+ post(chitose, {
+ text: '#waaa',
+ });
- setTimeout(() => {
- assert.strictEqual(fooCount, 0);
- assert.strictEqual(barCount, 0);
- assert.strictEqual(fooBarCount, 1);
- assert.strictEqual(piyoCount, 1);
- assert.strictEqual(waaaCount, 0);
- ws.close();
- done();
- }, 3000);
- }));
+ setTimeout(() => {
+ assert.strictEqual(fooCount, 0);
+ assert.strictEqual(barCount, 0);
+ assert.strictEqual(fooBarCount, 1);
+ assert.strictEqual(piyoCount, 1);
+ assert.strictEqual(waaaCount, 0);
+ ws.close();
+ done();
+ }, 3000);
+ }));
+ });
});
});
diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts
index 0ee15067d1..245cf858d8 100644
--- a/packages/backend/test/utils.ts
+++ b/packages/backend/test/utils.ts
@@ -186,7 +186,7 @@ export function connectStream(user: any, channel: string, listener: (message: Re
});
}
-export const waitFire = async (user: any, channel: string, trgr: () => any, cond: (msg: Record<string, any>) => boolean) => {
+export const waitFire = async (user: any, channel: string, trgr: () => any, cond: (msg: Record<string, any>) => boolean, params?: any) => {
return new Promise<boolean>(async (res, rej) => {
let timer: NodeJS.Timeout;
@@ -198,7 +198,7 @@ export const waitFire = async (user: any, channel: string, trgr: () => any, cond
if (timer) clearTimeout(timer);
res(true);
}
- });
+ }, params);
} catch (e) {
rej(e);
}
@@ -208,7 +208,7 @@ export const waitFire = async (user: any, channel: string, trgr: () => any, cond
timer = setTimeout(() => {
ws.close();
res(false);
- }, 5000);
+ }, 3000);
try {
await trgr();