Skip to content

Commit

Permalink
Fix flaky test
Browse files Browse the repository at this point in the history
This test wasn't properly waiting for the add emails to be sent.
  • Loading branch information
tobias committed Jul 2, 2023
1 parent cd2d213 commit 34e136a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/clojars/email.clj
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
(reset! email-latch (CountDownLatch. n))))

(defn wait-for-mock-emails
"Blocks for up to 100ms waiting for `n` emails to be sent via the mock,
where `n` was passed to `expect-mock-emails` (defaulting to 1 if not called).
Returns true if `n` reached within that time. Reset with `expect-mock-emails`
between tests using the same system."
[]
(.await @email-latch 100 TimeUnit/MILLISECONDS))
"Blocks for up to `wait-ms` (default: 100ms) waiting for `n` emails to be sent
via the mock, where `n` was passed to `expect-mock-emails` (defaulting to 1 if
not called). Returns true if `n` reached within that time. Reset with
`expect-mock-emails` between tests using the same system."
([]
(wait-for-mock-emails 100))
([wait-ms]
(.await @email-latch wait-ms TimeUnit/MILLISECONDS)))

(defn mock-mailer []
(expect-mock-emails)
Expand Down
5 changes: 5 additions & 0 deletions test/clojars/integration/users_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@
(register-as "dantheman" "[email protected]" "password")
(visit "/groups/org.clojars.dantheman")
(fill-in [:#username] "fixture")
((fn [session]
;; clear the add emails
(email/expect-mock-emails 2)
(email/wait-for-mock-emails 1000)
session))
(press "Add Member")
((fn [session] (email/expect-mock-emails 2) session))
(press "Remove Member"))
Expand Down

0 comments on commit 34e136a

Please sign in to comment.