           (handler [context]
             (ct/websocket context websocket))]
     (with-server handler
-      (let [p (promise)]
-        (ws/connect! "ws://localhost:5050/"
-                     (fn [{:keys [in out]}]
-                       (go
-                         (>! out "PING")
-                         (when (= "PONG" (<! in))
-                           (close! out)
-                           (deliver p true)))))
-        (is (deref p 1000 false))))))
+      (let [conn @(http/websocket-client "ws://localhost:5050/")]
+        (deref (s/put! conn "PING"))
+        (let [rsp @(s/take! conn)]
+          (is (= "PONG" rsp))
+          (s/close! conn))))))
 
 (deftest websocket-handshake-websocket-handler
   (letfn [(handler [{:keys [in out]}]

                (close! out))))]
    (with-server (with-meta handler
                   {:handler-type :catacumba/websocket})
      (let [p (promise)]
        (ws/connect! "ws://localhost:5050/"
                     (fn [{:keys [in out]}]
                       (go
                         (>! out "PING")
                         (when (= "PONG" (<! in))
                           (close! out)
                           (deliver p true)))))
        (is (deref p 1000 false)))))
)

(deftest websockets-backpressure
  (let [p1 (promise)
        p2 (promise)
        p3 (promise)]
    (letfn [(handler [{:keys [in out]}]
              (go
                (let [received (<! in)]

                  (deliver p3 received))
                (>! out "PONG")
                (close! out)))]

      (with-server (with-meta handler {:handler-type :catacumba/websocket})
        (thread
          (let [conn @(http/websocket-client "ws://localhost:5050/")]
            @(s/put! conn "foo")
            (<!! (timeout 100))
            @(s/put! conn "bar")
            (<!! (timeout 100))
            @(s/put! conn "baz")
            (let [rsp @(s/take! conn)]
              (when (= rsp "PONG")
                (deliver p4 true)))))
        (is (deref p4 2000 false))))))
