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/#209] 테스트 컨테이너 및 액션 개선 #327

Merged
merged 14 commits into from
Aug 8, 2024

Conversation

belljun3395
Copy link
Collaborator

@belljun3395 belljun3395 commented Aug 8, 2024

🎫 연관 이슈

resolved: #209

💁‍♂️ PR 내용

  • 테스트 컨테이너 및 액션 개선

🙏 작업

  • 모듈별 테스트 컨테이너가 한번만 동작하도록 수정
  • validate-test 액션에서 각 모듈의 테스트가 병렬적으로 수행될 수 있도록 수정 -> 전체적인 액션 완료 속도에는 영향이 적지만 추후 실패한 테스트만 별도로 다시 수행 시킬 수 있다는 장점이 있습니다.

🙈 PR 참고 사항

📸 스크린샷

스크린샷 2024-08-08 오후 4 24 36

스크린샷 2024-08-08 오후 4 23 04

1m 18s -> 1m 5s
미미하지만 개선.. 하였습니다.

컨테이너가 한번만 떠야 환경을 위한 도커도 한번만 떠서 개선하였습니다.!

🤖 테스트 체크리스트

  • 체크 미완료
  • 체크 완료

@github-actions github-actions bot added the refactor 기존 기능에 대해 개선할 때 사용됩니다. label Aug 8, 2024
@belljun3395 belljun3395 force-pushed the refactor/#209_belljun3395 branch 5 times, most recently from 6050fad to be97c6a Compare August 8, 2024 08:46
@belljun3395 belljun3395 changed the title [WIP][Refactor/#209] 테스트 컨테이너 개선 [WIP][Refactor/#209] 테스트 컨테이너 및 액션 개선 Aug 8, 2024

- name: Test with Gradle
run: |
./gradlew --info test
./gradlew test -parallel
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

전체 테스트를 수행하는 경우에는 병렬로 실행할 수 있도록 -parallel 옵션 추가하였습니다.

Copy link
Member

Choose a reason for hiding this comment

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

오 이거 ㄹㅇ 굳굳

Comment on lines +39 to +57
- name: Cache Api Repo Jooq
uses: actions/cache@v3
with:
path: |
./api-repo/src/generated
./api-repo/src/main/resources/db/migration
key: ${{ runner.os }}-api-repo-jooq-${{ hashFiles('./api-repo/src/generated/**', './api-repo/src/main/resources/db/migration/**') }}
restore-keys: |
${{ runner.os }}-api-repo-jooq-

- name: Cache Batch Jooq
uses: actions/cache@v3
with:
path: |
./batch/src/generated
./batch/src/main/resources/db/migration
key: ${{ runner.os }}-batch-jooq-${{ hashFiles('./batch/src/generated/**', './batch/src/main/resources/db/migration/**') }}
restore-keys: |
${{ runner.os }}-batch-jooq-
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

jooq 관련 파일을 캐싱합니다.

restore-keys: |
${{ runner.os }}-batch-jooq-

api-test:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

아래 각각의 모듈 별로 필요한 캐싱된 값을 받아 테스트를 수행합니다.

- "13306:3306"
- "33306:3306"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

로컬 환경이 켜져있어도 테스트 수행할 수 있고
병렬로 테스트 수행하기 위해 포트를 변경해주었습니다.
-> 모듈별로 독립된 포트로

Copy link
Member

Choose a reason for hiding this comment

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

이제 로컬에서 디비 컨태이너를 내리지 않고도 테스트가 가능하겠네요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네!!😃

Comment on lines 50 to 69
/** Common */
@Autowired
lateinit var apiControllerExceptionHandler: ApiControllerExceptionHandler

@Autowired
lateinit var objectMapper: ObjectMapper

lateinit var webTestClient: WebTestClient

@Autowired
lateinit var mockMvc: MockMvc

@MockBean
lateinit var tokenResolver: TokenResolver

/** AdminControllerTest */
@Autowired
lateinit var adminController: AdminController

@MockBean
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

부모 테스트 클래스를 가지고 있어도
자식 클래스에 @MockBean이 들어가면 컨텍스트가 달라져 컨테이너가 다시 뜨는 문제가 있었어요!

그래서 @MockBean 클래스를 부모 클래스에서 주입 받도록 수정하였고
그김에 공통으로 사용하는 클래스 역시 부모 클래스에서 한번에 주입 받도록 수정하였습니다.

우선 수정은 하였는데 자세한 것은 추후 보충해서 공유할께요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

https://youtu.be/N06UeRrWFdY?si=Exobuxb1xFS0NGoM

요 영상을 참고해서 수정하였어요!

Copy link
Member

Choose a reason for hiding this comment

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

나중에 mockmvc만 사용하도록 바꾸는거 어때요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

요건 다른 pr로 진행할께요

@belljun3395 belljun3395 changed the title [WIP][Refactor/#209] 테스트 컨테이너 및 액션 개선 [Refactor/#209] 테스트 컨테이너 및 액션 개선 Aug 8, 2024
Copy link
Member

@hun-ca hun-ca left a comment

Choose a reason for hiding this comment

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

많이 개선되었네요👍🏻

@belljun3395 belljun3395 merged commit 7e1c21a into dev Aug 8, 2024
8 checks passed
belljun3395 added a commit that referenced this pull request Aug 9, 2024
* [Fix/#322] 멤버 구독 정보 조회 수정 (#323)

* [#325/Refactor] Validate Test 동작 조건 수정 (#326)

* [#321/Fix] 완료된 구독 기록을 갱신하는 문제 해결 (#324)

* [Refactor/#209] 테스트 컨테이너 및 액션 개선 (#327)

* [Fix/#333] main-dev 연결을 위한 이슈 (#334)

* [Fix/#333] main-dev 연결을 위한 이슈 v2

---------

Co-authored-by: 지훈 <hun.ca.dev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor 기존 기능에 대해 개선할 때 사용됩니다.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

테스트 컨테이너 개선
2 participants