Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Always call parent teardown even if an exception is thrown #1129

Conversation

tomb1n0
Copy link
Contributor

@tomb1n0 tomb1n0 commented Apr 8, 2024

What:

  • Bug Fix
  • New Feature

Description:

This PR attempts to fix the issue outlined in #988.

Essentially, the core issue is that if an exception occurs when calling ->__callClosure, parent::tearDown is never called. This can cause issues in Test Suites that rely on performing certain tasks in tearDown. For example the RefreshDatabase trait in Laravel relies on this in order to rollback the current transaction.

The issue i was running into specifically was that my tests after the failing one were appearing to hang. But actually they were just waiting to get a lock on a table, this ended up never resolving and just exceeding my databases lock_wait_timeout. This (usually passing) test would then fail, before moving onto the next one, looping round again. The root cause appeared to be because Laravel couldn't cleanup the database transaction from the failing test as tearDown was never called due to a Mock exception.

I've added a try/finally block around the call to ->callClosure to ensure teardown is always called. We should have a test case for this situation to ensure we don't have a regression in the future, however i was unsure on the approach that should be taken here as i'm not familiar with all the internals at play here.

I've modified Testable.php locally on my project and my issue has gone away. The failing test correctly cleans up after itself (still reporting the fail, of course) before moving onto subsequent tests without having the lock issue.

Related:

Fixes #988.
Fixes #533

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants