Skip to content

Commit

Permalink
Revert "Int test changes (#5945)"
Browse files Browse the repository at this point in the history
This reverts commit ab04929.
  • Loading branch information
gc authored Jul 7, 2024
1 parent ab04929 commit 88417a0
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TZ="UTC"
ROBOCHIMP_DATABASE_URL="postgresql://postgres:postgres@localhost:5435/robochimp_integration_test?connection_limit=500&pool_timeout=0&schema=public"
DATABASE_URL="postgresql://postgres:postgres@localhost:5435/osb_integration_test?connection_limit=500&pool_timeout=0&schema=public"
ROBOCHIMP_DATABASE_URL=postgresql://postgres:postgres@localhost:5436/robochimp_integration_test?connection_limit=1000&pool_timeout=0
DATABASE_URL=postgresql://postgres:postgres@localhost:5435/osb_integration_test?connection_limit=1000&pool_timeout=0
CLIENT_ID=111398433321891634
BOT_TOKEN=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
TEST=true
7 changes: 5 additions & 2 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:

- name: Checkout Project
uses: actions/checkout@v4
- run: corepack enable && corepack install
- run: corepack enable
- run: corepack install
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v4
with:
Expand All @@ -40,6 +41,8 @@ jobs:
run: |
pushd src &&
cp config.example.ts config.ts &&
popd && cp .env.test .env
popd
- name: Copy env
run: cp .env.test .env
- name: Test
run: yarn test:integration
15 changes: 7 additions & 8 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ jobs:
steps:
- name: Checkout Project
uses: actions/checkout@v4
- run: corepack enable && corepack install
- run: corepack enable
- run: corepack install
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v4
with:
Expand All @@ -37,14 +38,12 @@ jobs:
run: |
pushd src &&
cp config.example.ts config.ts &&
popd && cp .env.test .env
- name: Generate Prisma Clients
run: yarn gen
popd
- name: Copy env
run: cp .env.test .env
- name: Build
run: yarn build:tsc
run: yarn build --clean
- name: Test
run: |
yarn test:unit
yarn test:lint
tsc -p tests/integration && tsc -p tests/unit
yarn test
npm i -g dpdm && dpdm --exit-code circular:1 --progress=false --warning=false --tree=false ./dist/index.js
27 changes: 25 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
version: "3.9"

services:
osb:
image: postgres:16-alpine
command: -c 'max_connections=1000'
restart: always
container_name: osb_database
ports:
- "5435:3001"
- "5435:1234"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
PGPORT: 3001
POSTGRES_DB: osb_integration_test
PGPORT: 1234

robochimp:
image: postgres:16-alpine
command: -c 'max_connections=1000'
restart: always
container_name: robochimp_database
ports:
- "5436:1235"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: robochimp_integration_test
PGPORT: 1235

redis:
image: redis:alpine
restart: always
container_name: redis
ports:
- "6379:6379"
2 changes: 2 additions & 0 deletions src/lib/util/getOSItem.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import '../data/trophies';

import { getItem, getItemOrThrow } from 'oldschooljs/dist/util/util';

export { getItem, getItemOrThrow as getOSItem };
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/integration-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ async function main() {
execSync('docker compose up -d --wait', { stdio: 'inherit' });
stopwatch.check('Docker compose finished.');

await sleep(500);
await sleep(3000);
stopwatch.check('Finished waiting.');

const env = { ...process.env, ...config({ path: path.resolve('.env.test') }).parsed };
execSync('yarn prisma db push --schema="./prisma/schema.prisma"', { stdio: 'inherit', env });
Expand All @@ -31,7 +32,6 @@ async function main() {
console.log(`Finished run ${i + 1}/${runs}`);
}
} catch (err) {
console.log(execSync('docker-compose logs', { encoding: 'utf-8' }));
console.error(err);
throw new Error(err as any);
} finally {
Expand Down
16 changes: 9 additions & 7 deletions tests/integration/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import '../globalSetup';

import { Image } from '@napi-rs/canvas';
import { noOp } from 'e';
import { afterAll, beforeAll, beforeEach, vi } from 'vitest';
import { afterEach, beforeEach, vi } from 'vitest';

import { BankImageTask, bankImageTask } from '../../src/lib/bankImage';

Expand Down Expand Up @@ -57,12 +57,8 @@ BankImageTask.prototype.generateBankImage = mockBankImageTask.generateBankImage;
BankImageTask.prototype.getItemImage = mockBankImageTask.getItemImage;
BankImageTask.prototype.fetchAndCacheImage = mockBankImageTask.fetchAndCacheImage;

beforeAll(async () => {
await prisma.$connect();
await prisma.$queryRaw`CREATE EXTENSION IF NOT EXISTS intarray;`.catch(noOp);
});

beforeEach(async () => {
await prisma.$connect();
global.bankImageGenerator = mockBankImageTask as any;
BankImageTask.prototype.init = mockBankImageTask.init;
BankImageTask.prototype.run = mockBankImageTask.init;
Expand All @@ -71,6 +67,12 @@ beforeEach(async () => {
BankImageTask.prototype.fetchAndCacheImage = mockBankImageTask.fetchAndCacheImage;
});

afterAll(async () => {
afterEach(async () => {
await prisma.$disconnect();
});

async function init() {
await prisma.$queryRaw`CREATE EXTENSION IF NOT EXISTS intarray;`.catch(noOp);
}

init();
6 changes: 3 additions & 3 deletions vitest.integration.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export default defineConfig({
testTimeout: 30_000,
bail: 1,
pool: 'threads',
maxConcurrency: 10,
maxConcurrency: 30,
poolOptions: {
threads: {
maxThreads: 5,
minThreads: 5
maxThreads: 30,
minThreads: 10
}
}
}
Expand Down

0 comments on commit 88417a0

Please sign in to comment.