dotkom / monoweb

Future version of Online, NTNU's informatics student association's website
https://web.online.ntnu.no/
MIT License
19 stars 2 forks source link

Improve performance in integration tests #829

Closed henrikskog closed 8 months ago

henrikskog commented 8 months ago

Set up one container at the start of running tests. Instead of starting new containers for each test, do this:

beforeEach(async () => {
  const env = createEnvironment()
  await runMigrations(env)
})

afterEach(async () => {
  const env = createEnvironment()
  await resetTestDatabase(container, env)
})

Note: I added the withReuse() option to the PostgreSqlContainer. I think this should run fine in ci but I'm not 100% sure.

Benchmarks

Before:

 ✓ src/modules/user/__test__/user-service.e2e-spec.ts (4) 35020ms
   ✓ users (4) 35020ms
     ✓ can create new users 9889ms
     ✓ will not allow two users the same subject 8424ms
     ✓ will find users by their user id 8364ms
     ✓ can update users given their id 8342ms

After: Without reusing container

✓ src/modules/user/__test__/user-service.e2e-spec.ts (4) 13469ms
   ✓ users (4) 4478ms
     ✓ can create new users 1239ms
     ✓ will not allow two users the same subject 1089ms
     ✓ will find users by their user id 1084ms
     ✓ can update users given their id 1064ms

With reusing container

 ✓ src/modules/user/__test__/user-service.e2e-spec.ts (4) 4924ms
   ✓ users (4) 4098ms
     ✓ can create new users 838ms
     ✓ will not allow two users the same subject 1098ms
     ✓ will find users by their user id 1105ms
     ✓ can update users given their id 1056ms
linear[bot] commented 8 months ago

DOT-632 Improve performance in integration tests