     (with-redefs [server/on-connect (fn [_ ws] (websockets-client/send! ws (message/encode self-request)))
                   server/on-text (fn [_ ws text] (deliver response (message/decode text)))]
       (with-app-with-config app (conj broker-services server/mock-server) broker-config
-        (is (deref response 3000 nil))
-        (is (= "http://puppetlabs.com/error_message" (:message_type @response)))
-        (is (= (:id self-request) (:in_reply_to @response)))
-        (is (= "Message not authorized." (:data @response)))))))
+        (let [answer (deref response 3000 nil)]
+          (is answer)
+          (is (= "http://puppetlabs.com/error_message" (:message_type answer)))
+          (is (= (:id self-request) (:in_reply_to answer)))
+          (is (= "Message not authorized." (:data answer))))))))
 
 (def spoof-sender-request (message/make-message
                             {:message_type "greeting"

                        (websockets-client/send! ws (message/encode agent-request)))
                      (deliver response2 (message/decode text))))]
      (with-app-with-config app (conj broker-services server/mock-server) broker-config
        (is (deref response1 3000 nil))
        (is (= "http://puppetlabs.com/inventory_response" (:message_type @response1)))
        (is (= (:id inventory-request) (:in_reply_to @response1)))
        (is (= [] (get-in @response1 [:data :uris])))

        (is (deref response2 3000 nil))
        (is (= "http://puppetlabs.com/error_message" (:message_type @response2)))
        (is (= (:id agent-request) (:in_reply_to @response2)))
        (is (= "Not connected." (:data @response2)))))))

(deftest controller-agent-connected-test
  (let [inventory-response (promise)


            ;; Verify message from client reaches controller
            (client/send! client (assoc agent-request :target sender :sender target))
            (let [agent-answer (deref agent-response 1000 nil)]
              (is agent-answer)
              (is (= "greeting" (:message_type agent-answer))))))))))

(def self-request (message/make-message
                    {:message_type "loopy"
