Skip to content
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

test: Added tests #27

Merged
merged 3 commits into from
Jan 2, 2025
Merged

Conversation

koreanMike513
Copy link
Collaborator

말씀하신 부분에 대해 test 를 진행해보았습니다.

가장 애를 먹었던 건 동시성 테스트였습니다.

  • PR에 올라온 하나의 테스트와 더불어서 동시에 여러가지 test를 진행하려고 했을 때 @beforeeach annotation이 붙은 foodRepository.saveAndFlush(dummyFood); 에서 동시성 문제가 일어나는 것을 확인했습니다.

  • 이를 해결하기 위해

    • FoodRepository를 extend 하여 따로 비관적 락을 적용하여 save하려 했으나 deleteAll()에서 cascade에서 문제가 생겨 실패
    • Food entity 를 상속하여 @Version 적용 후 실패
      등등 을 시도해보았지만 다 실패하였습니다..

결론적으로 한 파일에 다 테스트를 놓는 것 보다 따로 다른 test file을 만들어서 동시성을 검증하는 게 낫다는 결론에 이르렀습니다.
혹시 죄송하지만 근본적인 해결방법에 대한 아이디어가 있으시다면 여쭤봐도 될까요?

- added Currency to Food entity
- added currency parameter to the apply() method in Voucher
- updated Order entity's apply() method
- updated Payment entity's annotations and import statements
- updated OrderService after changes
- added the Order, Voucher tests
- added the synchronisation test
- added application.yml for the test profile
@koreanMike513 koreanMike513 added enhancement New feature or request question Further information is requested labels Dec 29, 2024
@koreanMike513 koreanMike513 self-assigned this Dec 29, 2024
Copy link

@f-lab-troy f-lab-troy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

말씀하신 saveAndFlush에서의 동시성 문제가 어떤 것인지 명확하게 이해가 어렵습니다.
동시의 여러스레드에서 테스트 진행시 deleteAll이 문제를 발생 시키는 것이라면 동시성 문제라기보다 실제 사용자에게서 발생할 수 없는 테스트 logic상의 문제일 수 있습니다.
멘토링때 코드를 보며 논의해보도록 하겠습니다.

@koreanMike513 koreanMike513 force-pushed the update/update-entities branch from 1fba7b5 to 9d6aac6 Compare January 2, 2025 11:29
@koreanMike513 koreanMike513 merged commit ca2de6e into update/update-entities Jan 2, 2025
1 check passed
@koreanMike513 koreanMike513 deleted the test/added-tests branch January 9, 2025 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants