Skip to content

Instantly share code, notes, and snippets.

@rzane
Last active August 5, 2024 21:15
Show Gist options
  • Save rzane/a4efe24db7ce44491f0ec6056ac16401 to your computer and use it in GitHub Desktop.
Save rzane/a4efe24db7ce44491f0ec6056ac16401 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
source "https://rubygems.org"
gem "cuprite", "~> 0.15.1"
gem "sinatra", "~> 4.0"
gem "puma", "~> 6.4"
gem "minitest", "~> 5.24"
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
base64 (0.2.0)
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
concurrent-ruby (1.3.3)
cuprite (0.15.1)
capybara (~> 3.0)
ferrum (~> 0.15.0)
ferrum (0.15)
addressable (~> 2.5)
concurrent-ruby (~> 1.1)
webrick (~> 1.7)
websocket-driver (~> 0.7)
matrix (0.4.2)
mini_mime (1.1.5)
mini_portile2 (2.8.7)
minitest (5.24.1)
mustermann (3.0.1)
ruby2_keywords (~> 0.0.1)
nio4r (2.7.3)
nokogiri (1.16.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.16.7-arm64-darwin)
racc (~> 1.4)
public_suffix (6.0.1)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.8.1)
rack (3.1.7)
rack-protection (4.0.0)
base64 (>= 0.1.0)
rack (>= 3.0.0, < 4)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
rack (>= 1.3)
regexp_parser (2.9.2)
ruby2_keywords (0.0.5)
sinatra (4.0.0)
mustermann (~> 3.0)
rack (>= 3.0.0, < 4)
rack-protection (= 4.0.0)
rack-session (>= 2.0.0, < 3)
tilt (~> 2.0)
tilt (2.4.0)
webrick (1.8.1)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
PLATFORMS
arm64-darwin-22
ruby
DEPENDENCIES
cuprite (~> 0.15.1)
minitest (~> 5.24)
puma (~> 6.4)
sinatra (~> 4.0)
BUNDLED WITH
2.5.16
require 'irb'
require 'sinatra/base'
require 'capybara/cuprite'
require 'capybara/dsl'
require 'minitest/autorun'
class App < Sinatra::Base
get '/' do
erb <<~ERB
<form id="form">
<button type="submit">Submit</button>
</form>
<script>
const form = document.getElementById('form');
form.addEventListener('submit', async event => {
event.preventDefault();
fetch('/submit', { method: 'POST' });
fetch('/submit', { method: 'POST' });
fetch('/submit', { method: 'POST' });
fetch('/submit', { method: 'POST' });
fetch('/submit', { method: 'POST' });
});
</script>
ERB
end
post '/submit' do
'OK'
end
end
Capybara.app = App
Capybara.current_driver = :cuprite
class Reproduce < Minitest::Test
include Capybara::DSL
def test_reproduction
network = page.driver.browser.network
network.whitelist = %r{127.0.0.1}
visit '/'
100.times do |i|
click_button 'Submit'
begin
network.wait_for_idle
rescue Ferrum::TimeoutError
# Find the exchange that isn't finished
exchange = network.traffic.reject(&:finished?).first
# Find all exchanges with the same ID
exchanges = network.traffic.select { _1.id == exchange.id }
# There will be two exchanges
assert_equal 2, exchanges.length
# Poke around
binding.irb
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment