postgresql - Race Condition with Authlogic and Rails 4.1.1 -
i upgrading app rails 4.1.1 , authlogic 3.4.2 , encountered problem race condition in integration test.
i have page issues 2 ajax requests upon loading. both requests cause authlogic try update logged in user record's last_request_at column. not same exception, raised when app tries update same user record back.
this not issue on rails 3 because used rack::lock in test environment.
here snippet of logs:
user load (0.6ms) select "users".* "users" "users"."id" = 2 limit 1 [50/1923] user load (0.8ms) select "users".* "users" "users"."id" = 2 limit 1 (1.5ms) begin (0.2ms) begin sql (0.3ms) update "users" set "last_request_at" = $1, "perishable_token" = $2, "updated_at" = $3 "users"."type" in ('medicalprofessional') , "user s"."id" = 2 [["last_request_at", "2014-05-18 00:19:46.564174"], ["perishable_token", "awlh6mbghl2mdu2uboi"], ["updated_at", "2014-05-18 00:19:46.566315"]] pg::error: command in progress : update "users" set "last_request_at" = $1, "perishable_token" = $2, "updated_at" = $3 "users"."type" in ('medicalprofessional') , "users"."id" = 2 sql (1.7ms) update "users" set "last_request_at" = $1, "perishable_token" = $2, "updated_at" = $3 "users"."type" in ('medicalprofessional') , "user s"."id" = 2 [["last_request_at", "2014-05-18 00:19:46.562637"], ["perishable_token", "soxbkucms0zu3vtxkgqn"], ["updated_at", "2014-05-18 00:19:46.564956"]] (0.2ms) rollback completed 500 internal server error in 132ms (0.5ms) commit activerecord::statementinvalid (pg::error: command in progress : update "users" set "last_request_at" = $1, "perishable_token" = $2, "updated_at" = $3 "users"."type" in ('medicalprofessional') , "users"."id" = 2): app/helpers/auth_helper.rb:3:in `current_user_session' app/helpers/auth_helper.rb:7:in `current_user'
how should/can resolve issue?
turns out else on team had monkey patched activerecord threads use same db connection in order speed tests. got idea this: http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/
i able work around issue setting activerecord::base.shared_connection = nil @ start of failing tests.
Comments
Post a Comment