Skip to content

Commit

Permalink
e2eテストがランダムにコケるのを修正 (#11)
Browse files Browse the repository at this point in the history
* test: e2eテストがCIで失敗していた問題をいくつか修正 (misskey-dev#8642)

* test: indexeddbをテスト毎に初期化するように

* fix: metaが無いときにfetch-metaを同時に呼ぶと死ぬことがある問題を修正

* test: ログイン後のクライアント側処理を待たずにリロードされてログイン出来ないことがあったのを修正

* redisClient.FLUSHDB

* TypeORM 0.2.x

Co-authored-by: iwata <ishowta@gmail.com>
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
  • Loading branch information
3 people authored Dec 1, 2022
1 parent f309fc6 commit a531049
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
16 changes: 13 additions & 3 deletions cypress/integration/basic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
describe('Before setup instance', () => {
beforeEach(() => {
cy.window(win => {
win.indexedDB.deleteDatabase('keyval-store');
});
cy.request('POST', '/api/reset-db').as('reset');
cy.get('@reset').its('status').should('equal', 204);
cy.reload(true);
Expand Down Expand Up @@ -32,6 +35,9 @@ describe('Before setup instance', () => {

describe('After setup instance', () => {
beforeEach(() => {
cy.window(win => {
win.indexedDB.deleteDatabase('keyval-store');
});
cy.request('POST', '/api/reset-db').as('reset');
cy.get('@reset').its('status').should('equal', 204);
cy.reload(true);
Expand Down Expand Up @@ -70,6 +76,9 @@ describe('After setup instance', () => {

describe('After user signup', () => {
beforeEach(() => {
cy.window(win => {
win.indexedDB.deleteDatabase('keyval-store');
});
cy.request('POST', '/api/reset-db').as('reset');
cy.get('@reset').its('status').should('equal', 204);
cy.reload(true);
Expand Down Expand Up @@ -129,6 +138,9 @@ describe('After user signup', () => {

describe('After user singed in', () => {
beforeEach(() => {
cy.window(win => {
win.indexedDB.deleteDatabase('keyval-store');
});
cy.request('POST', '/api/reset-db').as('reset');
cy.get('@reset').its('status').should('equal', 204);
cy.reload(true);
Expand Down Expand Up @@ -163,12 +175,10 @@ describe('After user singed in', () => {
});

it('successfully loads', () => {
cy.visit('/');
cy.get('[data-cy-open-post-form]').should('be.visible');
});

it('note', () => {
cy.visit('/');

cy.get('[data-cy-open-post-form]').click();
cy.get('[data-cy-post-form-text]').type('Hello, Misskey!');
cy.get('[data-cy-open-post-form-submit]').click();
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/db/postgre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const types = require('pg').types;
types.setTypeParser(20, Number);

import { createConnection, Logger, getConnection } from 'typeorm';
import { redisClient } from './redis';
import * as highlight from 'cli-highlight';
import config from '@/config/index';

Expand Down Expand Up @@ -218,6 +219,7 @@ export function initDb(justBorrow = false, sync = false, forceRecreate = false)

export async function resetDb() {
const reset = async () => {
await redisClient.FLUSHDB();
const conn = await getConnection();
const tables = await conn.query(`SELECT relname AS "table"
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
Expand Down
13 changes: 10 additions & 3 deletions packages/backend/src/misc/fetch-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ export async function fetchMeta(noCache = false): Promise<Meta> {
cache = meta;
return meta;
} else {
const saved = await transactionalEntityManager.save(Meta, {
id: 'x',
}) as Meta;
// metaが空のときfetchMetaが同時に呼ばれるとここが同時に呼ばれてしまうことがあるのでフェイルセーフなupsertを使う
const saved = await transactionalEntityManager
.upsert(
Meta,
{
id: 'x',
},
['id'],
)
.then((x) => transactionalEntityManager.findOneOrFail(Meta, x.identifiers[0])) as Meta;

cache = saved;
return saved;
Expand Down

0 comments on commit a531049

Please sign in to comment.