Repository navigation
Conversation
The default reset disposes the browser context, so every test downloads all assets again. With reset: :soft Cuprite keeps the context and opens a fresh blank window, closes the others and other contexts, clears cookies and clears storage for every origin found in the network traffic. Any failure falls back to the full reset. CUPRITE_RESET=soft runs the suite in soft mode. Refs rubycdp#128 Co-authored-by: Maxwell Salzberg <maxwell@backerkit.com>
Capybara's Session#reset! resets the driver before it waits for pending server requests, so a response can set a cookie after the soft reset clears them. Page timers, an unused modal response and window size, device and media emulation also live in the old window. Each example passes because the soft reset closes the old window and opens a new one. The in-flight request example fails when the old window is left open, and the other three fail when the current window is reused.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c8f74ba4b6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The soft reset collected origins from the windows still open and their network traffic. close_window removes the target, so an origin a test opened in a window and closed before the reset kept its storage into the next test. close_window now remembers the window's origins, and the next soft reset clears them.
Target.closeTarget returns before Chrome has torn the page down. A busy page kept running for a few milliseconds and could set a cookie, and a response arriving in that window could store one, after the soft reset had cleared them. The soft reset now waits until the closed targets leave Target.getTargets, up to the browser timeout, before it clears cookies. A timeout falls back to the full reset like any other soft reset error. "clears cookies only after the old windows are gone" failed in 4 of 8 runs under full CPU load without the wait and passed 8 of 8 with it.
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.
Refs rubycdp#128
This is the
feat/soft-resetbranch from this repo brought up to date withmain, following the plan in rubycdp#128 (comment):reset: :softis opt-in and the full reset stays the default.The first commit is that branch's commit, with what it needed to run on current
mainfolded in:Ferrum::Contexts#eachyields the id and the context as two values, socontexts.each.map(&:first)raisedNoMethodError: undefined method 'first' for an instance of Stringon every soft reset. The fallback only rescuesFerrum::Error, so it propagated. The ids are now collected withmap { |id, _| id }before the other contexts are disposed./cuprite/cacheableis back in the test app. a35c5c1 removed it, and "keeps the HTTP cache" visits it.indexedDB.opento succeed before listing databases.openis asynchronous, so the assertion before the reset failed on every run.spec/features/soft_reset_spec.rbtodescribe "#reset!"inspec/driver_spec.rb, undercontext "with reset: :soft", to match the layout from test: restructure specs by public method rubycdp/cuprite#357.The second commit adds four examples for state that lives in the old window, so they pass because the soft reset closes it and opens a new one:
Session#reset!resets the driver before it waits for pending server requests, so a response can set a cookie after the cookies are cleared. Closing the old window cancels the request. With the old window left open (noclose_pages), the example fails:expected: 0, got: 10.The third commit fixes a leak a review found: the soft reset collected origins from the windows still open and their traffic, and
close_windowremoves the target, so an origin a test opened in a window and closed before the reset kept its storage into the next test.close_windownow remembers the window's origins and the next soft reset clears them. "clears storage of an origin whose window closed before the reset" fails without it:expected: nil, got: "left behind".I first wrote a soft reset that reused the window, and the in-flight request case is what broke it: a session cookie from a request still running when the test ended survived into the next test. That's why I think the new window is the right design and worth pinning in specs.
bundle exec rakepasses, and so doesCUPRITE_RESET=soft bundle exec rake, which runs Capybara's shared specs with the soft reset. RuboCop is clean.Benchmarks
Cuprite's own suite,
bundle exec rakeon one machine with nothing else running:reset: :softThe test app serves almost nothing cacheable, so this mostly measures skipping the browser context: disposing it and creating a new one on every reset.
A Rails app's system specs on CI (Semaphore, 18 jobs × 2 processes, about 31,200 examples), comparing two runs that differ only in the reset mode:
reset: :softThe wall time barely moves because it is mostly setup and the slowest job. Locally, a 113-file sample of the same app ran in 217s with
reset: :softand in 259s with my earlier tab-reusing version.