Fix aarch64 test (#1007)
This commit is contained in:
parent
4c075e07e4
commit
0f723a1e7c
4 changed files with 142 additions and 156 deletions
|
|
@ -60,6 +60,9 @@ if [ "$BABASHKA_STATIC" = "true" ]; then
|
||||||
args+=("--libc=musl"
|
args+=("--libc=musl"
|
||||||
# see https://github.com/oracle/graal/issues/3398
|
# see https://github.com/oracle/graal/issues/3398
|
||||||
"-H:CCompilerOption=-Wl,-z,stack-size=2097152")
|
"-H:CCompilerOption=-Wl,-z,stack-size=2097152")
|
||||||
|
else
|
||||||
|
# see https://github.com/oracle/graal/issues/3737
|
||||||
|
args+=("-H:+StaticExecutableWithDynamicLibC")
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,7 @@
|
||||||
(is (instance? java.net.http.WebSocket$Builder (ws-client/websocket-builder))))
|
(is (instance? java.net.http.WebSocket$Builder (ws-client/websocket-builder))))
|
||||||
|
|
||||||
(deftest async-smoke-test
|
(deftest async-smoke-test
|
||||||
(when-not (and
|
(is (= 200 (:status @(client/send-async {:uri "https://www.clojure.org" :method :get})))))
|
||||||
(= "aarch64" (System/getenv "BABASHKA_ARCH"))
|
|
||||||
(= "true" (System/getenv "BABASHKA_STATIC")))
|
|
||||||
(is (= 200 (:status @(client/send-async {:uri "https://www.clojure.org" :method :get}))))))
|
|
||||||
|
|
||||||
(defn ws-handler [{:keys [init] :as opts} req]
|
(defn ws-handler [{:keys [init] :as opts} req]
|
||||||
(when init (init req))
|
(when init (init req))
|
||||||
|
|
@ -28,22 +25,19 @@
|
||||||
(try ~@body (finally (s# :timeout 100)))))
|
(try ~@body (finally (s# :timeout 100)))))
|
||||||
|
|
||||||
(deftest websockets-smoke-test
|
(deftest websockets-smoke-test
|
||||||
(when-not (and
|
(with-ws-server {:on-receive #(httpkit.server/send! %1 %2)}
|
||||||
(= "aarch64" (System/getenv "BABASHKA_ARCH"))
|
(is (= "zomg websockets!"
|
||||||
(= "true" (System/getenv "BABASHKA_STATIC")))
|
(let [p (promise)
|
||||||
(with-ws-server {:on-receive #(httpkit.server/send! %1 %2)}
|
ws (ws-client/build-websocket "ws://localhost:1234"
|
||||||
(is (= "zomg websockets!"
|
{:on-binary (fn [_ data last?] (deliver p data))
|
||||||
(let [p (promise)
|
:on-text (fn [ws data last?] (deliver p data))
|
||||||
ws (ws-client/build-websocket "ws://localhost:1234"
|
:on-error (fn [ws throwable] (deliver p throwable))
|
||||||
{:on-binary (fn [_ data last?] (deliver p data))
|
:on-ping (fn [ws data] (deliver p data))
|
||||||
:on-text (fn [ws data last?] (deliver p data))
|
:on-pong (fn [ws data] (deliver p data))
|
||||||
:on-error (fn [ws throwable] (deliver p throwable))
|
:on-open (fn [ws] nil)
|
||||||
:on-ping (fn [ws data] (deliver p data))
|
:on-close (fn [ws status-code reason] nil)})]
|
||||||
:on-pong (fn [ws data] (deliver p data))
|
(-> ws
|
||||||
:on-open (fn [ws] nil)
|
(ws-client/send "zomg websockets!"))
|
||||||
:on-close (fn [ws status-code reason] nil)})]
|
(try (deref p 5000 ::timeout)
|
||||||
(-> ws
|
(finally
|
||||||
(ws-client/send "zomg websockets!"))
|
(ws-client/close ws))))))))
|
||||||
(try (deref p 5000 ::timeout)
|
|
||||||
(finally
|
|
||||||
(ws-client/close ws)))))))))
|
|
||||||
|
|
|
||||||
|
|
@ -239,104 +239,97 @@
|
||||||
"HttpClient$Redirect/NEVER"
|
"HttpClient$Redirect/NEVER"
|
||||||
:always
|
:always
|
||||||
"HttpClient$Redirect/ALWAYS")))]
|
"HttpClient$Redirect/ALWAYS")))]
|
||||||
;; TODO: make graalvm repro of never-ending request with redirect always on linux aarch64 (+ musl?)
|
(println "Testing redirect always")
|
||||||
(when-not (and (= "aarch64" (System/getenv "BABASHKA_ARCH"))
|
(is (= 200 (bb (redirect-prog :always))))
|
||||||
(= "linux" (System/getenv "BABASHKA_PLATFORM")))
|
|
||||||
(println "Testing redirect always")
|
|
||||||
(is (= 200 (bb (redirect-prog :always)))))
|
|
||||||
(println "Testing redirect never")
|
(println "Testing redirect never")
|
||||||
(is (= 302 (bb (redirect-prog :never))))))
|
(is (= 302 (bb (redirect-prog :never))))))
|
||||||
|
|
||||||
(deftest ssl-context-test
|
(deftest ssl-context-test
|
||||||
;; TODO: investigate aarch64 issue
|
(is (= {:expired "java.security.cert.CertificateExpiredException"
|
||||||
(when-not
|
:revoked 200 ;; TODO: fix, "sun.security.cert.CertificateRevokedException"
|
||||||
(and (= "aarch64" (System/getenv "BABASHKA_ARCH"))
|
:self-signed "sun.security.provider.certpath.SunCertPathBuilderException"
|
||||||
(= "linux" (System/getenv "BABASHKA_PLATFORM")))
|
:untrusted-root "sun.security.provider.certpath.SunCertPathBuilderException"
|
||||||
(is (= {:expired "java.security.cert.CertificateExpiredException"
|
:wrong-host "sun.security.provider.certpath.SunCertPathBuilderException"}
|
||||||
:revoked 200 ;; TODO: fix, "sun.security.cert.CertificateRevokedException"
|
(bb
|
||||||
:self-signed "sun.security.provider.certpath.SunCertPathBuilderException"
|
'(do
|
||||||
:untrusted-root "sun.security.provider.certpath.SunCertPathBuilderException"
|
(ns net
|
||||||
:wrong-host "sun.security.provider.certpath.SunCertPathBuilderException"}
|
(:import
|
||||||
(bb
|
(java.net URI)
|
||||||
'(do
|
(java.net.http HttpClient
|
||||||
(ns net
|
HttpRequest
|
||||||
(:import
|
HttpResponse$BodyHandlers)))
|
||||||
(java.net URI)
|
|
||||||
(java.net.http HttpClient
|
|
||||||
HttpRequest
|
|
||||||
HttpResponse$BodyHandlers)))
|
|
||||||
|
|
||||||
(defn send-and-catch [client req handler]
|
(defn send-and-catch [client req handler]
|
||||||
(try
|
(try
|
||||||
(let [res (.send client req (HttpResponse$BodyHandlers/discarding))]
|
(let [res (.send client req (HttpResponse$BodyHandlers/discarding))]
|
||||||
(.statusCode res))
|
(.statusCode res))
|
||||||
(catch Throwable t
|
(catch Throwable t
|
||||||
(-> (Throwable->map t) :via last :type name))))
|
(-> (Throwable->map t) :via last :type name))))
|
||||||
|
|
||||||
(let [client (HttpClient/newHttpClient)
|
(let [client (HttpClient/newHttpClient)
|
||||||
handler (HttpResponse$BodyHandlers/discarding)
|
handler (HttpResponse$BodyHandlers/discarding)
|
||||||
reqs (->> [:expired
|
reqs (->> [:expired
|
||||||
:self-signed
|
:self-signed
|
||||||
:revoked
|
:revoked
|
||||||
:untrusted-root
|
:untrusted-root
|
||||||
:wrong-host]
|
:wrong-host]
|
||||||
(map (fn [k]
|
(map (fn [k]
|
||||||
(let [req (-> (URI. (format "https://%s.badssl.com" (name k)))
|
(let [req (-> (URI. (format "https://%s.badssl.com" (name k)))
|
||||||
(HttpRequest/newBuilder)
|
(HttpRequest/newBuilder)
|
||||||
(.GET)
|
(.GET)
|
||||||
(.build))]
|
(.build))]
|
||||||
[k req])))
|
[k req])))
|
||||||
(into {}))]
|
(into {}))]
|
||||||
(->> reqs
|
(->> reqs
|
||||||
(map (fn [[k req]]
|
(map (fn [[k req]]
|
||||||
[k (send-and-catch client req handler)]))
|
[k (send-and-catch client req handler)]))
|
||||||
(into {})))))))
|
(into {})))))))
|
||||||
|
|
||||||
(is (= {:expired 200
|
(is (= {:expired 200
|
||||||
:self-signed 200
|
:self-signed 200
|
||||||
:untrusted-root 200}
|
:untrusted-root 200}
|
||||||
(bb
|
(bb
|
||||||
'(do
|
'(do
|
||||||
(ns net
|
(ns net
|
||||||
(:import
|
(:import
|
||||||
(java.net URI)
|
(java.net URI)
|
||||||
(java.net.http HttpClient
|
(java.net.http HttpClient
|
||||||
HttpRequest
|
HttpRequest
|
||||||
HttpResponse$BodyHandlers)
|
HttpResponse$BodyHandlers)
|
||||||
(java.security SecureRandom)
|
(java.security SecureRandom)
|
||||||
(java.security.cert X509Certificate)
|
(java.security.cert X509Certificate)
|
||||||
(javax.net.ssl SSLContext
|
(javax.net.ssl SSLContext
|
||||||
TrustManager
|
TrustManager
|
||||||
X509TrustManager)))
|
X509TrustManager)))
|
||||||
|
|
||||||
(let [insecure-trust-manager (reify X509TrustManager
|
(let [insecure-trust-manager (reify X509TrustManager
|
||||||
(checkClientTrusted [_ _ _])
|
(checkClientTrusted [_ _ _])
|
||||||
(checkServerTrusted [_ _ _])
|
(checkServerTrusted [_ _ _])
|
||||||
(getAcceptedIssuers [_] (into-array X509Certificate [])))
|
(getAcceptedIssuers [_] (into-array X509Certificate [])))
|
||||||
insecure-trust-managers (into-array TrustManager [insecure-trust-manager])
|
insecure-trust-managers (into-array TrustManager [insecure-trust-manager])
|
||||||
insecure-context (doto (SSLContext/getInstance "TLS")
|
insecure-context (doto (SSLContext/getInstance "TLS")
|
||||||
(.init nil
|
(.init nil
|
||||||
insecure-trust-managers
|
insecure-trust-managers
|
||||||
(SecureRandom.)))
|
(SecureRandom.)))
|
||||||
client (-> (HttpClient/newBuilder)
|
client (-> (HttpClient/newBuilder)
|
||||||
(.sslContext insecure-context)
|
(.sslContext insecure-context)
|
||||||
(.build))
|
(.build))
|
||||||
handler (HttpResponse$BodyHandlers/discarding)
|
handler (HttpResponse$BodyHandlers/discarding)
|
||||||
reqs (->> [:expired
|
reqs (->> [:expired
|
||||||
:self-signed
|
:self-signed
|
||||||
:untrusted-root]
|
:untrusted-root]
|
||||||
(map (fn [k]
|
(map (fn [k]
|
||||||
(let [req (-> (URI. (format "https://%s.badssl.com" (name k)))
|
(let [req (-> (URI. (format "https://%s.badssl.com" (name k)))
|
||||||
(HttpRequest/newBuilder)
|
(HttpRequest/newBuilder)
|
||||||
(.GET)
|
(.GET)
|
||||||
(.build))]
|
(.build))]
|
||||||
[k req])))
|
[k req])))
|
||||||
(into {}))]
|
(into {}))]
|
||||||
(->> reqs
|
(->> reqs
|
||||||
(map (fn [[k req]]
|
(map (fn [[k req]]
|
||||||
[k (-> (.send client req handler)
|
[k (-> (.send client req handler)
|
||||||
(.statusCode))]))
|
(.statusCode))]))
|
||||||
(into {})))))))))
|
(into {}))))))))
|
||||||
|
|
||||||
;; HttpRequest
|
;; HttpRequest
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,38 +43,36 @@
|
||||||
(timbre/swap-config! (constantly old-config))))
|
(timbre/swap-config! (constantly old-config))))
|
||||||
|
|
||||||
(deftest logging-test
|
(deftest logging-test
|
||||||
(when-not (and (= "true" (System/getenv "BABASHKA_STATIC"))
|
(let [res (tu/bb nil (pr-str program))]
|
||||||
(= "aarch64" (System/getenv "BABASHKA_ARCH")))
|
(is (= 17 (count (re-seq #"\[dude:.\]" res))))
|
||||||
(let [res (tu/bb nil (pr-str program))]
|
(is (= 6 (count (re-seq #"DEBUG" res))))
|
||||||
(is (= 17 (count (re-seq #"\[dude:.\]" res))))
|
(is (= 11 (count (re-seq #"INFO" res)))))
|
||||||
(is (= 6 (count (re-seq #"DEBUG" res))))
|
(testing "println appender works with with-out-str"
|
||||||
(is (= 11 (count (re-seq #"INFO" res)))))
|
(let [res (tu/bb
|
||||||
(testing "println appender works with with-out-str"
|
nil
|
||||||
(let [res (tu/bb
|
(pr-str '(do
|
||||||
nil
|
(require '[taoensso.timbre :as timbre]
|
||||||
(pr-str '(do
|
'[clojure.string :as str])
|
||||||
(require '[taoensso.timbre :as timbre]
|
(str/includes? (with-out-str (timbre/info "hello")) "hello"))))
|
||||||
'[clojure.string :as str])
|
res (edn/read-string res)]
|
||||||
(str/includes? (with-out-str (timbre/info "hello")) "hello"))))
|
(is (true? res))))
|
||||||
res (edn/read-string res)]
|
(testing "spit-appender"
|
||||||
(is (true? res))))
|
(let [temp-file (-> (fs/create-temp-dir)
|
||||||
(testing "spit-appender"
|
(fs/file "log.txt"))
|
||||||
(let [temp-file (-> (fs/create-temp-dir)
|
program (pr-str '(do
|
||||||
(fs/file "log.txt"))
|
(require '[taoensso.timbre :as timbre]
|
||||||
program (pr-str '(do
|
'[clojure.string :as str])
|
||||||
(require '[taoensso.timbre :as timbre]
|
(def appender (timbre/spit-appender {:fname :fname-placeholder}))
|
||||||
'[clojure.string :as str])
|
(def old-config timbre/*config*)
|
||||||
(def appender (timbre/spit-appender {:fname :fname-placeholder}))
|
(timbre/swap-config! assoc-in [:appenders :spit] appender)
|
||||||
(def old-config timbre/*config*)
|
(str/includes? (with-out-str (timbre/info "hello")) "hello")
|
||||||
(timbre/swap-config! assoc-in [:appenders :spit] appender)
|
(timbre/swap-config! (constantly old-config))))
|
||||||
(str/includes? (with-out-str (timbre/info "hello")) "hello")
|
program (str/replace program ":fname-placeholder" (pr-str (.getPath temp-file)))
|
||||||
(timbre/swap-config! (constantly old-config))))
|
_ (tu/bb
|
||||||
program (str/replace program ":fname-placeholder" (pr-str (.getPath temp-file)))
|
nil
|
||||||
_ (tu/bb
|
program)
|
||||||
nil
|
res (slurp temp-file)]
|
||||||
program)
|
(is (str/includes? res "hello")))))
|
||||||
res (slurp temp-file)]
|
|
||||||
(is (str/includes? res "hello"))))))
|
|
||||||
|
|
||||||
(def readable-prog
|
(def readable-prog
|
||||||
'(do
|
'(do
|
||||||
|
|
@ -103,14 +101,12 @@
|
||||||
(timbre/set-level! :debug)))
|
(timbre/set-level! :debug)))
|
||||||
|
|
||||||
(deftest readable-logging-test
|
(deftest readable-logging-test
|
||||||
(when-not (and (= "true" (System/getenv "BABASHKA_STATIC"))
|
(let [res (tu/bb nil (pr-str readable-prog))]
|
||||||
(= "aarch64" (System/getenv "BABASHKA_ARCH")))
|
(testing "spied value is returned and printed (and printed from println even though spyf level isn't enabled)"
|
||||||
(let [res (tu/bb nil (pr-str readable-prog))]
|
(is (= 5 (count (re-seq #"abc,def,ghi" res)))))
|
||||||
(testing "spied value is returned and printed (and printed from println even though spyf level isn't enabled)"
|
(testing "spied value is printed readably as a result of spyf"
|
||||||
(is (= 5 (count (re-seq #"abc,def,ghi" res)))))
|
(is (= 2 (count (re-seq #"\"abc,def,ghi\"" res)))))
|
||||||
(testing "spied value is printed readably as a result of spyf"
|
(testing "strings logged are printed readably"
|
||||||
(is (= 2 (count (re-seq #"\"abc,def,ghi\"" res)))))
|
(is (= 3 (count (re-seq #"\"test warn\"" res)))))
|
||||||
(testing "strings logged are printed readably"
|
(testing "lists are printed readably"
|
||||||
(is (= 3 (count (re-seq #"\"test warn\"" res)))))
|
(is (= 2 (count (re-seq #"\(\\a \\b\)" res)))))))
|
||||||
(testing "lists are printed readably"
|
|
||||||
(is (= 2 (count (re-seq #"\(\\a \\b\)" res))))))))
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue