                         "http://puppetlabs.com/inventory_response" (deliver inventory-response msg)
                         "http://puppetlabs.com/inventory_update" (deliver @inventory-update msg))))]
       (with-app-with-config app (conj broker-services server/mock-server) broker-config
-        (is (deref inventory-response 3000 nil))
-        (is (= (:id inventory-subscribe) (:in_reply_to @inventory-response)))
-        (is (= [] (get-in @inventory-response [:data :uris])))
+        (let [answer (deref inventory-response 3000 nil)]
+          (is answer)
+          (is (= (:id inventory-subscribe) (:in_reply_to answer)))
+          (is (= [] (get-in answer [:data :uris]))))
 
         (with-open [client (client/connect :certname agent-cert)]
           (let [update (deref @inventory-update 3000 nil)]

        (server/wait-for-inbound-connection (get-context app :MockServer))
        (with-open [client (client/connect :certname agent-cert)]
          ;; Verify we get an inventory including the client
          (is (deref inventory-response 3000 nil))
          (is (= "http://puppetlabs.com/inventory_response" (:message_type @inventory-response)))
          (is (= (:id inventory-request) (:in_reply_to @inventory-response)))
          (is (= [agent-uri] (get-in @inventory-response [:data :uris])))

          (let [response (client/recv! client)
                target (:target response)

                                                                "wss://localhost:58144/server"
                                                                "wss://localhost:58145/server"])
        (doseq [server [:mock-server-1 :mock-server-2 :mock-server-3]]
          (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
