From 072d5a2fe1a9dd0c07ff590db47769d15dc51888 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Thu, 22 Aug 2024 12:48:37 +1000 Subject: [PATCH] Add test for mini racer forking safety --- test/mini_racer_test.rb | 12 ++++++++++++ test/test_forking.rb | 2 ++ 2 files changed, 14 insertions(+) diff --git a/test/mini_racer_test.rb b/test/mini_racer_test.rb index c21e889a..cef234e3 100644 --- a/test/mini_racer_test.rb +++ b/test/mini_racer_test.rb @@ -1164,4 +1164,16 @@ def test_threading_safety Thread.new { MiniRacer::Context.new.eval("100") }.join GC.start end + + + if RUBY_ENGINE == "truffleruby" + skip "TruffleRuby forking is not supported" + else + def test_forking + `bundle exec ruby test/test_forking.rb` + if $?.exitstatus != 0 + assert false, "forking test failed" + end + end + end end diff --git a/test/test_forking.rb b/test/test_forking.rb index 8490b03c..abc705ce 100644 --- a/test/test_forking.rb +++ b/test/test_forking.rb @@ -1,4 +1,5 @@ # use bundle exec to run this script +# require 'mini_racer' MiniRacer::Platform.set_flags! :single_threaded @@ -25,4 +26,5 @@ def trigger_gc if Process.respond_to?(:fork) Process.wait fork { puts @ctx.eval("a"); @ctx.dispose; puts Process.pid; trigger_gc; puts "done #{Process.pid}" } + exit $?.exitstatus || 1 end