-
-
Save tobias/22a799e06969276e542e to your computer and use it in GitHub Desktop.
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
(deftest websocket-from-servlet | |
(let [path "/test-servlet" | |
events (atom []) | |
result (promise) | |
handler (fn [req] | |
(as-channel req | |
{:on-open (fn [_] | |
(swap! events conj :open)) | |
:on-close (fn [_ {c :code}] | |
(deliver result (swap! events conj c))) | |
:on-message (fn [_ m] | |
(swap! events conj m))})) | |
servlet (create-servlet handler)] | |
(try | |
(run servlet {:path path}) | |
(let [socket (ws/connect (str "ws://localhost:8080" path))] | |
(ws/send-msg socket "hello") | |
(ws/close socket)) | |
(is (= [:open "hello" 1001] (deref result 2000 [:fail]))) | |
(finally | |
(stop {:path path}))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment