           (with-open [client (client/connect :certname agent-cert)]
             (while (empty? (:inventory @(:database broker)))
               (Thread/sleep 100))
-            (is (deref inventory-response 3000 nil))
-            @first-update-sent?
-            (is (= (:id inventory-subscribe) (:in_reply_to @inventory-response)))
+            (let [answer (deref inventory-response 3000 nil)]
+              (is answer)
+              (is (= (:id inventory-subscribe) (:in_reply_to answer))))
+            (is (deref first-update-sent? 3000 nil))
             ;; Disconnect the mock server
             (doseq [ws @(:inventory (get-context app :MockServer))]
               (websockets-client/close! ws))

    (with-redefs [server/on-connect (fn [_ ws] (websockets-client/send! ws (message/encode spoof-sender-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 spoof-sender-request) (:in_reply_to @response)))
        (is (= "Message not authenticated." (:data @response)))))))

(deftest multiple-controllers-test
  (let [responses {:mock-server-1 [(promise) (promise)]

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