Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Respawn is not resetting my SQL Server database

I'm using Respawn to clean up my test database, but when this method executes:

public static Task ResetCheckpoint() => Checkpoint.Reset(ConfigurationManager.ConnectionStrings["TestConnection"].ConnectionString);

This error message is shown:

Message: System.InvalidOperationException : Invalid operation. The connection is closed.

I have already checked the value returned by ConfigurationManager.ConnectionStrings["TestConnection"].ConnectionString and it is correct.

I based my integration test structure in this sample project by Jimmy Bogard: https://github.com/jbogard/ContosoUniversityDotNetCore-Pages, more specifically, these two classes:

  • https://github.com/jbogard/ContosoUniversityDotNetCore-Pages/blob/master/ContosoUniversity.IntegrationTests/IntegrationTestBase.cs
  • https://github.com/jbogard/ContosoUniversityDotNetCore-Pages/blob/master/ContosoUniversity.IntegrationTests/SliceFixture.cs
like image 364
Marcell Alves Avatar asked Feb 28 '26 04:02

Marcell Alves


1 Answers

I have figured this out. The issue was the connection timeout. I'm using a clone from the production database as a test database and there are many tables with a lot of rows, some with millions of registers. So I ran the commands generates by Respawn by hand, in SQL Server Management Studio, and it took 17 minutes to clear it all. For now on, I'm going to be able to write and run my tests with a clean database, without issues.

So, the lesson learned here is:

  • Clear a big database before running Respawn Reset, or set the CommandTimeout property of Checkout class to a higher value.

I think Respawn could return a better message of what has gone wrong in the Reset, maybe I'll send a pull request to address this issue.

like image 160
Marcell Alves Avatar answered Mar 01 '26 17:03

Marcell Alves