-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(seed): run rebuilds in parallel, add perf logs #4334
Open
ThatOneBro
wants to merge
27
commits into
main
Choose a base branch
from
derrick-parallelize-db-seed
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
5bddaac
perf(seed): run rebuilds in parallel, add perf logs
ThatOneBro e0f710a
cleanup: remove stray performance.mark
ThatOneBro f3941d3
feat(server): add both `serial` and `parallel` modes for seed
ThatOneBro 1c424bc
test(seed): split out seed tests, test in parallel to main tests
ThatOneBro ba9eaa8
cleanup(compose): rm stray service
ThatOneBro f98f105
cleanup(package.json): rm stray package
ThatOneBro 6ca8cd1
cleanup(tsconfig): add `seed-tests` dir to tsconfig
ThatOneBro 340ee80
fix(test.sh): make parallel tests fail together
ThatOneBro e5a9888
fix(actions/build): fix `postgres_seed` port
ThatOneBro fb90a1a
test(actions/build): see if hardcoding port works
ThatOneBro b4dfc20
cleanup(coverage): `coverage/seed/{parallel,serial}`
ThatOneBro ec0746b
cleanup(server/test): don't call `docker-compose` in `test` cmd
ThatOneBro 10bc983
test(coverage): add back coverage of `src` to `seed` tests
ThatOneBro 472be29
test(coverage): add exclusions too
ThatOneBro f99b615
fix(tests/seed): do minimal setup in seed tests to actually test seeding
ThatOneBro 7e18ad8
cleanup(sonar): rm unnecessary `as`s, use `??` operator
ThatOneBro dfe2307
refactor(seed): always build promise arr first
ThatOneBro d71b8cd
refactor(seed): move seed tests back into `src`, filter them
ThatOneBro 8369583
docs(server/jest): add comment about weird glob behavior
ThatOneBro 5bdd757
docs(testing): note running `test:seed:parallel` on fresh install
ThatOneBro c13e908
revert(seed): restore separate rebuild paths
ThatOneBro 743060f
test(seed): make serial seed test run migrations before test
ThatOneBro 8080800
chore(package-lock): fix needless updates
ThatOneBro ed4a256
chore(package-lock): actually fix needless updates
ThatOneBro 436298b
test(seed): stop needlessly busting cache
ThatOneBro 8ad3add
test(seed): always bust cache
ThatOneBro 8ef8b4b
tweak(jest): set the default test timeout lower
ThatOneBro File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: '3.7' | ||
services: | ||
postgres-seed: | ||
image: postgres:12 | ||
restart: always | ||
environment: | ||
- POSTGRES_USER=medplum | ||
- POSTGRES_PASSWORD=medplum | ||
|
||
volumes: | ||
- ./postgres/postgres.conf:/usr/local/etc/postgres/postgres.conf | ||
- ./postgres/:/docker-entrypoint-initdb.d/ | ||
command: postgres -c config_file=/usr/local/etc/postgres/postgres.conf | ||
ports: | ||
- '5433:5432' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Config } from 'jest'; | ||
|
||
export default { | ||
testEnvironment: 'node', | ||
testTimeout: 5000, | ||
testSequencer: '<rootDir>/jest.sequencer.js', | ||
transform: { | ||
'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest', | ||
}, | ||
// Oddly, the glob `<rootDir>/src/seed*.test.ts` correctly matches both seed tests in the positive case in `jest.seed.config.ts` | ||
// But `!<rootDir>/src/seed*.test.ts` doesn't match both in the negative case, and only matches `seed-serial.test.ts` | ||
// That's why we use `!**/src/seed*.test.ts` here | ||
testMatch: ['<rootDir>/src/**/*.test.ts', '!**/src/seed*.test.ts'], | ||
moduleFileExtensions: ['ts', 'js', 'json', 'node'], | ||
coverageDirectory: 'coverage', | ||
coverageReporters: ['json', 'text'], | ||
collectCoverageFrom: ['**/src/**/*', '!**/src/__mocks__/**/*.ts', '!**/src/migrations/**/*.ts'], | ||
} satisfies Config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { Config } from 'jest'; | ||
import defaultConfig from './jest.config'; | ||
|
||
export default { | ||
...defaultConfig, | ||
testTimeout: 300000, | ||
testMatch: ['<rootDir>/src/seed*.test.ts'], | ||
collectCoverageFrom: ['<rootDir>/src/**/*', '!**/src/__mocks__/**/*.ts', '!**/src/migrations/**/*.ts'], | ||
} satisfies Config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Project } from '@medplum/fhirtypes'; | ||
import { shutdownApp } from './app'; | ||
import { loadTestConfig } from './config'; | ||
import { AuthenticatedRequestContext, requestContextStore } from './context'; | ||
import { getDatabasePool, initDatabase } from './database'; | ||
import { SelectQuery } from './fhir/sql'; | ||
import { loadStructureDefinitions } from './fhir/structure'; | ||
import { initRedis } from './redis'; | ||
import { seedDatabase } from './seed'; | ||
import { withTestContext } from './test.setup'; | ||
|
||
describe('Seed Serial', () => { | ||
beforeAll(async () => { | ||
console.log = jest.fn(); | ||
|
||
const config = await loadTestConfig(); | ||
config.database.port = process.env['POSTGRES_SEED_PORT'] | ||
? Number.parseInt(process.env['POSTGRES_SEED_PORT'], 10) | ||
: 5433; | ||
// Keep Redis separate so caches between main test suite and this are separate | ||
config.redis.db = 8; | ||
config.database.runMigrations = true; | ||
|
||
// We load the minimal required to get things running so this actually tests seeding the database | ||
return withTestContext(() => | ||
requestContextStore.run(AuthenticatedRequestContext.system(), async () => { | ||
loadStructureDefinitions(); | ||
initRedis(config.redis); | ||
await initDatabase(config); | ||
}) | ||
); | ||
}); | ||
|
||
afterAll(async () => { | ||
await shutdownApp(); | ||
}); | ||
|
||
test('Seeder completes successfully -- serial version', async () => { | ||
// First time, seeder should run | ||
await seedDatabase({ parallel: false }); | ||
|
||
// Make sure the first project is a super admin | ||
const rows = await new SelectQuery('Project') | ||
.column('content') | ||
.where('name', '=', 'Super Admin') | ||
.execute(getDatabasePool()); | ||
expect(rows.length).toBe(1); | ||
|
||
const project = JSON.parse(rows[0].content) as Project; | ||
expect(project.superAdmin).toBe(true); | ||
expect(project.strictMode).toBe(true); | ||
|
||
// Second time, seeder should silently ignore | ||
await seedDatabase({ parallel: false }); | ||
}, 240000); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would
||
actually be preferable here to guard againstconfig.emailProvider === ''
?