Skip to content

Commit

Permalink
fix burn testing /wo leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Dec 5, 2024
1 parent 0c3cbab commit 7151f9f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 39 deletions.
16 changes: 6 additions & 10 deletions tests/mutex/CASMutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use malkusch\lock\exception\LockAcquireException;
use malkusch\lock\mutex\CASMutex;
use phpmock\environment\SleepEnvironmentBuilder;
use phpmock\MockEnabledException;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\TestCase;

Expand All @@ -20,17 +19,14 @@ protected function setUp(): void
{
parent::setUp();

$sleepBuilder = new SleepEnvironmentBuilder();
$sleepBuilder->addNamespace(__NAMESPACE__);
$sleepBuilder->addNamespace('malkusch\lock\mutex');
$sleepBuilder->addNamespace('malkusch\lock\util');
$sleep = $sleepBuilder->build();
try {
if (!function_exists(__NAMESPACE__ . '\microtime')) { // workaround for burn testing
$sleepBuilder = new SleepEnvironmentBuilder();
$sleepBuilder->addNamespace(__NAMESPACE__);
$sleepBuilder->addNamespace('malkusch\lock\mutex');
$sleepBuilder->addNamespace('malkusch\lock\util');
$sleep = $sleepBuilder->build();
$sleep->enable();
$this->registerForTearDown($sleep);
} catch (MockEnabledException $e) {
// workaround for burn testing
self::assertSame('microtime is already enabled.Call disable() on the existing mock.', $e->getMessage());
}
}

Expand Down
16 changes: 6 additions & 10 deletions tests/mutex/RedisMutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use malkusch\lock\exception\TimeoutException;
use malkusch\lock\mutex\RedisMutex;
use phpmock\environment\SleepEnvironmentBuilder;
use phpmock\MockEnabledException;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
Expand All @@ -30,17 +29,14 @@ protected function setUp(): void
{
parent::setUp();

$sleepBuilder = new SleepEnvironmentBuilder();
$sleepBuilder->addNamespace(__NAMESPACE__);
$sleepBuilder->addNamespace('malkusch\lock\mutex');
$sleepBuilder->addNamespace('malkusch\lock\util');
$sleep = $sleepBuilder->build();
try {
if (!function_exists(__NAMESPACE__ . '\microtime')) { // workaround for burn testing
$sleepBuilder = new SleepEnvironmentBuilder();
$sleepBuilder->addNamespace(__NAMESPACE__);
$sleepBuilder->addNamespace('malkusch\lock\mutex');
$sleepBuilder->addNamespace('malkusch\lock\util');
$sleep = $sleepBuilder->build();
$sleep->enable();
$this->registerForTearDown($sleep);
} catch (MockEnabledException $e) {
// workaround for burn testing
self::assertSame('microtime is already enabled.Call disable() on the existing mock.', $e->getMessage());
}
}

Expand Down
16 changes: 6 additions & 10 deletions tests/mutex/SpinlockMutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use malkusch\lock\exception\TimeoutException;
use malkusch\lock\mutex\SpinlockMutex;
use phpmock\environment\SleepEnvironmentBuilder;
use phpmock\MockEnabledException;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand All @@ -24,17 +23,14 @@ protected function setUp(): void
{
parent::setUp();

$sleepBuilder = new SleepEnvironmentBuilder();
$sleepBuilder->addNamespace(__NAMESPACE__);
$sleepBuilder->addNamespace('malkusch\lock\mutex');
$sleepBuilder->addNamespace('malkusch\lock\util');
$sleep = $sleepBuilder->build();
try {
if (!function_exists(__NAMESPACE__ . '\microtime')) { // workaround for burn testing
$sleepBuilder = new SleepEnvironmentBuilder();
$sleepBuilder->addNamespace(__NAMESPACE__);
$sleepBuilder->addNamespace('malkusch\lock\mutex');
$sleepBuilder->addNamespace('malkusch\lock\util');
$sleep = $sleepBuilder->build();
$sleep->enable();
$this->registerForTearDown($sleep);
} catch (MockEnabledException $e) {
// workaround for burn testing
self::assertSame('microtime is already enabled.Call disable() on the existing mock.', $e->getMessage());
}
}

Expand Down
14 changes: 5 additions & 9 deletions tests/util/LoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use malkusch\lock\exception\TimeoutException;
use malkusch\lock\util\Loop;
use phpmock\environment\SleepEnvironmentBuilder;
use phpmock\MockEnabledException;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\TestCase;

Expand All @@ -20,16 +19,13 @@ protected function setUp(): void
{
parent::setUp();

$sleepBuilder = new SleepEnvironmentBuilder();
$sleepBuilder->addNamespace(__NAMESPACE__);
$sleepBuilder->addNamespace('malkusch\lock\util');
$sleep = $sleepBuilder->build();
try {
if (!function_exists(__NAMESPACE__ . '\microtime')) { // workaround for burn testing
$sleepBuilder = new SleepEnvironmentBuilder();
$sleepBuilder->addNamespace(__NAMESPACE__);
$sleepBuilder->addNamespace('malkusch\lock\util');
$sleep = $sleepBuilder->build();
$sleep->enable();
$this->registerForTearDown($sleep);
} catch (MockEnabledException $e) {
// workaround for burn testing
self::assertSame('microtime is already enabled.Call disable() on the existing mock.', $e->getMessage());
}
}

Expand Down

0 comments on commit 7151f9f

Please sign in to comment.