           (event->str {:data (range 3)})))))
 
 (deftest sse
-  (let [closed (promise)
+  (let [complete (promise)
+        closed (promise)
         result (atom [])
         app (fn [req]
               (as-channel req

                             (send! ch x)
                             (Thread/sleep 10))
                           (send! ch {:event "close", :data "bye!"}
                             {:on-complete (fn [_] (swap! result conj :done))}))))
        server (run app)
        client (event-source "http://localhost:8080")]
    (handle-events client (fn [e]

                              (.close client)
                              (deliver closed :success))))
    (.open client)
    (is (= :success (deref complete 2000 :fail)))
    (is (= :success (deref closed 2000 :fail)))
    (is (not (.isOpen client)))
    (is (= ["5" "4" "3" "2" "1" "bye!"] @result))
    (stop server)))

(deftest sse-should-be-utf8-and-have-proper-content-type
