 (defn mock-latest-release-fn
   "Create latest-release version which returns
   new version every time it called."
-  []
-  (let [versions (atom {"lib-1" 0
-                        "lib-2" 1
-                        "lib-3" 2
-                        "lib-4" 3})]
-    (fn [library]
-      (timbre/debug library)
-      (let [version (-> versions
-                        (swap! update-in [library] inc)
-                        (get library))]
-        (str version ".0")))))
+  [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 delivers 'true' to the 'finished' promise
-  once it called times-to-call times."
-  [arguments times-to-call finished]
-  (let [counter (atom times-to-call)]
-    (fn [& args]
-      (when (zero? @counter)
-        (throw (ex-info (str "Function expected to be called only "
-                             times-to-call " times.")
-                        {})))
-      (swap! arguments conj (vec args))
-      (when (zero? (swap! counter dec))
-        (deliver finished true)))))
+  '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)]


      (assert (= (count bar-actions) 1))
      (assert (and (= (:library (first bar-actions)) "lib-4")
               (= (:last-processed-version (first bar-actions))
                  "6.0"))))))

(deftest worker-integration-test
  (let [db (component/start (get-db))
        web-server (component/start (map->WebServer {:config config
                                                     :db db}))]
    (timbre/set-level! :info)
    (try
      (with-redefs [ver/latest-release (mock-latest-release-fn)]
        (create-actions)
        (run-worker db)
        (assert-actions-updated))
      (finally
        (component/stop web-server)

            [hatnik.versions :as ver]
            [com.stuartsierra.component :as component]
            [hatnik.test-utils :refer :all :exclude [config]]
            [taoensso.timbre :as timbre])
  (:import [java.util.concurrent Semaphore TimeUnit]))

;;;
;;; Integration test that verifies that worker job is executed periodically.
