Skip to content

Commit

Permalink
Fix proc-test for Windows (#386)
Browse files Browse the repository at this point in the history
Closes #382
  • Loading branch information
lread authored May 11, 2022
1 parent 9f07e30 commit ccd6a07
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions test/etaoin/proc_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@
[etaoin.proc :as proc]
[clojure.string :as str]))

(defn get-count-chromedriver-processes
(defn get-count-chromedriver-instances
[]
(->> (sh "sh" "-c" "ps aux | grep chromedriver")
:out
str/split-lines
(drop-last 2)
count))
(let [process-count (->> (if proc/windows?
(sh "tasklist")
(sh "sh" "-c" "ps aux"))
:out
str/split-lines
(filter #(str/includes? % "chromedriver"))
count)]
(if proc/windows?
(/ process-count 2) ;; on Windows we seem to have 2 chromedriver.exe instances per launch
process-count)))

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

0 comments on commit ccd6a07

Please sign in to comment.