Github Actions에서 Minitest 병렬 테스트를 실행하는 방법
Minitest 테스트에 수십 분이 걸리고 Ruby 엔지니어링 팀의 시간을 절약하고 싶다면 CI 서버에서 테스트 병렬화를 사용할 수 있습니다.
가능한 한 빨리 테스트를 실행하려면 테스트를 동일한 버킷(병렬 작업)으로 분할해야 합니다. 하지만 어떻게 해야 할까요? 일부 테스트 파일은 매우 빠르게 실행될 수 있고 다른 Minitest 파일은 시스템 테스트(E2E 테스트)를 실행하는 경우 몇 분 정도 걸릴 수 있습니다.
각 병렬 작업에 대한 테스트 환경을 준비하는 측면도 있습니다. 준비한다는 것은 저장소를 복제하거나 루비 보석을 설치하거나 캐시에서 로드해야 한다는 것을 의미합니다. 도커 컨테이너를 로드해야 할 수도 있습니다. 이는 각 병렬 작업에서 다양한 시간이 걸릴 수 있습니다. load cached gems에 대한 네트워크 지연과 같은 임의의 네트워크 오류가 발생하거나 때때로 Github 작업이 다른 작업에 비해 작업 중 하나를 늦게 시작할 수 있습니다. 이는 네트워크 환경에서 불가피한 문제이며 각 병렬 작업에서 테스트가 다른 시간 동안 실행되도록 할 수 있습니다. 이는 아래 그래프에서 볼 수 있으며 이로 인해 CI 빌드 속도가 느려집니다.

완벽한 시나리오에서는 각 병렬 작업에 대한 테스트가 비슷한 시간에 완료되도록 보장하는 방식으로 Minitest 작업을 병렬 작업으로 분할할 수 있는 것과 상관없이 이러한 모든 문제를 다루고 싶습니다. 이렇게 하면 병목 현상이 발생하지 않습니다. 완벽한 테스트 분할은 아래 그래프에 있습니다.

대기열 모드를 사용하여 동적으로 테스트 분할
Knapsack Pro 대기열 모드를 사용하여 병렬 작업 간에 동적으로 테스트를 분할할 수 있습니다. 이렇게 하면 대기열이 비워질 때까지 각 작업이 대기열에서 테스트를 소비합니다. 간단히 말해 CI 서버 리소스를 효율적으로 활용하고 최적의 시간에 테스트를 실행할 수 있습니다.
나는 how Queue Mode splits Ruby and JavaScript tests in parallel with a dynamic test suite split을 설명했다. 그 기사에서 그것에 대해 배울 수 있습니다.
병렬 테스트를 실행하기 위한 Github Actions 빌드 매트릭스
Github Actions에는 동시에 많은 작업을 실행할 수 있는 build matrix feature이 있습니다. 이를 사용하여 병렬 작업 간에 Minitest 테스트를 실행할 수 있습니다.
아래는 Rails 프로젝트 및 Minitest에 대한 전체 Github Actions YML 구성입니다.
테스트는
knapsack_pro
Ruby gem 및 대기열 모드로 분할됩니다.name: Main
on: [push]
jobs:
test:
runs-on: ubuntu-latest
# If you need DB like PostgreSQL, Redis then define service below.
# https://github.com/actions/example-services/tree/master/.github/workflows
services:
postgres:
image: postgres:10.8
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ""
POSTGRES_DB: postgres
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
# tmpfs makes DB faster by using RAM
options: >-
--mount type=tmpfs,destination=/var/lib/postgresql/data
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis
ports:
- 6379:6379
options: --entrypoint redis-server
# https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
strategy:
fail-fast: false
matrix:
# Set N number of parallel jobs you want to run tests on.
# Use higher number if you have slow tests to split them on more parallel jobs.
# Remember to update ci_node_index below to 0..N-1
ci_node_total: [8]
# set N-1 indexes for parallel jobs
# When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc
ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7]
env:
RAILS_ENV: test
PGHOST: localhost
PGUSER: postgres
# Rails verifies Time Zone in DB is the same as time zone of the Rails app
TZ: "Europe/Warsaw"
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
# Not needed with a .ruby-version file
ruby-version: 2.7
# runs 'bundle install' and caches installed gems automatically
bundler-cache: true
- name: Create DB
run: |
bin/rails db:prepare
- name: Run tests
env:
KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST }}
KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }}
KNAPSACK_PRO_FIXED_QUEUE_SPLIT: true
KNAPSACK_PRO_LOG_LEVEL: info
run: |
bundle exec rake knapsack_pro:queue:minitest
요약
보시다시피 느린 Minitest 테스트 스위트는 문제가 될 필요가 없습니다. QA, 테스터 또는 자동화 엔지니어는 CI 빌드 속도를 개선하고 소프트웨어 개발자 팀이 제품을 더 빨리 제공할 수 있도록 하는 이점을 얻을 수 있습니다. 자세한 내용은 Knapsack Pro에서 확인할 수 있습니다.
Reference
이 문제에 관하여(Github Actions에서 Minitest 병렬 테스트를 실행하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/arturt/how-to-run-minitest-parallel-tests-on-github-actions-bmd텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)