                                         :utils utils})
                    component/start)]
     (try
-      (assert (deref emails-done 5000 false) "send-email not done")
-      (assert (deref gi-done 5000 false) "create-github-issue not done")
+      ; Wait for the first update by worker and update libraries.
+      (acquire email-semaphore 2)
+      (acquire gi-semaphore 1)
+      (reset! versions {"lib-1" 3
+                        "lib-2" 4
+                        "lib-3" 5
+                        "lib-4" 6})
+
+      ; Wait for the second update by worker and verify send-email
+      ; and create-github-issue mocks.
+      (acquire email-semaphore 2)
+      (acquire gi-semaphore 1)
       (assert-emails-args @email-args)
       (assert-github-issue-args @gi-args)
 

        :body (str "Body lib-3 5.0 4.0 Default {{not-used}}"
                   "\n\nThis issue is created on behalf of @dummy-login")}))

(defn run-worker
  "Run worker jobs. The job will be run 2 times."
  [db]
  (let [; send-email is called 4 times: 2 times for 2 actions.
        ; Both first and second users have email actions.
        email-args (atom [])
        emails-done (promise)
        send-email (create-function-mock email-args 4 emails-done)

        ; create-github-issue is run 2 times: first user has single
        ; github-issue action.
        gi-args (atom [])
        gi-done (promise)
        create-github-issue (create-function-mock gi-args 2 gi-done)

        utils {:send-email send-email
               :create-github-issue create-github-issue}

(defn mock-latest-release-fn
  "Create latest-release version which returns
  new version every time it called."
  [versions]
  (fn [library]
    (str (@versions library) ".0")))

(defn create-function-mock
  "Creates mock funciton which saves all arguments it called with into
  'arguments' atom vector. Also releases a permit on provided semaphore."
  [arguments semaphore]
  (fn [& args]
    (swap! arguments conj (vec args))
    (.release semaphore)))

(defn create-actions []
  (binding [clj-http.core/*cookie-store* (clj-http.cookies/cookie-store)]
