feat(be): implement transaction rollback in unit test#1562
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Jaehyeon1020
approved these changes
Mar 18, 2024
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Close #1561
Backend Unit Test에서 Transaction Rollback을 이용하는 기능을 구현했습니다.
Additional context
prisma.service.ts에 있는PrismaServiceClass를GroupService에 주입하는 대신, 새로 만든transaction.extension.ts의 transactionextension을 PrismaClient에 extend하여서, extended된 PrismaClient를PrismaService에 주입했습니다. 이를 이용해 transaction client를 unit test 상에서 구현했습니다.트랜잭션_클라이언트.$commit(),트랜잭션_클라이언트.$rollback()을 통해, Transaction 커밋과 롤백을 이용할 수 있습니다.상기 mocha hook이 local에서는 default timeout setting인 2000ms를 무리 없이 통과하는데요, github action에서는 2000ms 넘겨서 CI 테스트를 통과하지 못했었습니다.
그래서
this.timeout(0)를 넣어서 timeout에 걸리지 않게 했습니다. (0으로 설정하면 disable됨)tx = await prisma.$begin()이 부분때문에 약간의 병목이 생긴 것인지는 확실치 않으나, 나름의 최적화 여지가 있을 것 같습니다.#1257 PR과 관련이 있습니다.
transactionExtension은 prisma/prisma-client-extensions#47을 참고하여 작성했습니다.Before submitting the PR, please make sure you do the following
fixes #123).