database_cleaner-sequel
database_cleaner-sequel copied to clipboard
transaction policy don't work with fiber_concurrency plugins.
trafficstars
Following is a very simple example for describe this issue.
require 'test_helper'
describe 'test /stocks' do
it 'test /stocks return a stock lists' do
exchange = Exchange.create(name: 'nyse')
create(:stock, name: 'ge', exchange: exchange, percent_of_institutions: 0.5525, id: 1)
create(:stock, name: 'lu', exchange: exchange, percent_of_institutions: 0.2233, id: 2)
get "/stocks"
last_response.body.must_equal File.read('test/stocks.html')
end
end
will return following error message:
╰─ $ 1 rake test TEST=test/stocks_test.rb
RACK_ENV=test
DB connected: postgres://postgres:postgres@localhost:5432/marketbet_crawler_test
Eager loading ...
Run options: --seed 7382
# Running:
E
Fabulous run in 0.006004s, 166.5512 runs/s, 0.0000 assertions/s.
1) Error:
test /stocks#test_0001_test /stocks return a stock lists:
Sequel::UniqueConstraintViolation: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "exchanges_name_key"
DETAIL: Key (name)=(nyse) already exists.
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:113:in `check'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:113:in `yield_each_row'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:113:in `block in fetch_rows'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/adapters/postgres.rb:146:in `execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/adapters/postgres.rb:500:in `_execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:47:in `_execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/adapters/postgres.rb:318:in `block (2 levels) in execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/adapters/postgres.rb:522:in `check_database_errors'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/adapters/postgres.rb:318:in `block in execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/connection_pool/threaded.rb:88:in `hold'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/database/connecting.rb:269:in `synchronize'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/adapters/postgres.rb:318:in `execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/dataset/actions.rb:1093:in `execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:112:in `fetch_rows'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/dataset/actions.rb:946:in `with_sql_each'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/dataset/actions.rb:954:in `with_sql_first'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/adapters/shared/postgres.rb:1721:in `insert_select'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:1739:in `_insert_select_raw'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:1712:in `_insert'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:1784:in `block (2 levels) in _save'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:1038:in `around_create'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:1781:in `block in _save'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:1038:in `around_save'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:1776:in `_save'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:1488:in `block (2 levels) in save'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:1942:in `block in checked_transaction'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/database/transactions.rb:258:in `_transaction'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/database/transactions.rb:233:in `block in transaction'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/connection_pool/threaded.rb:92:in `hold'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/database/connecting.rb:269:in `synchronize'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/database/transactions.rb:195:in `transaction'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:1942:in `checked_transaction'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:1488:in `block in save'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:1930:in `checked_save_failure'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:1488:in `save'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.49.0/lib/sequel/model/base.rb:254:in `create'
/home/zw963/Stocks/marketbet_crawler/test/stocks_test.rb:5:in `block (2 levels) in <top (required)>'
Only if change policy to truncation, all test passed now.