From: Tom Hughes Date: Wed, 12 Mar 2025 18:45:27 +0000 (+0000) Subject: Monkey patch Selenium to allocate unique bidi ports X-Git-Tag: live~1^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/d5f462f7d01299cdf79d4acced54ff57a6cad027?ds=inline Monkey patch Selenium to allocate unique bidi ports https://github.com/mozilla/geckodriver/issues/2218 --- diff --git a/config/initializers/selenium.rb b/config/initializers/selenium.rb new file mode 100644 index 000000000..5e683d8b2 --- /dev/null +++ b/config/initializers/selenium.rb @@ -0,0 +1,35 @@ +if Rails.env.test? + require "active_support/testing/parallelization" + + module OpenStreetMap + module Selenium + module BidiPort + module ClassMethods + attr_accessor :websocket_port + end + + def self.prepended(base) + class << base + prepend ClassMethods + end + + base.websocket_port = 10000 + + ActiveSupport::Testing::Parallelization.after_fork_hook do |worker| + base.websocket_port = 10000 + worker + end + end + + def initialize(config) + super + + @extra_args = Array(@extra_args) << "--websocket-port=#{self.class.websocket_port}" + + self.class.websocket_port += 256 + end + end + end + end + + Selenium::WebDriver::ServiceManager.prepend(OpenStreetMap::Selenium::BidiPort) +end