summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorBarrett Ingram <barrettkingram@gmail.com>2021-07-03 07:55:57 -0500
committerGitHub <noreply@github.com>2021-07-03 15:55:57 +0300
commitd6f31838757d3a490b3d368994115875eed798c9 (patch)
tree7da4ab43bccd118cb05d994548cd5d9a172cceaf /spec
parent58a026d8f1e4a2d31dc782d29333647b58d58714 (diff)
downloadpry-d6f31838757d3a490b3d368994115875eed798c9.tar.gz
Return with an error message if pry is started inside signal handler (#2206)
Mutex#synchronize will throw an error if called from code passed to Signal.trap. This makes it impossible to start a working Pry session inside a signal handler. Currently, calling binding.pry inside signal handling code raises an exception because Pry uses mutexes to solve various thread-safety issues. This commit updates Pry.start to detect whether we'll have the ability to use Mutex#synchronize. If not, we'll print an error message and return instead of raising an error. https://github.com/pry/pry/issues/2191
Diffstat (limited to 'spec')
-rw-r--r--spec/pry_spec.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/pry_spec.rb b/spec/pry_spec.rb
index 1ea0210d..f5bb0713 100644
--- a/spec/pry_spec.rb
+++ b/spec/pry_spec.rb
@@ -184,6 +184,31 @@ describe Pry do
.to raise_error SignalException
end
+ describe "inside signal handler" do
+ before do
+ if Pry::Helpers::Platform.jruby?
+ skip "jruby allows mutex usage in signal handlers"
+ end
+
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.0.0")
+ skip "pre-2.0 mri allows mutex usage in signal handlers"
+ end
+
+ trap("USR1") { @str_output = mock_pry }
+ end
+
+ after do
+ trap("USR1") do
+ # do nothing
+ end
+ end
+
+ it "should return with error message" do
+ Process.kill("USR1", Process.pid)
+ expect(@str_output).to match(/Unable to obtain mutex lock/)
+ end
+ end
+
describe "multi-line input" do
it "works" do
expect(mock_pry('x = ', '1 + 4')).to match(/5/)