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

refactor: 테스트 최적화 #867

Merged
merged 48 commits into from
Sep 12, 2024
Merged

Conversation

20HyeonsuLee
Copy link
Contributor

@20HyeonsuLee 20HyeonsuLee commented Sep 3, 2024

🔥 연관 이슈

🚀 작업 내용

  1. 테스트코드 실행 시간 최적화를 진행했습니다.
  2. MockMvc를 이용하여 테스트코드를 작성하였습니다.
  3. @Transactional을 이용한 롤백테스트로 변경하였습니다.
    • 롤백테스트로 변경되었기 때문에 beforeEach로 초기화해주던 테스트데이터를 beforeAll을 이용해서 테스트중 한번만 생성하도록 하였습니다. → beforeEach로 매번 생성하는 비용 감소
  4. 이벤트 발송을 검증할 때 다음과 같이 작성하도록 변경되었습니다.
    • 이벤트는 기본적으로 after_commit시점에 발송됨.
    • 트랜잭션 롤백테스트는 커밋하지 않음. 따라서 이벤트가 발송되지 않음.
    • forceVerify함수에서 강제 커밋해서 이벤트를 발송시킨 후 검증함
    • 강제 커밋했기 때문에 자동으로 롤백되지 않음. → clear하여 db를 초기화 한 후 setup을 실행하여 수동 롤백을 해줘야함.
forceVerify(() -> verify(coopEventListener).onDiningImageUploadRequest(any()));
        clear();
        setUp();
  1. 변경된 테스트를 참고해서 앞으로의 테스트를 작성해주시면 되겠습니다.

맥북 에어 M2 기준 속도

기존 속도

image

개선 속도

image

9/10(화) 주간공유때 전체적으로 한번 설명 드리겠습니다~

💬 리뷰 중점사항

테스트 작성된거 보면서 궁금한점 있으면 질문해주세요~

@20HyeonsuLee 20HyeonsuLee self-assigned this Sep 3, 2024
@github-actions github-actions bot added the 기능 새로운 기능을 개발합니다. label Sep 3, 2024
Copy link

github-actions bot commented Sep 3, 2024

Unit Test Results

274 tests   273 ✔️  1m 0s ⏱️
  30 suites      1 💤
  30 files        0

Results for commit ddcd062.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@duehee duehee left a comment

Choose a reason for hiding this comment

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

양이 완전 많네요.. 트랙장님 대박😮
고생 많으셨습니다! 간단한 코멘트 남겼으니 확인해주세요~

class ActivityApiTest extends AcceptanceTest {

@Autowired
protected ActivityFixture activityFixture;

@Test
@DisplayName("BCSD Lab 활동 내역을 조회한다.")
void getActivities() {
void BCSD_Lab_활동_내역을_조회한다() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

A

테스트 컨벤션이 바뀌겠네요 👀
머지 되면 위키 수정하러 가야겠습니당

Copy link
Member

@Choi-JJunho Choi-JJunho left a comment

Choose a reason for hiding this comment

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

이렇게 많은양을.. 진짜 고생하셨습니다
몇가지 코멘트 남겼으니 확인 부탁드릴게요~

+) 추가로 PR에 속도가 얼마나 개선되었는지 결과를 알려주면 좋을 것 같아요!

  • PC 사양, 이전 속도, 개선 후 속도

@krSeonghyeon krSeonghyeon requested review from krSeonghyeon and removed request for krSeonghyeon September 9, 2024 04:15
Copy link
Collaborator

@daheeParkk daheeParkk left a comment

Choose a reason for hiding this comment

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

코드 양이 많네요.. 고생하셨습니다..!

Copy link
Collaborator

@songsunkook songsunkook left a comment

Choose a reason for hiding this comment

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

엄청나네요.. ㄷㄷ
고생하셨습니다!

Copy link
Collaborator

Choose a reason for hiding this comment

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

A

잘 몰라서 혹시 테스트 최적화와 관련있는 내용인가요?

Comment on lines +119 to +122
void initIncrement() {
dataInitializer.initIncrement();
dataInitializer.clearRedis();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

A

resetAutoIncrement같은 네이밍은 어떤가요? 함수 용도를 유추하기 애매한 것 같아요

Comment on lines +124 to 126
protected void clear() {
dataInitializer.clear();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

A

이것도 어떤 걸 clear하는지 명시하면 좋겠어요 (ex. dbClear)

Comment on lines +128 to +132
protected void forceVerify(Runnable runnable) {
TestTransaction.flagForCommit();
TestTransaction.end();
runnable.run();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

A

이건 어떤 용도인가요?

Comment on lines +33 to +36
@BeforeAll
void setup() {
clear();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

A

@BeforeAllclear()를 호출하는 기준이 있나요? 일부 클래스에는 없는 것 같아서 궁금합니다.

Copy link
Contributor

@dradnats1012 dradnats1012 left a comment

Choose a reason for hiding this comment

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

왕많네요
고생하셨습니당

Copy link
Contributor

@Choon0414 Choon0414 left a comment

Choose a reason for hiding this comment

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

이 많은 양을 다 하셨다니.. 고생하셨습니다.

@20HyeonsuLee 20HyeonsuLee merged commit 76bcbdf into develop Sep 12, 2024
4 checks passed
@20HyeonsuLee 20HyeonsuLee deleted the feature/853-test-optimization branch September 12, 2024 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
기능 새로운 기능을 개발합니다.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

테스트 시간을 단축한다.
8 participants