aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorPaul Battley <pbattley@gmail.com>2012-07-03 10:29:32 +0100
committerPaul Battley <pbattley@gmail.com>2012-07-03 12:01:53 +0100
commit8e1d8fd0934b8e04fd6b1f8f8d4de17cd3b1abe5 (patch)
tree777c5c0d97aa356b96196be8d1b0e237f68b883f /railties
parent55456ad34ac2be56392bce074577ebc0aeb509b2 (diff)
downloadrails-8e1d8fd0934b8e04fd6b1f8f8d4de17cd3b1abe5.tar.gz
rails-8e1d8fd0934b8e04fd6b1f8f8d4de17cd3b1abe5.tar.bz2
rails-8e1d8fd0934b8e04fd6b1f8f8d4de17cd3b1abe5.zip
Track queue threading with named classes
Using an anonymous class prevented marshalling: we're not doing that yet, but the next commit will introduce this. This also provided an opportunity to improve the expressivity of the tests and to make the assertion failure messages clearer.
Diffstat (limited to 'railties')
-rw-r--r--railties/test/application/queue_test.rb38
1 files changed, 24 insertions, 14 deletions
diff --git a/railties/test/application/queue_test.rb b/railties/test/application/queue_test.rb
index da8bdeed52..d5198b07e8 100644
--- a/railties/test/application/queue_test.rb
+++ b/railties/test/application/queue_test.rb
@@ -30,34 +30,44 @@ module ApplicationTests
assert_kind_of Rails::Queueing::Queue, Rails.queue
end
- test "in development mode, an enqueued job will be processed in a separate thread" do
- app("development")
+ class ThreadTrackingJob
+ def initialize
+ @origin = Thread.current.object_id
+ end
- job = Struct.new(:origin, :target).new(Thread.current)
- def job.run
- self.target = Thread.current
+ def run
+ @target = Thread.current.object_id
end
+ def ran_in_different_thread?
+ @origin != @target
+ end
+
+ def ran?
+ @target
+ end
+ end
+
+ test "in development mode, an enqueued job will be processed in a separate thread" do
+ app("development")
+
+ job = ThreadTrackingJob.new
Rails.queue.push job
sleep 0.1
- assert job.target, "The job was run"
- assert_not_equal job.origin, job.target
+ assert job.ran?, "Expected job to be run"
+ assert job.ran_in_different_thread?, "Expected job to run in a different thread"
end
test "in test mode, explicitly draining the queue will process it in a separate thread" do
app("test")
- job = Struct.new(:origin, :target).new(Thread.current)
- def job.run
- self.target = Thread.current
- end
-
+ job = ThreadTrackingJob.new
Rails.queue.push job
Rails.queue.drain
- assert job.target, "The job was run"
- assert_not_equal job.origin, job.target
+ assert job.ran?, "Expected job to be run"
+ assert job.ran_in_different_thread?, "Expected job to run in a different thread"
end
test "in test mode, the queue can be observed" do