Hi All.
I want to test by multi thread.(functional test)
as below

* test
class ItemControllerTest < ActionController::TestCase

self.use_transactional_fixtures = false
POOL_SIZE = 5

def setup
@connection = ActiveRecord::Base.remove_connection

ActiveRecord::Base.establish_connection(@connection.merge({:allow_concurrency
=> true, :pool => POOL_SIZE}))
activate_authlogic
end

test "multi thread test" do
user = accounts(:one)
assert(AdAccountSession.create(user))
item = items(:one)
before_count = item.count
params = {:id => item.id.to_s, :count => 10}
threads = (1..5).map do
Thread.new do
10.times do
put :update, params
end
end
end
threads.each(&:join)
end
assert_equal before_count + 10 * 5, item.reload.count

end

* controller
class ItemsController < ApplicationController
def update
count = params[:count]
id = params[:id]
update_sql = "UPDATE items SET count = count + #{count} WHERE id =
#{id}"
Item.connection.update(update_sql)
redirect_to(@item, :notice => 'Item was successfully updated.')
return
end
end


But raise error
test_samaple(ItemsTransactionControllerTest):
AbstractController::DoubleRenderError: Render and/or redirect were
called multiple times in this action.
Please note that you may only call render OR redirect, and at most
once per action.
Also note that neither redirect nor render terminate execution of the
action,
so if you want to exit an action after redirecting, you need to do
something like "redirect_to(...) and return".

This error isn't raised in case of single thread(threads = (1..1).map
do)
How can I test by multi thread?

appreciate any help.
Thank you
Masaki.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 21, '11 at 1:48p
activeDec 21, '11 at 1:48p
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Tamagohan: 1 post

People

Translate

site design / logo © 2021 Grokbase