Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed race condition in tests.

  • Loading branch information...
commit 4dda757c172e89a494057a464974f05211c78376 1 parent 6fe3f8e
@jimweirich jimweirich authored
Showing with 16 additions and 6 deletions.
  1. +3 −1 Rakefile
  2. +13 −5 test/lib/multitask_test.rb
View
4 Rakefile
@@ -102,7 +102,9 @@ begin
'--sort coverage'
] + FileList['rakelib/*.rake'].pathmap("-x%p")
t.test_files = FileList[
- 'test/test*.rb', 'test/functional.rb'
+ 'test/lib/*_test.rb',
+ 'test/contrib/*_test.rb',
+ 'test/functional/*_test.rb'
]
t.output_dir = 'coverage'
t.verbose = true
View
18 test/lib/multitask_test.rb
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require 'test/unit'
+require 'thread'
require 'rake'
######################################################################
@@ -10,11 +11,18 @@ class TestMultiTask < Test::Unit::TestCase
def setup
Task.clear
@runs = Array.new
+ @mutex = Mutex.new
+ end
+
+ def add_run(obj)
+ @mutex.synchronize do
+ @runs << obj
+ end
end
def test_running_multitasks
- task :a do 3.times do |i| @runs << "A#{i}"; sleep 0.01; end end
- task :b do 3.times do |i| @runs << "B#{i}"; sleep 0.01; end end
+ task :a do 3.times do |i| add_run("A#{i}"); sleep 0.01; end end
+ task :b do 3.times do |i| add_run("B#{i}"); sleep 0.01; end end
multitask :both => [:a, :b]
Task[:both].invoke
assert_equal 6, @runs.size
@@ -25,9 +33,9 @@ def test_running_multitasks
end
def test_all_multitasks_wait_on_slow_prerequisites
- task :slow do 3.times do |i| @runs << "S#{i}"; sleep 0.05 end end
- task :a => [:slow] do 3.times do |i| @runs << "A#{i}"; sleep 0.01 end end
- task :b => [:slow] do 3.times do |i| @runs << "B#{i}"; sleep 0.01 end end
+ task :slow do 3.times do |i| add_run("S#{i}"); sleep 0.05 end end
+ task :a => [:slow] do 3.times do |i| add_run("A#{i}"); sleep 0.01 end end
+ task :b => [:slow] do 3.times do |i| add_run("B#{i}"); sleep 0.01 end end
multitask :both => [:a, :b]
Task[:both].invoke
assert_equal 9, @runs.size
Please sign in to comment.
Something went wrong with that request. Please try again.