Skip to content

Commit

Permalink
Use WunderBoss that allows WS onClose to work in-WF [IMMUTANT-529]
Browse files Browse the repository at this point in the history
This also includes tests to confirm.
  • Loading branch information
tobias committed Feb 20, 2015
1 parent 805b4ec commit 2a32086
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
6 changes: 3 additions & 3 deletions project.clj
Expand Up @@ -90,8 +90,8 @@
potemkin "0.3.11"
clj-http "1.0.1"

org.projectodd.wunderboss "0.4.1"
;; org.projectodd.wunderboss "1.x.incremental.193"
;; org.projectodd.wunderboss "0.4.1"
org.projectodd.wunderboss "1.x.incremental.195"
;; org.projectodd.wunderboss "0.5.0-SNAPSHOT"

org.immutant :version}}
Expand All @@ -100,7 +100,7 @@
["change" "version" "set" "\"2.0.0-beta2\""]
["modules" "change" "version" "set" "\"2.0.0-beta2\""]

["modules" ":dirs" ".,web,messaging,transactions,scheduling,caching"
["modules" ":dirs" ".,web,messaging,transactions,scheduling,caching"
"file-replace" "README.md" "(<version>| \")" "(\"]|</version>)" "version"]

["vcs" "commit"]
Expand Down
3 changes: 2 additions & 1 deletion web/src/immutant/web/internal/servlet.clj
Expand Up @@ -125,7 +125,8 @@
(when (instance? WebsocketChannel body)
(-> config
.getUserProperties
(.put "Endpoint" (.endpoint ^WebsocketChannel body)))))))
(.put DelegatingJavaxEndpoint/ENDPOINT_KEY
(.endpoint ^WebsocketChannel body)))))))

(defn ^Servlet create-servlet
"Encapsulate a ring handler within a servlet"
Expand Down
24 changes: 24 additions & 0 deletions web/test-integration/immutant/web/integ_test.clj
Expand Up @@ -212,6 +212,30 @@
(ws/send-msg socket "hello")
(is (= 1000 (:code (read-string (get-body (str (cdef-url) "state"))))))))

(deftest ws-on-close-should-be-invoked-when-closing-on-client
(replace-handler
'(do
(reset! client-state (promise))
(fn [request]
(async/as-channel request
:on-close (fn [_ r] (deliver @client-state r))))))
(let [socket (ws/connect (cdef-url "ws"))]
(ws/close socket)
(is (= 1000 (:code (read-string (get-body (str (cdef-url) "state"))))))))

(deftest ws-on-close-should-be-invoked-for-every-connection
(replace-handler
'(do
(reset! client-state #{})
(fn [request]
(async/as-channel request
:on-close (fn [ch r] (swap! client-state conj (str ch)))))))
(let [socket1 (ws/connect (cdef-url "ws"))
socket2 (ws/connect (cdef-url "ws"))]
(ws/close socket1)
(ws/close socket2)
(is (= 2 (-> (str (cdef-url) "state") get-body read-string count)))))

(deftest ws-on-complete-should-be-called-after-send
(replace-handler
'(do
Expand Down

0 comments on commit 2a32086

Please sign in to comment.