clojure.test/inc-report-counter is not thread safe

Description

clojure.test/inc-report-counter function combines dereferencing the report-counters ref and operating on the previous state of the ref, leading to race conditions during concurrent use.

(dosync (commute *report-counters* assoc name (inc (or (*report-counters* name) 0))))

Approach: Rewrite update function to be entirely in terms of the old state:

(dosync (commute *report-counters* update-in [name] (fnil inc 0)))

Patch: fix-CLJ-1528.diff
Screened by: Alex Miller

Environment

OS X, Clojure 1.7, Macbook pro

Attachments

1
  • 19 Sep 2014, 04:58 PM

Activity

Show:

Alexander Redington September 19, 2014 at 4:58 PM

Fixes 1528

Completed

Details

Assignee

Reporter

Labels

Approval

Ok

Patch

Code

Priority

Affects versions

Fix versions

Created September 19, 2014 at 4:55 PM
Updated July 18, 2015 at 12:55 AM
Resolved July 18, 2015 at 12:55 AM