mezuro / kalibro_processor

Reimplementation of Kalibro processing
GNU Affero General Public License v3.0
2 stars 10 forks source link

Unit test touching the database #212

Open rafamanzo opened 8 years ago

rafamanzo commented 8 years ago

While developing https://github.com/mezuro/kalibro_processor/pull/211 I ran into an special seed for our unit tests. By running ruby performance/tests/aggregation.rb && rspec --seed 20271 from that branch:

KalibroModuleLongNameValidator methods validate within a different processing and with the same granularity and the same long name is expected to NOT add any errors
     Failure/Error: same_name.save
     ActiveRecord::RecordNotUnique:
       PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "processings_pkey"
       DETAIL:  Key (id)=(1) already exists.
       : INSERT INTO "processings" ("created_at", "updated_at", "state", "root_module_result_id", "id") VALUES ($1, $2, $3, $4, $5) RETURNING "id"

Running just rspec --seed 20271 does not produce the error. On the other hand, the first script runs DatabaseCleaner before and after running, so the database should be left clean after the first script.

So we need to investigate deeper wether the first script is leaving the database dirty or is leaving the ids sequence in some special state that produces the test error or even if the unit test itself is touching the database unnecessarily.

danielkza commented 8 years ago

This was a case of hardcoded IDs I believe. I think I have it fixed on my DB fixes branch - I'll make a PR for it soon.