Skip to content

Commit

Permalink
Move the TestQueue tests to the proper file
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Oct 12, 2012
1 parent d08b89f commit 08f57bf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 47 deletions.
44 changes: 44 additions & 0 deletions activesupport/test/queueing/test_queue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,48 @@ def test_drain
assert job.ran?, "The job runs synchronously when the queue is drained"
assert_equal job.thread_id, Thread.current.object_id
end

class IdentifiableJob
def initialize(id)
@id = id
end

def ==(other)
other.same_id?(@id)
end

def same_id?(other_id)
other_id == @id
end

def run
end
end

def test_queue_can_be_observed
jobs = (1..10).map do |id|
IdentifiableJob.new(id)
end

jobs.each do |job|
@queue.push job
end

assert_equal jobs, @queue.jobs
end

def test_adding_an_unmarshallable_job
anonymous_class_instance = Struct.new(:run).new

assert_raises TypeError do
@queue.push anonymous_class_instance
end
end

def test_attempting_to_add_a_reference_to_itself
job = {reference: @queue}
assert_raises TypeError do
@queue.push job
end
end
end
47 changes: 0 additions & 47 deletions railties/test/application/queue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,60 +69,13 @@ def ran?
refute job.ran_in_different_thread?, "Expected job to run in the same thread"
end

class IdentifiableJob
def initialize(id)
@id = id
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|
IdentifiableJob.new(id)
end

jobs.each do |job|
Rails.queue.push job
end

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

test "attempting to marshal a queue will raise an exception" do
app("test")
assert_raises TypeError do
Marshal.dump Rails.queue
end
end

test "attempting to add a reference to itself to the queue will raise an exception" do
app("test")
job = {reference: Rails.queue}
assert_raises TypeError do
Rails.queue.push job
end
end

def setup_custom_queue
add_to_env_config "production", <<-RUBY
require "my_queue"
Expand Down

0 comments on commit 08f57bf

Please sign in to comment.