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