Module: SimpleCov::ResultMerger::ResultsetStore
- Defined in:
- lib/simplecov/result_merger/resultset_store.rb
Overview
Reads and writes the persistent .resultset.json cache, including
file-lock synchronization between processes and atomic temp-file
renames so concurrent readers don't observe a truncated file.
Class Method Summary collapse
- .resultset_path ⇒ Object
-
.synchronize ⇒ Object
Serialize threads before taking the process-wide file lock.
- .with_flock ⇒ Object
-
.write(resultset) ⇒ Object
Compact JSON, not pretty-printed: this is a machine-read cache that every parallel worker rewrites wholesale, and on a large project pretty printing nearly doubles the bytes written, read back, and parsed on each of those store-merge round trips.
- .writelock_path ⇒ Object
Class Method Details
.resultset_path ⇒ Object
19 20 21 |
# File 'lib/simplecov/result_merger/resultset_store.rb', line 19 def resultset_path File.join(SimpleCov.coverage_path, ".resultset.json") end |
.synchronize ⇒ Object
Serialize threads before taking the process-wide file lock. Nested calls by the owning thread bypass flock so they cannot deadlock on a second descriptor for the same lock file.
38 39 40 41 42 |
# File 'lib/simplecov/result_merger/resultset_store.rb', line 38 def synchronize(&) return yield if LOCK_MONITOR.mon_owned? LOCK_MONITOR.synchronize { with_flock(&) } end |
.with_flock ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/simplecov/result_merger/resultset_store.rb', line 44 def with_flock FileUtils.mkdir_p(SimpleCov.coverage_path) File.open(writelock_path, "w+") do |f| f.flock(File::LOCK_EX) yield end end |
.write(resultset) ⇒ Object
Compact JSON, not pretty-printed: this is a machine-read cache that every parallel worker rewrites wholesale, and on a large project pretty printing nearly doubles the bytes written, read back, and parsed on each of those store-merge round trips.
31 32 33 |
# File 'lib/simplecov/result_merger/resultset_store.rb', line 31 def write(resultset) AtomicFile.write(resultset_path, "#{JSON.generate(resultset)}\n") end |
.writelock_path ⇒ Object
23 24 25 |
# File 'lib/simplecov/result_merger/resultset_store.rb', line 23 def writelock_path File.join(SimpleCov.coverage_path, ".resultset.json.lock") end |