Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
fixup! Combine Mutex with ReentrantMutex
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Dec 14, 2020
1 parent 03dbe8f commit 2c58e18
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
11 changes: 0 additions & 11 deletions lib/rspec/support/mutex.rb

This file was deleted.

10 changes: 8 additions & 2 deletions lib/rspec/support/reentrant_mutex.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
RSpec::Support.require_rspec_support "mutex"

module RSpec
module Support
# This class protects us against Mutex.new stubbed out within tests.
# @private
class Mutex < ::Mutex
class << self
define_method(:new, &::Mutex.method(:new))
end
end

# Allows a thread to lock out other threads from a critical section of code,
# while allowing the thread with the lock to reenter that section.
#
Expand Down
8 changes: 0 additions & 8 deletions spec/rspec/support/mutex_spec.rb

This file was deleted.

7 changes: 7 additions & 0 deletions spec/rspec/support/reentrant_mutex_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
require 'rspec/support/reentrant_mutex'
require 'thread_order'

RSpec.describe RSpec::Support::Mutex do
it "allows ::Mutex to be mocked" do
expect(Mutex).to receive(:new)
::Mutex.new
end
end

# There are no assertions specifically
# They pass if they don't deadlock
RSpec.describe RSpec::Support::ReentrantMutex do
Expand Down

0 comments on commit 2c58e18

Please sign in to comment.