Browse files

Merge pull request #6020 from 7even/test_queue_order

Rails::Queueing::TestQueue run order
  • Loading branch information...
2 parents 4dcaffb + 804db94 commit 3ca7b137fbc7001a9b3384d2a44132913a93bb4b @tenderlove tenderlove committed Apr 27, 2012
Showing with 14 additions and 1 deletion.
  1. +1 −1 railties/lib/rails/queueing.rb
  2. +13 −0 railties/test/queueing/test_queue_test.rb
View
2 railties/lib/rails/queueing.rb
@@ -18,7 +18,7 @@ def drain
# run the jobs in a separate thread so assumptions of synchronous
# jobs are caught in test mode.
t = Thread.new do
- while job = @contents.pop
+ while job = @contents.shift
job.run
end
end
View
13 railties/test/queueing/test_queue_test.rb
@@ -25,6 +25,19 @@ def test_contents
assert_equal [job], @queue.contents
end
+ def test_order
+ time1 = time2 = nil
+
+ job1 = Job.new(1) { time1 = Time.now }
+ job2 = Job.new(2) { time2 = Time.now }
+
+ @queue.push job1
+ @queue.push job2
+ @queue.drain
+
+ assert time1 < time2, "Jobs run in the same order they were added"
+ end
+
def test_drain
t = nil
ran = false

0 comments on commit 3ca7b13

Please sign in to comment.