From f304f04ded4dfcfb8b370924675da079597daf41 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Tue, 17 Sep 2019 19:19:09 +0200 Subject: [PATCH] Always run concurrency tests for File adapter with threads Since fork is not available on some platforms (aka. Windows), we avoid it and use normal Threads instead. We have fail saves in place to ensure that tests are still valid even on MRI with its GIL. --- spec/rackstash/adapter/file_spec.rb | 31 ++++++++--------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/spec/rackstash/adapter/file_spec.rb b/spec/rackstash/adapter/file_spec.rb index 233c835..cf94a2b 100644 --- a/spec/rackstash/adapter/file_spec.rb +++ b/spec/rackstash/adapter/file_spec.rb @@ -332,32 +332,17 @@ RSpec.describe Rackstash::Adapter::File do # start at about the same time logfile.flock(File::LOCK_EX) - if Concurrent.on_cruby? - worker_processes = Array.new(workers) { |worker_id| - Process.fork do - run_worker worker_id - end - } - - # Workers will only start writing once we have released the lock - logfile.flock(File::LOCK_UN) - - worker_processes.each do |pid| - Process.wait(pid) + worker_threads = Array.new(workers) { |worker_id| + Thread.new do + run_worker worker_id end - else - worker_threads = Array.new(workers) { |worker_id| - Thread.new do - run_worker worker_id - end - } + } - # Worker threads will only start writing once we have released the lock - logfile.flock(File::LOCK_UN) + # Worker threads will only start writing once we have released the lock + logfile.flock(File::LOCK_UN) - worker_threads.each do |thread| - thread.join - end + worker_threads.each do |thread| + thread.join end # Resulting file size is exactly as expected, i.e. no dropped logs