                                                                 "wss://localhost:58144/server"
                                                                 "wss://localhost:58145/server"])
         (doseq [server [:mock-server-1 :mock-server-2 :mock-server-3]]
-          (let [[response1 response2] (get responses server)]
-            (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)))))))))
+          (testing (str "connected to " server ", inventory response received, and agent unreachable")
+            (let [[response1 response2] (get responses server)]
+              (let [answer (deref response1 3000 nil)]
+                (is answer)
+                (is (= "http://puppetlabs.com/inventory_response" (:message_type answer)))
+                (is (= (:id inventory-request) (:in_reply_to answer)))
+                (is (= [] (get-in answer [:data :uris]))))
+
+              (let [answer (deref response2 3000 nil)]
+                (is answer)
+                (is (= "http://puppetlabs.com/error_message" (:message_type answer)))
+                (is (= (:id agent-request) (:in_reply_to answer)))
+                (is (= "Not connected." (:data answer)))))))))))
 
 (def inventory-subscribe
   (client/make-message

                        (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)

    (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
        (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"
