From 413f2709c4e4efa8740036eacd5d55997577ac0f Mon Sep 17 00:00:00 2001 From: tomykaira Date: Thu, 16 May 2013 23:55:30 +0900 Subject: [PATCH 1/2] Lock resultset json file To prevent two processes writes at the same time. --- lib/simplecov/result_merger.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/simplecov/result_merger.rb b/lib/simplecov/result_merger.rb index c114463e..23570aec 100644 --- a/lib/simplecov/result_merger.rb +++ b/lib/simplecov/result_merger.rb @@ -66,6 +66,7 @@ def store_result(result) command_name, data = result.to_hash.first new_set[command_name] = data File.open(resultset_path, "w+") do |f| + f.flock(File::LOCK_EX) f.puts SimpleCov::JSON.dump(new_set) end true From b5af664e7851d4b010763f9df6ba27a2570f1313 Mon Sep 17 00:00:00 2001 From: tomykaira Date: Thu, 16 May 2013 23:58:05 +0900 Subject: [PATCH 2/2] Rescue LoadError and return empty set --- lib/simplecov/result_merger.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/simplecov/result_merger.rb b/lib/simplecov/result_merger.rb index 23570aec..c9c05971 100644 --- a/lib/simplecov/result_merger.rb +++ b/lib/simplecov/result_merger.rb @@ -13,7 +13,11 @@ def resultset_path # Loads the cached resultset from YAML and returns it as a Hash def resultset if stored_data - SimpleCov::JSON.parse(stored_data) + begin + SimpleCov::JSON.parse(stored_data) + rescue + {} + end else {} end