Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test prevent process fork #309

Merged
merged 3 commits into from
Aug 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions test/etaoin/proc_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(ns etaoin.proc-test
(:require [etaoin.api :refer :all]
[clojure.java.shell :refer [sh]]
[clojure.test :refer :all]
[etaoin.proc :as proc]
[clojure.string :as str]))

(defn get-count-chromedriver-processes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

отделить одной строкой от импортов

[]
(->> (sh "sh" "-c" "ps aux | grep chromedriver")
:out
str/split-lines
(drop-last 2)
count))

(deftest test-prevent-process-fork
(testing "certain driver port"
(let [port 9999
process (proc/run ["chromedriver" (format "--port=%d" port)])
_ (wait-running (atom {:port port :host "localhost"}))]
(is (= 1 (get-count-chromedriver-processes)))
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"already in use"
(chrome {:port port})))
(proc/kill process)))
(testing "random driver port"
(let [port 9999
process (proc/run ["chromedriver" (format "--port=%d" port)])
_ (wait-running (atom {:port port :host "localhost"}))]
(with-chrome {:args ["--no-sandbox"]} driver
(is (= 2 (get-count-chromedriver-processes)))
(proc/kill process))))
(testing "connect to driver"
(let [port 9999
process (proc/run ["chromedriver" (format "--port=%d" port)])
_ (wait-running (atom {:port port :host "localhost"}))
driver (chrome {:host "localhost" :port port :args ["--no-sandbox"]})]
(is (= 1 (get-count-chromedriver-processes)))
(proc/kill process))))