22
17

More than 5 years have passed since last update.

test-queueを使って、rspecのテストを高速化

Last updated at Posted at 2015-03-23

test-queueとは?

  • テストを同時に実行するgem
  • rspecやtestunitに対応
  • parallel_testsやrrrspecのように、専用のDBやクライアントは不要(なのでテスト対象に変更が入らないのが嬉しい)
  • 実際のテストでは20分かかっていたのを、3分に短縮できた

インストール

$ gem install test-queue

実行

$ rspec-queue spec

  • rspec -> rspec-queueにするだけなので簡単
  • デフォルトの同時実行数はCPUのコア数
  • 同時実行数を指定したい場合は、TEST_QUEUE_WORKERSを使う
    $ TEST_QUEUE_WORKERS=4 rspec-queue spec

実行結果

Run options:
Starting test-queue master (/tmp/test_queue_25534_206036260.sock)

==> Summary (4 workers in 295.0616s)

    [ 3]       650 examples, 0 failures    8 suites in 277.5766s      (pid 25545 exit 0)
    [ 1]       550 examples, 0 failures    3 suites in 285.6700s      (pid 25539 exit 0)
    [ 4]       692 examples, 0 failures    4 suites in 286.9296s      (pid 25548 exit 0)
    [ 2]       645 examples, 0 failures    5 suites in 295.0375s      (pid 25542 exit 0)
  • 同時並行した数(プロセス)ごとに結果が出力される

注意すること

  • テスト中の進捗が分からない(Fuubarを指定しても進捗は出なかった)
通常のFuubar
Run options:
  include {}
  exclude {}
394/2537 |========= 15 ==========>                                   |  ETA: 00:16:40
test-queueのFuubar
Run options:
  include {}
  exclude {}
Starting test-queue master (/tmp/test_queue_17895_161019340.sock)
  • HTML出力が正しく出力されない(同時に同じファイルに書き込む為)
    • 対策としてはテキスト出力にする、もしくはHTMLファイルをプロセスごとに分けることで対応可能

参考: test-queue で worker 毎に設定値を変更したくなったらこうする - Thanks Driven Life

  • --fail-fastを指定しても、該当プロセスのみテストを途中で中断するだけで、テスト全体は止まらない
22
17
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
17