-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting PG Error from specs #23
Comments
Would you try to get me a transcript of the SQL that's executed? This might do it:
Not pretty, but it should work |
Thanks for the quick response! Processing by ApiController#job_code as JSON [upsert] Creating or replacing database function "upsert2_0_1_job_codes_SEL_source_id_A_store_id_SET_cr3198577771" on table "job_codes" for selector "source_id", "store_id" and setter "created_at", "name", "source_id", "store_id", "updated_at"
[upsert] SELECT upsert2_0_1_job_codes_SEL_source_id_A_store_id_SET_cr3198577771($1, $2, $3, $4, $5, $6, $7) with [25, 1, "2013-09-30 17:44:58.912634+00:00", "Server", 25, 1, "2013-09-30 17:44:58.912637+00:00"]
Completed 500 Internal Server Error in 2ms |
we are running into the same thing. let me know if there is something to test. i am trying to dig into it. |
is the maybe try running some throwaway upserts before tests are run - that way the functions will already exist? |
i don't know upserts relationship to active records connection but rspec will normally put transactions around tests and rollback to make tests faster i will try some things next week |
got it to work. normally this would be sufficient. you can do this globally in a describe # config
config.use_transactional_fixtures = false
# in a describe block
self.use_transactional_fixtures = false we are using database cleaner which hijacks those settings. this is how we are solving the problem. before :all do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean_with(:truncation)
end
after :all do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end |
for now just mentioning this in readme f8e09e9 |
This might have been fixed with our earlier thread-safety patch. |
I ran into a similar situation today and found the following quite useful
The culprit was a lock held on one of the tables due to schema creation within a transaction. I worked around that problem with the following structure.
|
Is there another fix for this? |
I have the following method using upsert:
def job_code
@code = JobCode.new(params[:api])
selector = {:store_id => @code.store_id, :source_id => @code.source_id}
setter = { :name => @code.name, :created_at => Time.now, :updated_at => Time.now }
JobCode.upsert(selector, setter)
render_json(@code, :created)
end
And here is the spec that is giving me trouble:
describe 'job_code' do
context 'when it is a new job_code' do
Given(:params) { {:format => 'json', :api=>{ :store_id=> 1, :source_id=>25, :name=>'Server'}} }
Then { lambda{ post :job_code, params }.should change(JobCode, :count) }
end
end
I can run each of these specs individually and everything works well, but when I run them together, I get the following error:
Failure/Error: Then { lambda{ post :job_code, params }.should_not change(JobCode, :count) }
PG::Error:
ERROR: current transaction is aborted, commands ignored until end of transaction block
I can call this method with a script many times back-to back, and it works well. I'm also using upsert elsewhere without an issue. Also, all rows are successfully loaded in the database in all cases except for the test. Not sure if this is an Upsert issue or user error, but any insight is much appreciated!
The text was updated successfully, but these errors were encountered: