Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky tests #94

Merged
merged 7 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Instances of quickblog can be seen here:

## Unreleased

- Fix flaky caching tests ([@jmglov](https://github.com/jmglov))
- Fix argument passing in test runner ([@jmglov](https://github.com/jmglov))
- Add `--date` to api/new. ([@jmglov](https://github.com/jmglov))
- Support Selmer template for new posts in api/new; see [Templates > New
Expand Down
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
18 changes: 13 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 @@ -311,6 +310,7 @@
:templates-dir templates-dir
:cache-dir cache-dir
:out-dir out-dir})]
(Thread/sleep 5)
(write-test-post posts-dir)
(write-test-file assets-dir "asset.txt" "something")
(render)
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 @@ -355,16 +361,17 @@
(is (= (map str [filename mtime])
(map str [filename (fs/last-modified-time filename)]))))
;; Should rewrite all but metadata-cached files when post modified
(Thread/sleep 5)
(write-test-post posts-dir)
(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
(Thread/sleep 5)
(write-test-post posts-dir {:title "Changed", :tags #{"not-clojure"}})
(render)
(doseq [[filename mtime] (merge content-cached metadata-cached)]
Expand Down Expand Up @@ -418,6 +425,7 @@
(is (= #{"clojure1.html"
"clojurescript1.html"}
(post-ids (fs/file out-dir "planetclojure.xml"))))
(Thread/sleep 5)
(write-test-post posts-dir {:file "clojure2.md"
:tags #{"clojure"}})
(write-test-post posts-dir {:file "random2.md"
Expand Down
Loading