about summary refs log tree commit homepage
path: root/t/app_deferred.ru
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-01-09 18:59:00 +0000
committerEric Wong <e@80x24.org>2017-01-09 18:59:00 +0000
commitf385ed423e11ad40822f688bc592eaa78efa5b34 (patch)
tree1cc73c8b3c1ebba45c2ed23d27c32467e778fe4b /t/app_deferred.ru
parent28194bd423ee559a2693459fcceb24ea1200863b (diff)
downloadrainbows-f385ed423e11ad40822f688bc592eaa78efa5b34.tar.gz
Since EventMachine 1.0.0 in 2012, the EM.defers_finish? API
exists to check for the existence of deferred actions.
Support it if it exists in the running version of EM and
update the note in our SIGNALS document.

Thanks to <alex0375@gmail.com> on the mailing list for bringing
this up:
https://bogomips.org/rainbows-public/CAKwvcL-VH3we4qA1pkNAstTmWvqNA=Rir2N_YiWztV_qbaLQvA@mail.gmail.com/
Diffstat (limited to 't/app_deferred.ru')
-rw-r--r--t/app_deferred.ru8
1 files changed, 7 insertions, 1 deletions
diff --git a/t/app_deferred.ru b/t/app_deferred.ru
index a70b33b..b3d7ff1 100644
--- a/t/app_deferred.ru
+++ b/t/app_deferred.ru
@@ -6,12 +6,18 @@
 
 class DeferredApp < Struct.new(:app)
   def deferred?(env)
-    env["PATH_INFO"] == "/deferred"
+    env["PATH_INFO"] =~ %r{\A/deferred}
   end
 
   def call(env)
     env["rack.multithread"] or raise RuntimeError, "rack.multithread not true"
     body = "#{Thread.current.inspect}\n"
+    if env["PATH_INFO"] =~ %r{\A/deferred(\d+)}
+      delay = $1.to_i
+      File.open(ENV['fifo'], 'w') { |fp| fp.write "sleeping #{delay}s\n" }
+      body = "deferred sleep\n"
+      sleep(delay)
+    end
     headers = {
       "Content-Type" => "text/plain",
       "Content-Length" => body.size.to_s,