DEFRA / ruby-services-team

Guides, info and issue management for the Ruby Services team
Other
1 stars 3 forks source link

WEX engine - Database is left dirty sometimes #54

Closed cintamani closed 1 year ago

cintamani commented 5 years ago

We have discovered that there is some test not cleaning up after itself on the engine test suite. We had an expectation of 0 records in the registration recently and we had to take it out because it was randomly failing for a dirty record not cleaned up in the table in certain occasions. I suggest we find the offending test adding an around hook to the test suite and checking after the run of every test that the database is clean, and fixing the test that don't pass that expectation.

https://travis-ci.com/DEFRA/waste-exemptions-engine/builds/120830154

Randomized with seed 63550

...... 

Failures:
  1) WasteExemptionsEngine::RegistrationCompletionService#complete is idempotent
     Failure/Error: expect(WasteExemptionsEngine::Registration.count).to eq(0)

       expected: 0
            got: 1

       (compared using ==)
     # ./spec/services/waste_exemptions_engine/registration_completion_service_spec.rb:14:in `block (3 levels) in <module:WasteExemptionsEngine>'
     # ./spec/support/database_cleaner.rb:16:in `block (3 levels) in <top (required)>'
     # ./spec/support/database_cleaner.rb:15:in `block (2 levels) in <top (required)>'
  2) WasteExemptionsEngine::RegistrationCompletionService#complete when a race condition calls the service twice generates only one record and fail to execute subsequent calls
     Failure/Error: expect(WasteExemptionsEngine::Registration.count).to eq(0)

       expected: 0
            got: 1

       (compared using ==)
     # ./spec/services/waste_exemptions_engine/registration_completion_service_spec.rb:25:in `block (4 levels) in <module:WasteExemptionsEngine>'
     # ./spec/support/database_cleaner.rb:16:in `block (3 levels) in <top (required)>'
     # ./spec/support/database_cleaner.rb:15:in `block (2 levels) in <top (required)>'
Finished in 1 minute 41.58 seconds (files took 4.46 seconds to load)
1638 examples, 2 failures