jbogard / Respawn

Intelligent database cleaner for integration tests
Apache License 2.0
2.67k stars 134 forks source link

Respawn if there is nothing to clear at the moment doesn't work #124

Open drauch opened 1 year ago

drauch commented 1 year ago

Maybe we don't understand Respawn good enough and there is an easy workaround for this. We basically respawn in each SetUpFixture in our tests. However, sometimes there are no tables to clear and Respawn failed. To overcome this we've used the following workaroud: add an DbAdapter that checks in BuildDeleteCommandText whether the built commandText is empty and in that case throw a specific exception that we can catch and ignore when calling Respawner. Since 6.1.0 this is no longer possible according to one of my team mates.

Is there a real way to do this? If not, how to workaround this problem with v6.1.0?

Best regards, D.R.

jbogard commented 1 year ago

Why are there no tables to clear? That sounds like a bug.

chrischu commented 1 year ago

Well as my colleague explained, we do that in the SetUpFixture of our tests, so we have cases where the database is actually empty (because nothing ran before) and in that case there are no tables to clear. We think that should be a supported scenario, maybe with a flag to avoid people from accidentally not clearing the tables (e.g. bool allowNoTables=false).

jbogard commented 1 year ago

So why not call Respawn after you set up the database? This sounds like something wonky in your test setup.

The reason this was put in was because people were messing up their test setups and not realizing it because Respawn still ran successfully, then wondered why their database still had data even though it ran "successfully".

chrischu commented 1 year ago

I understand the reasoning completely, for 99% of the users the behavior is correct probably. However, would it one of the following two options be acceptable (we would of course be willing to create pull request)?

If you could tell us which option you'd prefer we will submit a pull request implementing it.

Thanks in advance!

jbogard commented 1 year ago

Option 3 is to fix the behavior in your tests, what's wrong with that?