spec(backend/notes/create): ネットワーク不安定・高負荷時ノートが重複して投稿される問題を修正 (MisskeyIO#432)

This commit is contained in:
まっちゃとーにゅ
2024-02-11 04:02:34 +09:00
committed by GitHub
parent f07a701418
commit 43ef9ca4e2
6 changed files with 51 additions and 6 deletions

View File

@@ -13,6 +13,7 @@ import {
failedApiCall,
post,
role,
sendEnvUpdateRequest,
signup,
successfulApiCall,
testPaginationConsistency,
@@ -74,6 +75,8 @@ describe('アンテナ', () => {
let userMutedByAlice: User;
beforeAll(async () => {
await sendEnvUpdateRequest({ key: 'FORCE_IGNORE_IDEMPOTENCY_FOR_TESTING', value: 'true' });
root = await signup({ username: 'root' });
alice = await signup({ username: 'alice' });
alicePost = await post(alice, { text: 'test' });

View File

@@ -8,7 +8,7 @@ process.env.NODE_ENV = 'test';
import * as assert from 'assert';
import { MiNote } from '@/models/Note.js';
import { MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import { api, initTestDb, post, signup, uploadFile, uploadUrl } from '../utils.js';
import { api, initTestDb, post, sendEnvUpdateRequest, signup, uploadFile, uploadUrl } from '../utils.js';
import type * as misskey from 'misskey-js';
describe('Note', () => {
@@ -19,6 +19,8 @@ describe('Note', () => {
let tom: misskey.entities.SignupResponse;
beforeAll(async () => {
await sendEnvUpdateRequest({ key: 'FORCE_IGNORE_IDEMPOTENCY_FOR_TESTING', value: 'true' });
const connection = await initTestDb(true);
Notes = connection.getRepository(MiNote);
alice = await signup({ username: 'alice' });

View File

@@ -6,7 +6,7 @@
process.env.NODE_ENV = 'test';
import * as assert from 'assert';
import { api, post, signup, sleep, waitFire } from '../utils.js';
import { api, post, sendEnvUpdateRequest, signup, sleep, waitFire } from '../utils.js';
import type * as misskey from 'misskey-js';
describe('Renote Mute', () => {
@@ -16,6 +16,8 @@ describe('Renote Mute', () => {
let carol: misskey.entities.SignupResponse;
beforeAll(async () => {
await sendEnvUpdateRequest({ key: 'FORCE_IGNORE_IDEMPOTENCY_FOR_TESTING', value: 'true' });
alice = await signup({ username: 'alice' });
bob = await signup({ username: 'bob' });
carol = await signup({ username: 'carol' });

View File

@@ -8,7 +8,7 @@ process.env.NODE_ENV = 'test';
import * as assert from 'assert';
import { WebSocket } from 'ws';
import { MiFollowing } from '@/models/Following.js';
import { api, createAppToken, initTestDb, port, post, signup, waitFire } from '../utils.js';
import { api, createAppToken, initTestDb, port, post, sendEnvUpdateRequest, signup, waitFire } from '../utils.js';
import type * as misskey from 'misskey-js';
describe('Streaming', () => {
@@ -46,6 +46,8 @@ describe('Streaming', () => {
let list: any;
beforeAll(async () => {
await sendEnvUpdateRequest({ key: 'FORCE_IGNORE_IDEMPOTENCY_FOR_TESTING', value: 'true' });
const connection = await initTestDb(true);
Followings = connection.getRepository(MiFollowing);

View File

@@ -12,11 +12,12 @@ import WebSocket, { ClientOptions } from 'ws';
import fetch, { File, RequestInit } from 'node-fetch';
import { DataSource } from 'typeorm';
import { JSDOM } from 'jsdom';
import * as Redis from 'ioredis';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
import { entities } from '../src/postgres.js';
import { loadConfig } from '../src/config.js';
import type * as misskey from 'misskey-js';
import { Packed } from '@/misc/json-schema.js';
import { entities } from '@/postgres.js';
import { loadConfig } from '@/config.js';
import type * as misskey from 'misskey-js';
export { server as startServer, jobQueue as startJobQueue } from '@/boot/common.js';
@@ -584,6 +585,9 @@ export async function testPaginationConsistency<Entity extends { id: string, cre
export async function initTestDb(justBorrow = false, initEntities?: any[]) {
if (process.env.NODE_ENV !== 'test') throw new Error('NODE_ENV is not a test');
const redis = new Redis.Redis(config.redis);
await redis.flushdb();
const db = new DataSource({
type: 'postgres',
host: config.db.host,