Skip to content

Commit

Permalink
Start chromedriver with PartitionSupervisor (#692)
Browse files Browse the repository at this point in the history
* Start chromedriver with PartitionSupervisor

This will open as many chromedrivers you have as cores, and partition
them access to them based on your test pid. This effectively acts as a
"pool" of chromedrivers without needing logic to check them in and out
of the pool.

It just acts as if there is a single chromedriver and it seems to just
work.

Related to #365

* ci: increase minimum elixir/otp versions

* fix: add license for PartitionSupervisor

Since we are vendoring this from the Elixir codebase, we attribute the
project by providing its license in the file.

* chore: format

Formatting has changed since we have updated the minimum Elixir version.

* chore: Add link to elixir-lang/elixir repo for vendored code

* deps: Update Credo

* chore: add NOTICE.md and update LICENSE.md

* fix: Version mismatch of how to call IO.binread

It seems that using `:all` with IO.binread has changed between v1.12 and
v1.13, and is causing a Dialyzer problem. This patch adds some compile
time logic to call it with the right argument based on the Elixir
version.
  • Loading branch information
mhanberg authored Jul 15, 2022
1 parent 196d0d6 commit 7119602
Show file tree
Hide file tree
Showing 16 changed files with 473 additions and 61 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

strategy:
matrix:
elixir-otp: [{otp: 21.x, elixir: 1.8.x}, {otp: 21.x, elixir: 1.9.x}, {otp: 21.x, elixir: 1.10.x}, {otp: 21.x, elixir: 1.11.x}, {otp: 22.x, elixir: 1.12.x}]
elixir-otp: [{otp: 23.x, elixir: 1.12.x}, {otp: 25.x, elixir: 1.13.x}]
fail-fast: false

env:
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:

strategy:
matrix:
elixir-otp: [{otp: 21.x, elixir: 1.8.x}, {otp: 21.x, elixir: 1.9.x}, {otp: 21.x, elixir: 1.10.x}, {otp: 21.x, elixir: 1.11.x}, {otp: 22.x, elixir: 1.12.x}]
elixir-otp: [{otp: 23.x, elixir: 1.12.x}, {otp: 25.x, elixir: 1.13.x}]
fail-fast: false

steps:
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:

strategy:
matrix:
elixir-otp: [{otp: 21.x, elixir: 1.8.x}, {otp: 21.x, elixir: 1.9.x}, {otp: 21.x, elixir: 1.10.x}, {otp: 21.x, elixir: 1.11.x}, {otp: 22.x, elixir: 1.12.x}]
elixir-otp: [{otp: 23.x, elixir: 1.12.x}, {otp: 25.x, elixir: 1.13.x}]
fail-fast: false

env:
Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:

strategy:
matrix:
elixir-otp: [{otp: 21.x, elixir: 1.8.x}, {otp: 21.x, elixir: 1.9.x}, {otp: 21.x, elixir: 1.10.x}, {otp: 21.x, elixir: 1.11.x}, {otp: 22.x, elixir: 1.12.x}]
elixir-otp: [{otp: 23.x, elixir: 1.12.x}, {otp: 25.x, elixir: 1.13.x}]
fail-fast: false

env:
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.10.4
elixir 1.12.3
erlang 23.3.4.4
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2016 Chris Keathley
Copyright (c) 2022 Mitchell Hanberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
46 changes: 46 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
LEGAL NOTICE INFORMATION
------------------------

All the files in this distribution are copyright to the terms below.

== lib/wallaby/partition_supervisor.ex

Copyright 2012 Plataformatec
Copyright 2021 The Elixir Team

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

== All other files

The MIT License (MIT)

Copyright (c) 2016 Chris Keathley
Copyright (c) 2022 Mitchell Hanberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion integration_test/chrome/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ExUnit.configure(max_cases: 4, exclude: [pending: true])
ExUnit.configure(exclude: [pending: true])
ExUnit.start()

# Load support files
Expand Down
5 changes: 4 additions & 1 deletion lib/wallaby.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ defmodule Wallaby do

children = [
{driver(), [name: Wallaby.Driver.Supervisor]},
:hackney_pool.child_spec(:wallaby_pool, timeout: 15_000, max_connections: 4),
:hackney_pool.child_spec(:wallaby_pool,
timeout: 15_000,
max_connections: System.schedulers_online()
),
{Wallaby.SessionStore, [name: Wallaby.SessionStore]}
]

Expand Down
4 changes: 1 addition & 3 deletions lib/wallaby/browser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,7 @@ defmodule Wallaby.Browser do

_ ->
raise Wallaby.ExpectationNotMetError,
"Wallaby has encountered an internal error: #{inspect(error)} with session: #{
inspect(parent)
}"
"Wallaby has encountered an internal error: #{inspect(error)} with session: #{inspect(parent)}"
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions lib/wallaby/chrome.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ defmodule Wallaby.Chrome do

@behaviour Wallaby.Driver

@default_readiness_timeout 5_000
@default_readiness_timeout 10_000

alias Wallaby.Chrome.Chromedriver
alias Wallaby.WebdriverClient
Expand Down Expand Up @@ -144,7 +144,10 @@ defmodule Wallaby.Chrome do
def init(_) do
children = [
Wallaby.Driver.LogStore,
Wallaby.Chrome.Chromedriver
{PartitionSupervisor,
child_spec: Wallaby.Chrome.Chromedriver,
name: Wallaby.Chromedrivers,
partitions: System.schedulers_online()}
]

Supervisor.init(children, strategy: :one_for_one)
Expand Down
10 changes: 5 additions & 5 deletions lib/wallaby/chrome/chromedriver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ defmodule Wallaby.Chrome.Chromedriver do
alias Wallaby.Chrome
alias Wallaby.Chrome.Chromedriver.Server

@instance __MODULE__

def child_spec(_arg) do
{:ok, chromedriver_path} = Chrome.find_chromedriver_executable()
Server.child_spec([chromedriver_path, [name: @instance]])
Server.child_spec([chromedriver_path, []])
end

@spec wait_until_ready(timeout()) :: :ok | {:error, :timeout}
def wait_until_ready(timeout) do
Server.wait_until_ready(@instance, timeout)
process_name = {:via, PartitionSupervisor, {Wallaby.Chromedrivers, self()}}
Server.wait_until_ready(process_name, timeout)
end

@spec base_url :: String.t()
def base_url do
Server.get_base_url(@instance)
process_name = {:via, PartitionSupervisor, {Wallaby.Chromedrivers, self()}}
Server.get_base_url(process_name)
end
end
Loading

0 comments on commit 7119602

Please sign in to comment.