NodeJS & postgres - How to improve integration testing speed #5
LoganTann
announced in
Faced issues and how I solved them
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context
NestJs is a robust back-end framework for node.js. Jest is the default test framework.
You might test your code via integration tests and a temporary database. The code is tightly coupled to postgres so you can't test using an in-memory database.
Issue faced
Database operations take most of the running time, especially at the cleanup process.
Truncating all tables takes in average 500ms.
Investigation
TRUNCATE
overDELETE
offers greater efficiency.TRUNCATE
query, which is even more efficient than executing multiple truncate queries.Solution
POSTGRES_INITDB_ARGS=--no-sync -c fsync=false -c full_page_writes=false -c synchronous_commit=false
.Manual benchmarks for 13 tests:
Overall : 10x faster !!
--
Tags : nestjs, ts-jest, faster, postgres,
fsync=false
,truncate multiple
Beta Was this translation helpful? Give feedback.
All reactions