-
Notifications
You must be signed in to change notification settings - Fork 0
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
[REFACTOR/#174] MemberService 로직 리팩 및 회원가입 테스트 코드 작성 #176
Conversation
- 회원가입시 동일한 이메일로 사용자가 동시에 가입할 경우에 대한 테스트 진행했습니다.
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.
동시성 문제에 대해서 검증한다는건 아예 생각도 못하고 있었는데 정윤님 코드 보고 다양한 상황에서의 문제점을 고민해야겠다고 느꼈습니다. 멀티쓰레드로 테스트 작성하신 것도 좋구요!
이번에 레포지토리 레이어의 통합테스트를 잘 작성해주셨는데 서비스 레이어를 테스트 할 때는 회의 때 얘기해주신 퍼싸드 패턴이 도입되면 좋을 것 같아요. 필요하지 않은 시점에 무리하게 코드를 수정하지 않으신 것도 좋네요.
고생 많으셨어요👍
@@ -23,7 +23,7 @@ | |||
@Entity | |||
@Getter | |||
@Builder | |||
@NoArgsConstructor(access = PROTECTED) | |||
@NoArgsConstructor |
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.
이부분 protected 접근제어는 왜 제거된건가요?
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.
엇 이거 다시 추가해놀을게요!!
// memberRepository.findByEmail(memberSignUpReqDto.getEmail()) | ||
// .ifPresent( | ||
// existingMember -> { | ||
// throw new RestApiException(USER_ALREADY_EXISTS); | ||
// } | ||
// ); |
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.
사용하지 않는 코드라면 지워주세요!!
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@DataJpaTest |
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.
해당 테스트를 DataJpaTest로 실행하신 이유가 있나요?
SpringBootTest와의 차이점이 내부 트랜잭션 유무라고 알고있는데, 멀티쓰레드 코드가 의도대로 동작하는지 궁금해서요..!!
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.
헙 해당 테스트가 데이터 엑세스 레이어(repository)에 대한 테스트여서, SpringBootTest에 비해 가벼운 DataJpaTest를 사용했는데
트랜잭션 관련 부분은 미쳐 생각을 못했네요...! 해당 부분 좀 더 테스트 해보고 제가 오늘 회의때 공유하겠습니다!!
완젼 놓친 부분 찦어주셔서 감사해요오😊
- 실수로 지웠던 접근제어자 추가했습니다.
📄 Work Description
⚙️ ISSUE
📷 Screenshot
💬 To Reviewers
✅ 1. MemberService 코드 리팩 진행했습니다.
✅ 2. 동일한 이메일로 사용자가 동시에 가입할 경우, 하나의 계정만 생성되는지에 대한 테스트코드를 작성했습니다.
AS-IS
Exception
이 발생했을 때 예외처리를 해주면 될 것이라고 생각하였습니다.)TO-BE
Member
엔티티의email
필드에unique
제약조건을 추가했습니다.MoeMoe-Server/src/main/java/com/favoriteplace/app/member/domain/Member.java
Lines 46 to 47 in a441dbe
동시다발적으로 회원가입 메서드를 수행시키기 위해 비동기 로직을 수행하는 java.util.concurrent 에 위치하는
ExecutorService
를 사용하여, 3개의 스레드가 병렬적으로 실행되는 환경을 구성했습니다.MoeMoe-Server/src/test/java/com/favoriteplace/app/repository/MemberRepositoryTest.java
Lines 44 to 47 in a441dbe
추가적으로 알게 된 사실
unique
제약 조건을 추가하면, mysql 기준으로Unique index
을 자동으로 설정해준다고 해요! 그래서select
쿼리가 나가면full-scan
대신Unique Index
를 통해 조회하게 되어 성능이 유의미하게 향상된다고 합니다!! 요건 성능테스트로 확실히 테스트 해봐도 좋을 것 같아욥 ㅎㅎ. -> 관련해서는 블로그 링크 첨부해둘게여ㅕ🔗 Reference
https://kth990303.tistory.com/451