                                       (fn [context] (:result context 10)))))
         (.countDown latch)))
     (testing ":all-services-rejected returned if all services reject action"
-      (let [latch (CountDownLatch. 1)]
-        (beehive/submit-action service1 (fn [] (.await latch)) Long/MAX_VALUE)
-        (beehive/submit-action service2 (fn [] (.await latch)) Long/MAX_VALUE)
-        (beehive/submit-action service3 (fn [] (.await latch)) Long/MAX_VALUE)
+      (let [submitted-latch (CountDownLatch. 3)
+            latch (CountDownLatch. 1)
+            action (blocking-action latch submitted-latch)]
+        (beehive/submit-action service1 action Long/MAX_VALUE)
+        (beehive/submit-action service2 action Long/MAX_VALUE)
+        (beehive/submit-action service3 action Long/MAX_VALUE)
+        (.await submitted-latch)
         (is (= :all-services-rejected
                @(patterns/submit-action
                   load-balancer


(use-fixtures :each start-and-stop)

(deftest load-balancer
  (let [load-balancer (patterns/load-balancer {service1 {:result 1}
                                               service2 {:result 2}

                      load-balancer (fn [context] (:result context 10))))))))

    (testing "If action rejected, other services will be called."
      (let [submitted-latch (CountDownLatch. 2)
            latch (CountDownLatch. 1)
            action (blocking-action latch submitted-latch)]
        (beehive/submit-action service1 action Long/MAX_VALUE)
        (beehive/submit-action service3 action Long/MAX_VALUE)
        (.await submitted-latch)
        (is (= 2 @(patterns/submit-action load-balancer
                                          (fn [context] (:result context 10))
                                          1000)))
