I'm having an odd issue with my test suite that I'm struggling to narrow down. Using the DatabaseTransactions trait and a MySQL database connection.
The vast majority of the tests pass however the exact same 15 or so are failing due to the below:
Doctrine\DBAL\Driver\PDOException: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction
or
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction (SQL: insert into `friendships` (`created_at`, `friend_id`, `updated_at`, `user_id`) values (2019-07-10 10:36:12, 1131, 2019-07-10 10:36:12, 1130))
However if I run the tests individually they pass all green. The error only occurs when running my full suite with ./vendor/bin/phpunit.
They are very simple tests for example for checking if two Users are friends.
public function test_is_friends_with_helper(): void
{
$user = factory(User::class)->state(User::CUSTOMER)->create([
'client_id' => $this->client->id,
]);
$result = $this->customer->fresh()->isFriendsWith($user);
$this->assertFalse($result);
$this->customer->friends()->attach($user);
$result = $this->customer->fresh()->isFriendsWith($user);
$this->assertTrue($result);
}
Falling back to using DatabaseMigrations trait "fixes" the issue but then obviously the whole suite will run way slower.
Does anyone have any ideas?
EDIT: Fixed.
parent::tearDown();