Skip to content

Commit

Permalink
add test prevent process fork (#309)
Browse files Browse the repository at this point in the history
* add test prevent process fork

* update

* update
  • Loading branch information
Uunnamed authored Aug 24, 2020
1 parent bb3eee0 commit 9694246
Showing 1 changed file with 40 additions and 0 deletions.
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
[]
(->> (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))))

0 comments on commit 9694246

Please sign in to comment.