-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Safaridriver logging is relatively odd. It only has debug level logging, only logs to a file, and discovering that file is somewhat tricky. This change adds minimal support to discover and dump safaridriver logs. I'm not sure how many folks bother with safaridriver testing, so this change might be mostly a favour to myself when diagnosing safaridriver issues that arise from time to time. Closes #563 Incidentally fixes #517
- Loading branch information
Showing
9 changed files
with
359 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
(ns fake-driver | ||
"A fake WebDriver to support testing, adapt as necessary for tests" | ||
(:require [babashka.cli :as cli] | ||
[cheshire.core :as json] | ||
[lread.status-line :as status] | ||
[org.httpkit.server :as server]) | ||
(:import [sun.misc Signal SignalHandler])) | ||
|
||
(def cli-spec {:help {:desc "This usage help" :alias :h} | ||
:port {:ref "<port>" | ||
:desc "Expose server on this port" | ||
:coerce :int | ||
:default 8888 | ||
:alias :p} | ||
:sigterm-filename {:ref "<filename>" | ||
:desc "Log a line to this filename when quit via sig term"} | ||
:start-server {:ref "<boolean>" | ||
:desc "Start a fake webdriver request handler" | ||
:default true}}) | ||
|
||
(defn- usage-help [] | ||
(status/line :head "Usage help") | ||
(status/line :detail (cli/format-opts {:spec cli-spec :order [:port :sigterm-filename :start-server :help]})) ) | ||
|
||
(defn- usage-fail [msg] | ||
(status/line :error msg) | ||
(usage-help) | ||
(System/exit 1)) | ||
|
||
(defn signal-handler [signal-id handler-fn] | ||
(let [signal (Signal. signal-id) | ||
handler (reify SignalHandler | ||
(handle [_ _] (handler-fn)))] | ||
(Signal/handle signal handler))) | ||
|
||
(defn make-handler [_opts] | ||
(fn handle-request [{:keys [request-method uri] :as _req}] | ||
(cond | ||
(and (= :post request-method) (= "/session" uri)) | ||
{:status 200 | ||
:headers {"Content-Type" "application/json"} | ||
:body (json/generate-string {:sessionId (random-uuid)})} | ||
(and (= :get request-method) (= "/status" uri)) | ||
{:status 200 | ||
:headers {"Content-Type" "application/json"} | ||
:body (json/generate-string {:ready true})} | ||
:else | ||
{:status 404}))) | ||
|
||
(defn -main [& args] | ||
(let [opts (cli/parse-opts args {:spec cli-spec | ||
:restrict true | ||
:error-fn (fn [{:keys [msg]}] | ||
(usage-fail msg))})] | ||
(if (:help opts) | ||
(usage-help) | ||
(do | ||
(when-let [log (:sigterm-filename opts)] | ||
(signal-handler "TERM" (fn sigterm-handler [] | ||
;; I don't think we need to worry about concurrency for our use case | ||
(spit log "SIGTERM received, quitting" :append true) | ||
(System/exit 0)))) | ||
|
||
(when (:start-server opts) | ||
(server/run-server (make-handler opts) opts))))) | ||
|
||
@(promise)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.