Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed mutex from minitest.rb

Removed mutex from test.rb
Removed Minitest::Reporter.synchronize
Removed Minitest::Test.synchronize
Upon loading minitest/parallel_each, record, capture_io and capture_subprocess_io are doped with synchronization code.

Paired with @phiggins.

[git-p4: depot-paths = "//src/minitest/dev/": change = 8488]
  • Loading branch information...
commit 412c031fc0fdca85982af9ccf3e0875d4d26b537 1 parent b9b17e0
@zenspider zenspider authored
View
26 lib/minitest.rb
@@ -322,16 +322,6 @@ class Reporter
attr_accessor :sync, :old_sync # :nodoc:
- @mutex = nil
-
- def self.synchronize # :nodoc:
- if @mutex then # see parallel_each.rb
- @mutex.synchronize { yield }
- else
- yield
- end
- end
-
def initialize io = $stdout, options = {} # :nodoc:
self.io = io
self.options = options
@@ -381,17 +371,15 @@ def start
# result of the run if the run did not pass.
def record result
- Reporter.synchronize do
- self.count += 1
- self.assertions += result.assertions
+ self.count += 1
+ self.assertions += result.assertions
- io.print "%s#%s = %.2f s = " % [result.class, result.name, result.time] if
- options[:verbose]
- io.print result.result_code
- io.puts if options[:verbose]
+ io.print "%s#%s = %.2f s = " % [result.class, result.name, result.time] if
+ options[:verbose]
+ io.print result.result_code
+ io.puts if options[:verbose]
- results << result if not result.passed? or result.skipped?
- end
+ results << result if not result.passed? or result.skipped?
end
##
View
53 lib/minitest/assertions.rb
@@ -391,19 +391,15 @@ def capture_io
captured_stdout, captured_stderr = StringIO.new, StringIO.new
- synchronize do
- orig_stdout, orig_stderr = $stdout, $stderr
- $stdout, $stderr = captured_stdout, captured_stderr
+ orig_stdout, orig_stderr = $stdout, $stderr
+ $stdout, $stderr = captured_stdout, captured_stderr
- begin
- yield
- ensure
- $stdout = orig_stdout
- $stderr = orig_stderr
- end
- end
+ yield
return captured_stdout.string, captured_stderr.string
+ ensure
+ $stdout = orig_stdout
+ $stderr = orig_stderr
end
##
@@ -426,25 +422,21 @@ def capture_subprocess_io
captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err")
- synchronize do
- orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
- $stdout.reopen captured_stdout
- $stderr.reopen captured_stderr
+ orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
+ $stdout.reopen captured_stdout
+ $stderr.reopen captured_stderr
- begin
- yield
+ yield
- $stdout.rewind
- $stderr.rewind
+ $stdout.rewind
+ $stderr.rewind
- [captured_stdout.read, captured_stderr.read]
- ensure
- captured_stdout.unlink
- captured_stderr.unlink
- $stdout.reopen orig_stdout
- $stderr.reopen orig_stderr
- end
- end
+ return captured_stdout.read, captured_stderr.read
+ ensure
+ captured_stdout.unlink
+ captured_stderr.unlink
+ $stdout.reopen orig_stdout
+ $stderr.reopen orig_stderr
end
##
@@ -647,14 +639,5 @@ def skip msg = nil, bt = caller
def skipped?
defined?(@skip) and @skip
end
-
- ##
- # Takes a block and wraps it with the runner's shared mutex.
-
- def synchronize
- Minitest::Test.synchronize do
- yield
- end
- end
end
end
View
40 lib/minitest/parallel_each.rb
@@ -59,10 +59,50 @@ class << self
class Test
@mutex = Mutex.new
+
+ def self.synchronize # :nodoc:
+ if @mutex then # see parallel_each.rb
+ @mutex.synchronize { yield }
+ else
+ yield
+ end
+ end
+
+ alias :simple_capture_io :capture_io
+
+ def capture_io(&b)
+ Test.synchronize do
+ simple_capture_io(&b)
+ end
+ end
+
+ alias :simple_capture_subprocess_io :capture_subprocess_io
+
+ def capture_subprocess_io(&b)
+ Test.synchronize do
+ simple_capture_subprocess_io(&b)
+ end
+ end
end
class Reporter
@mutex = Mutex.new
+
+ def self.synchronize # :nodoc:
+ if @mutex then # see parallel_each.rb
+ @mutex.synchronize { yield }
+ else
+ yield
+ end
+ end
+
+ alias :simple_record :record
+
+ def record result
+ Reporter.synchronize do
+ simple_record result
+ end
+ end
end
##
View
10 lib/minitest/test.rb
@@ -12,8 +12,6 @@ class Test < Runnable
PASSTHROUGH_EXCEPTIONS = [NoMemoryError, SignalException, # :nodoc:
Interrupt, SystemExit]
- @mutex = nil
-
##
# Call this at the top of your tests when you absolutely
# positively need to have ordered tests. In doing so, you're
@@ -76,14 +74,6 @@ def self.runnable_methods
end
end
- def self.synchronize # :nodoc:
- if @mutex then # see parallel_each.rb
- @mutex.synchronize { yield }
- else
- yield
- end
- end
-
##
# Defines the order to run tests (:random by default). Override
# this or use a convenience method to change it for your tests.
View
4 test/minitest/test_minitest_mock.rb
@@ -289,7 +289,7 @@ def teardown
def assert_stub val_or_callable
@assertion_count += 1
- synchronize do
+ Minitest::Test.synchronize do
t = Time.now.to_i
Time.stub :now, val_or_callable do
@@ -345,7 +345,7 @@ def test_stub_block
def test_stub_block_args
@assertion_count += 1
- synchronize do
+ Minitest::Test.synchronize do
t = Time.now.to_i
Time.stub :now, lambda { |n| n * 2 } do
Please sign in to comment.
Something went wrong with that request. Please try again.