aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application
diff options
context:
space:
mode:
authorPaul Battley <pbattley@gmail.com>2012-07-03 11:55:46 +0100
committerPaul Battley <pbattley@gmail.com>2012-07-03 12:01:53 +0100
commit33113ba0e73004d6508fc473a6d02f91cbb35709 (patch)
tree0a66a356cb61ccd3c718a46d090c6572d9d1bbf1 /railties/test/application
parent8e1d8fd0934b8e04fd6b1f8f8d4de17cd3b1abe5 (diff)
downloadrails-33113ba0e73004d6508fc473a6d02f91cbb35709.tar.gz
rails-33113ba0e73004d6508fc473a6d02f91cbb35709.tar.bz2
rails-33113ba0e73004d6508fc473a6d02f91cbb35709.zip
Ensure test jobs are marshallable
By marshalling and unmarshalling jobs when adding them to the test queue, we can ensure that jobs created during test runs are valid candidates for marshalling, and, thus, that they can be used with queueing backends other than the default simple in-process implementation. This will also be used in a subsequent commit to ensure that jobs pushed to the queue do not contain a reference to the queue itself.
Diffstat (limited to 'railties/test/application')
-rw-r--r--railties/test/application/queue_test.rb36
1 files changed, 28 insertions, 8 deletions
diff --git a/railties/test/application/queue_test.rb b/railties/test/application/queue_test.rb
index d5198b07e8..e8ee8c5c9f 100644
--- a/railties/test/application/queue_test.rb
+++ b/railties/test/application/queue_test.rb
@@ -62,24 +62,36 @@ module ApplicationTests
test "in test mode, explicitly draining the queue will process it in a separate thread" do
app("test")
- job = ThreadTrackingJob.new
- Rails.queue.push job
+ Rails.queue.push ThreadTrackingJob.new
+ job = Rails.queue.jobs.last
Rails.queue.drain
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
- app("test")
+ class IdentifiableJob
+ def initialize(id)
+ @id = id
+ end
- job = Struct.new(:id) do
- def run
- end
+ def ==(other)
+ other.same_id?(@id)
+ end
+
+ def same_id?(other_id)
+ other_id == @id
+ end
+
+ def run
end
+ end
+
+ test "in test mode, the queue can be observed" do
+ app("test")
jobs = (1..10).map do |id|
- job.new(id)
+ IdentifiableJob.new(id)
end
jobs.each do |job|
@@ -89,6 +101,14 @@ module ApplicationTests
assert_equal jobs, Rails.queue.jobs
end
+ test "in test mode, adding an unmarshallable job will raise an exception" do
+ app("test")
+ anonymous_class_instance = Struct.new(:run).new
+ assert_raises TypeError do
+ Rails.queue.push anonymous_class_instance
+ end
+ end
+
def setup_custom_queue
add_to_env_config "production", <<-RUBY
require "my_queue"