Permalink
Browse files

Clean and fix tests

  • Loading branch information...
1 parent 5ead5f5 commit 9b8217c892c1b168799714671e33b6879ff6b5f6 @chrisroberts chrisroberts committed Apr 21, 2012
Showing with 23 additions and 17 deletions.
  1. +8 −5 test/cases/general.rb
  2. +2 −2 test/cases/queue.rb
  3. +2 −2 test/cases/shutdown.rb
  4. +3 −2 test/cases/thread.rb
  5. +5 −5 test/cases/timeouts.rb
  6. +3 −1 test/run_tests.rb
View
@@ -36,18 +36,21 @@ def test_args
@pool.status :open
output = nil
@pool << [lambda{|x| output = x}, [2]]
- assert(2, output)
+ sleep(0.1)
+ assert_equal(2, output)
output = nil
@pool.add_jobs([[lambda{|x| output = x}, [3]]])
- assert(3, output)
+ sleep(0.1)
+ assert_equal(3, output)
output = nil
@pool << [lambda{|x,y| output = x+y}, [1,2]]
- assert(3, output)
+ sleep(0.1)
+ assert_equal(3, output)
output = nil
arr = []
@pool.add_jobs([[lambda{|x,y| arr << x + y}, [1,1]], [lambda{|x| arr << x}, [3]]])
::Thread.pass
- sleep(0.01)
+ sleep(0.1)
assert(arr.include?(2))
assert(arr.include?(3))
arr.clear
@@ -57,4 +60,4 @@ def test_args
assert(arr[1].is_a?(Array))
@pool.shutdown(true)
end
-end
+end
View
@@ -7,7 +7,7 @@ def setup
end
def test_pop
3.times{|i|@queue << i}
- 3.times{|i|assert(i, @queue.pop)}
+ 3.times{|i|assert_equal(i, @queue.pop)}
assert(@queue.empty?)
end
def test_pause
@@ -31,4 +31,4 @@ def test_pause
sleep(0.01)
assert(output)
end
-end
+end
View
@@ -12,7 +12,7 @@ def test_close
result = 0
@pool << lambda{ result = 5 }
sleep(0.01)
- assert(5, result)
+ assert_equal(5, result)
@pool.status :closed
assert_raise(ActionPool::PoolClosed) do
@pool << lambda{}
@@ -33,4 +33,4 @@ def test_shutdown
assert_equal(10, @pool.size)
@pool.shutdown(true)
end
-end
+end
View
@@ -17,11 +17,12 @@ def test_thread
assert(@thread.alive?)
stop = false
10.times{ @pool << lambda{ a = 0; a += 1 until stop || a > 9999999999 } }
- assert(!@thread.waiting?)
+ sleep(0.1)
+ assert(!@thread.waiting?, 'Thread is waiting')
@thread.stop(:force)
sleep(0.01)
assert(!@thread.alive?)
stop = true
@pool.shutdown(true)
end
-end
+end
View
@@ -26,7 +26,7 @@ def test_actiontimeout
sleep(0.3)
assert_equal(0, @pool.working)
assert_equal(20, output.size)
- assert_equal(20, @pool.size)
+ assert_equal(10, @pool.size)
@pool.shutdown(true)
end
def test_threadtimeout
@@ -39,11 +39,11 @@ def test_threadtimeout
end }, 0, 20)
@pool.add_jobs(t)
::Thread.pass
- sleep(0.01)
+ sleep(0.05)
assert(@pool.size >= 20)
::Thread.pass
- sleep(0.1)
- assert(10, @pool.size)
+ sleep(0.2)
+ assert_equal(10, @pool.size)
@pool.shutdown(true)
end
-end
+end
View
@@ -1,8 +1,10 @@
+#!/bin/env ruby
+
$LOAD_PATH.unshift(File.expand_path("#{__FILE__}/../../lib"))
require 'test/unit'
require 'actionpool'
Dir.glob(File.join(File.dirname(__FILE__), 'cases', '*.rb')).each do |file|
- require file
+ require File.expand_path(file)
end

0 comments on commit 9b8217c

Please sign in to comment.