fix: Turbo DriveのDOM差し替え中に起きるsystem specの不安定な失敗を解消する - #219
Merged
Conversation
CIでalarm_contents_specがまれに以下で落ちていた。
Selenium::WebDriver::Error::UnknownError:
unknown error: unhandled inspector error:
{"code":-32000,"message":"Node with given id does not belong to the document"}
フォーム送信後のリダイレクトをTurbo Driveが処理する際、bodyの差し替えが
終わる前にCapybaraがhave_contentの問い合わせを投げると、chromedriverが
参照していたノードが旧ドキュメント側に取り残されてこのエラーになる。
差し替えが終われば解消する一過性のものだが、Capybaraが再試行する
invalid_element_errorsにUnknownErrorは含まれないため、待機時間を使い切る
ことなく即失敗していた。
そこでCapybara::Node::Base#catch_error?をprependで拡張し、このメッセージを
持つUnknownErrorに限りStaleElementReferenceErrorなどと同じ再試行対象として
扱うようにした。待機時間内に差し替えが完了すれば成功し、超過すれば元の例外が
そのまま送出されるので、本物のエラーを握り潰すことはない。
specごとにsleepやwaitを足す案は採らなかった。同じ競合はTurboで遷移する
すべてのsystem specで起こりうるため、発生箇所ごとの対処では漏れが出る。
|
Warning Review limit reachedNext included review available in 31 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
mainのCIでsystem specがまれに落ちていた。
原因
フォーム送信後のリダイレクトをTurbo Driveが処理する際、bodyの差し替えが終わる前にCapybaraが
have_contentの問い合わせを投げると、chromedriverが参照していたノードが旧ドキュメント側に取り残されてこのエラーになる。差し替えが終われば解消する一過性のエラーだが、Capybaraが再試行対象とする
invalid_element_errors(StaleElementReferenceErrorなど)にUnknownErrorは含まれないため、待機時間を使い切ることなく即失敗していた。対応
Capybara::Node::Base#catch_error?をprependで拡張し、このメッセージを持つUnknownErrorに限り再試行対象として扱うようにした。Capybara.default_max_wait_time)内に差し替えが完了すれば成功するUnknownErrorは従来どおり即失敗するspecごとに
sleepや明示的なwaitを足す案は採らなかった。同じ競合はTurboで遷移するすべてのsystem specで起こりうるため、発生箇所ごとの対処では漏れが出るため。確認したこと
spec/system全件(62 examples, 0 failures, 6 pending)UnknownErrorは再試行され、それ以外のUnknownErrorは再試行されないことを検証