Skip to content
Senior300 views

If tests ran, data was created, but in the middle of the test the machine crashed — did the data remain in the database? How was it resolved?

Practice

Asked at

AI answer

It depends on whether the changes were committed. If the test ran in a transaction that was not committed, closing the connection usually causes a rollback; in the event of a network failure, the rollback may not happen immediately—it depends on timeouts and the state of the connection. If data was saved in separate commits or in autocommit mode, it may remain in the database. Therefore, tests should have reliable cleanup: rolling back the transaction or deleting test data in teardown, isolating data by run ID, and, if necessary, cleaning it up based on TTL. For flaky tests, it is convenient to use a separate schema or an ephemeral database. In practice, verify the result in the database rather than relying only on the test process having ended.