Skip to content

Commit

Permalink
Fix flaky caching tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmglov committed Feb 15, 2024
1 parent afbf21e commit d006ac4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/quickblog/internal.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@
(zipmap (map keyword ks)
ks))

;; Cons-ing *file* directly in `rendering-modified?` doesn't work for some reason
(def ^:private this-file (fs/file *file*))

(defn rendering-modified? [target-file rendering-system-files]
(let [rendering-system-files (cons this-file rendering-system-files)]
(seq (fs/modified-since target-file rendering-system-files))))
(seq (fs/modified-since target-file rendering-system-files)))

(defn copy-modified [src target]
(when (seq (fs/modified-since target src))
Expand Down
20 changes: 15 additions & 5 deletions test/quickblog/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@
:out-dir out-dir})
(is (not (str/includes? (slurp (fs/file out-dir "test.html")) lib/live-reload-script))))))

;; disabled, flaky in CI, cc @jmglov
#_(deftest caching
(deftest caching
(testing "assets"
(with-dirs [assets-dir
posts-dir
Expand All @@ -313,6 +312,7 @@
:out-dir out-dir})]
(write-test-post posts-dir)
(write-test-file assets-dir "asset.txt" "something")
(Thread/sleep 500)
(render)
(let [asset-file (fs/file out-dir "assets" "asset.txt")
mtime (fs/last-modified-time asset-file)]
Expand All @@ -332,9 +332,15 @@
(let [render #(api/render {:posts-dir posts-dir
:templates-dir templates-dir
:cache-dir cache-dir
:out-dir out-dir})]
:out-dir out-dir})
cache-dir (fs/file cache-dir "prod")]
(write-test-post posts-dir)
(render)
;; We need to render again, since the first render will have written
;; default templates for pages, post links, archive, and index after the
;; post, which means the post will be considered modified relative to
;; the templates dir
(render)
(let [->mtimes (fn [dir filenames]
(->> filenames
(map #(let [filename (fs/file dir %)]
Expand All @@ -350,22 +356,24 @@
(->mtimes (fs/file out-dir "tags")
["clojure.html"]))]
;; Shouldn't rewrite anything when post unmodified
(Thread/sleep 500)
(render)
(doseq [[filename mtime] (merge content-cached clojure-metadata-cached)]
(is (= (map str [filename mtime])
(map str [filename (fs/last-modified-time filename)]))))
;; Should rewrite all but metadata-cached files when post modified
(write-test-post posts-dir)
(Thread/sleep 500)
(render)
;; disabled, flaky, /cc @jmglov
#_(doseq [[filename mtime] content-cached]
(doseq [[filename mtime] content-cached]
(is (not= (map str [filename mtime])
(map str [filename (fs/last-modified-time filename)]))))
(doseq [[filename mtime] clojure-metadata-cached]
(is (= (map str [filename mtime])
(map str [filename (fs/last-modified-time filename)]))))
;; Should rewrite everything when metadata modified
(write-test-post posts-dir {:title "Changed", :tags #{"not-clojure"}})
(Thread/sleep 500)
(render)
(doseq [[filename mtime] (merge content-cached metadata-cached)]
(is (not= (map str [filename mtime])
Expand Down Expand Up @@ -422,6 +430,7 @@
:tags #{"clojure"}})
(write-test-post posts-dir {:file "random2.md"
:tags #{"something"}})
(Thread/sleep 500)
(let [mtimes (->mtimes out-dir ["atom.xml" "planetclojure.xml"])
_ (render)
mtimes-after (->mtimes out-dir ["atom.xml" "planetclojure.xml"])]
Expand All @@ -437,6 +446,7 @@
"clojure2.html"
"clojurescript1.html"}
(post-ids (fs/file out-dir "planetclojure.xml"))))
(Thread/sleep 500)
(let [mtimes (->mtimes out-dir ["atom.xml" "planetclojure.xml"])
_ (render)
mtimes-after (->mtimes out-dir ["atom.xml" "planetclojure.xml"])]
Expand Down

0 comments on commit d006ac4

Please sign in to comment.