aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2016-06-08 15:52:02 -0500
committerschneems <richard.schneeman@gmail.com>2016-06-08 15:52:02 -0500
commit7d733b9f0f847d67d8759421f6820ebc57567647 (patch)
tree078ca210ac525ef76e2b39c3662c01074074d93b /activesupport
parenta8f29f6455c303bbd321af248a730ca8b41f2f27 (diff)
downloadrails-7d733b9f0f847d67d8759421f6820ebc57567647.tar.gz
rails-7d733b9f0f847d67d8759421f6820ebc57567647.tar.bz2
rails-7d733b9f0f847d67d8759421f6820ebc57567647.zip
Test how evented file checker handles forks
Pretty proud of this. We are testing distributed processes synchronized via pipes which makes it deterministic. Pretty cool. We boot a listener in the parent process we then fork. Before we touch the file we verify the fork is booted using pipes. Then the parent process will touch the file while the fork waits on a pipe. Once the parent process signals that the file has been touched we continue inside of the fork.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/test/evented_file_update_checker_test.rb43
1 files changed, 42 insertions, 1 deletions
diff --git a/activesupport/test/evented_file_update_checker_test.rb b/activesupport/test/evented_file_update_checker_test.rb
index ce2e05da2c..2cb2d8167f 100644
--- a/activesupport/test/evented_file_update_checker_test.rb
+++ b/activesupport/test/evented_file_update_checker_test.rb
@@ -12,7 +12,6 @@ class EventedFileUpdateCheckerTest < ActiveSupport::TestCase
def new_checker(files = [], dirs = {}, &block)
ActiveSupport::EventedFileUpdateChecker.new(files, dirs, &block).tap do |c|
- c.updated?
wait
end
end
@@ -35,6 +34,48 @@ class EventedFileUpdateCheckerTest < ActiveSupport::TestCase
super
wait
end
+
+ test 'notifies forked processes' do
+ FileUtils.touch(tmpfiles)
+
+ checker = new_checker(tmpfiles) { }
+ assert !checker.updated?
+
+ # Pipes used for flow controll across fork.
+ boot_reader, boot_writer = IO.pipe
+ touch_reader, touch_writer = IO.pipe
+
+ pid = fork do
+ assert checker.updated?
+
+ # Clear previous check value.
+ checker.execute
+ assert !checker.updated?
+
+ # Fork is booted, ready for file to be touched
+ # notify parent process.
+ boot_writer.write("booted")
+
+ # Wait for parent process to signal that file
+ # has been touched.
+ IO.select([touch_reader])
+
+ assert checker.updated?
+ end
+
+ assert pid
+
+ # Wait for fork to be booted before touching files.
+ IO.select([boot_reader])
+ touch(tmpfiles)
+
+ # Notify fork that files have been touched.
+ touch_writer.write("touched")
+
+ assert checker.updated?
+
+ Process.wait(pid)
+ end
end
class EventedFileUpdateCheckerPathHelperTest < ActiveSupport::TestCase