Created
January 27, 2015 15:02
-
-
Save jcrossley3/a50dfc633fadb94e9f3f 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 sse | |
(let [closed (promise) | |
result (atom []) | |
app (fn [req] | |
(as-sse-channel req | |
:on-open (fn [ch] | |
(doseq [x (range 5 0 -1)] | |
(send! ch x)) | |
(send! ch {:event "close", :data "bye!"}) | |
(send! ch "to detect the client close")), | |
:on-close (fn [ch _] (deliver closed :success)))) | |
server (run app) | |
client (event-source "http://localhost:8080")] | |
(.register client (reify EventListener | |
(onEvent [_ e] | |
(swap! result conj (.readData e)) | |
(when (= "close" (.getName e)) | |
(.close client))))) | |
(.open client) | |
(is (= :success (deref closed 5000 :fail))) | |
(is (not (.isOpen client))) | |
(is (= ["5" "4" "3" "2" "1" "bye!"] @result)) | |
(stop server))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment