momocus / sakazuki

自宅の酒を管理するアプリケーション
https://sakazuki.fly.dev/
MIT License
13 stars 4 forks source link

ときどきCIのテストが落ち、ReRunすると落ちない #745

Open yonta opened 5 days ago

yonta commented 5 days ago

💡 Summary

ときどきテストが失敗する。 再現性が低い、おしまいだ。

📝 再現方法

  1. テストCIをまわす
  2. 時々落ちる

>わからない!!!<

🤬 失敗例

https://github.com/momocus/sakazuki/actions/runs/9731029983/job/26854920162

yonta commented 5 days ago

エラー内容は、酒フォームで酒の名前から加水・原酒を原酒に自動補完する機能。 原酒の補完ができてない。

エラーログ

...........................................................................................................................................................................................................................F................................................................................................

Failures:

  1) Sake Form Completion for Detail for detail accordion warimizu is completed 原酒
     Failure/Error: expect(page).to have_select("sake_warimizu", selected:)
       expected to find visible select box "sake_warimizu" that is not disabled but there were no matches. Also found "", which matched the selector but not all filters. 

     [Screenshot Image]: /home/runner/work/sakazuki/sakazuki/tmp/capybara/failures_r_spec_example_groups_sake_form_completion_for_detail_for_detail_accordion_warimizu_is_completed_原酒_309.png

     # ./spec/system/sake_form_completion_for_detail_spec.rb:178:in `block (4 levels) in <top (required)>'

Finished in 1 minute 48.9 seconds (files took 3.81 seconds to load)
3[16](https://github.com/momocus/sakazuki/actions/runs/9731029983/job/26854920162#step:9:17) examples, 1 failure

Failed examples:

rspec ./spec/system/sake_form_completion_for_detail_spec.rb:[17](https://github.com/momocus/sakazuki/actions/runs/9731029983/job/26854920162#step:9:18)5 # Sake Form Completion for Detail for detail accordion warimizu is completed 原酒

Stopped processing SimpleCov as a previous error not related to SimpleCov has been detected
Coverage report generated for RSpec to /home/runner/work/sakazuki/sakazuki/coverage/coverage.xml. 310 / 321 LOC (96.57%) covered
Error: Process completed with exit code 1.
yonta commented 5 days ago

よくあるのはJSの実行よりもCapybaraセレクタが早すぎること。 今回の補完機能もTS/JSで書かれているので、TAB後の補完が行われる前にマッチしてる?

でも1sスリープとかは入れたくない。テスト全体が恐ろしく遅くなる。

yonta commented 5 days ago

「フレーキーなテスト」というらしい。 よくまとまってて助かる~。 sleepは悪!!

https://qiita.com/jnchito/items/56ba52c9a7246fc5016a

yonta commented 5 days ago

カピバラは失敗したアサーションを自動で待ってリトライしてくれる。 この待つ時間(デフォルト2s)を少し伸ばしておくのがいいかな。3~5くらいか。

https://github.com/teamcapybara/capybara/blob/master/README.md#asynchronous-javascript-ajax-and-friends

これの面白いところは、

なんだね。 アサーションがfalseを返したときだけ、待機・自動リトライをするから、気を付けて書かないと引っ掛かりそう。

yonta commented 5 days ago

Capybara.default_max_wait_time = 2を5に伸ばして様子見るかー