Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions tests/Pools/Adapter/SwooleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ public function testSwooleCoroutineRaceCondition(): void

// Assertions inside coroutine context
$this->assertEmpty($errors, 'Errors occurred: ' . implode(', ', $errors));
$this->assertEquals(10, $successCount, 'All 10 coroutines should successfully complete');
$this->assertSame(10, $successCount, 'All 10 coroutines should successfully complete');

// Pool should be full again after all connections are reclaimed
$this->assertEquals(5, $pool->count(), 'Pool should have all 5 connections back');
$this->assertSame(5, $pool->count(), 'Pool should have all 5 connections back');

// Should only create exactly pool size connections (no race conditions with new implementation)
$this->assertEquals(5, $connectionCounter, 'Should create exactly 5 connections (pool size)');
$this->assertSame(5, $connectionCounter, 'Should create exactly 5 connections (pool size)');
});
}

Expand Down Expand Up @@ -163,14 +163,14 @@ public function testSwooleCoroutineHighConcurrency(): void
}

// All requests should succeed with proper retry logic
$this->assertEquals($totalRequests, $successCount, "All {$totalRequests} requests should succeed");
$this->assertEquals(0, $errorCount, 'No errors should occur with proper concurrency handling');
$this->assertSame($totalRequests, $successCount, "All {$totalRequests} requests should succeed");
$this->assertSame(0, $errorCount, 'No errors should occur with proper concurrency handling');

// Pool should be full again
$this->assertEquals(3, $pool->count(), 'Pool should have all 3 connections back');
$this->assertSame(3, $pool->count(), 'Pool should have all 3 connections back');

// Should only create 3 connections (pool size)
$this->assertEquals(3, $connectionCounter, 'Should only create 3 connections (pool size)');
$this->assertSame(3, $connectionCounter, 'Should only create 3 connections (pool size)');
});
}

Expand Down Expand Up @@ -286,14 +286,14 @@ public function testSwooleCoroutineIdleConnectionReuse(): void
}

// Assertions inside coroutine context
$this->assertEquals(3, $connectionCounter, 'Should only create 3 connections total');
$this->assertSame(3, $connectionCounter, 'Should only create 3 connections total');
$this->assertCount(3, $connectionIds['first'], 'First wave should have 3 connections');
$this->assertCount(3, $connectionIds['second'], 'Second wave should have 3 connections');

// Second wave should reuse connections from first wave
sort($connectionIds['first']);
sort($connectionIds['second']);
$this->assertEquals($connectionIds['first'], $connectionIds['second'], 'Second wave should reuse same connection IDs');
$this->assertSame($connectionIds['first'], $connectionIds['second'], 'Second wave should reuse same connection IDs');
});
}

Expand Down Expand Up @@ -347,10 +347,10 @@ public function testSwooleCoroutineStressTest(): void
}

// Assertions inside coroutine context
$this->assertEquals($totalRequests, $successCount, "All {$totalRequests} requests should succeed");
$this->assertEquals(0, $errorCount, 'No errors should occur');
$this->assertEquals(10, $connectionCounter, 'Should create exactly 10 connections (pool size)');
$this->assertEquals(10, $pool->count(), 'Pool should have all connections back');
$this->assertSame($totalRequests, $successCount, "All {$totalRequests} requests should succeed");
$this->assertSame(0, $errorCount, 'No errors should occur');
$this->assertSame(10, $connectionCounter, 'Should create exactly 10 connections (pool size)');
$this->assertSame(10, $pool->count(), 'Pool should have all connections back');
});
}
}
42 changes: 21 additions & 21 deletions tests/Pools/Scopes/ConnectionTestScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,43 @@ public function testConnectionGetID(): void
{
$this->execute(function (): void {
$this->setUpConnection();
$this->assertEquals(null, $this->connectionObject->getID());
$this->assertSame('', $this->connectionObject->getID());

$this->connectionObject->setID('test');

$this->assertEquals('test', $this->connectionObject->getID());
$this->assertSame('test', $this->connectionObject->getID());
});
}

public function testConnectionSetID(): void
{
$this->execute(function (): void {
$this->setUpConnection();
$this->assertEquals(null, $this->connectionObject->getID());
$this->assertSame('', $this->connectionObject->getID());

$this->assertInstanceOf(Connection::class, $this->connectionObject->setID('test'));

$this->assertEquals('test', $this->connectionObject->getID());
$this->assertSame('test', $this->connectionObject->getID());
});
}

public function testConnectionGetResource(): void
{
$this->execute(function (): void {
$this->setUpConnection();
$this->assertEquals('x', $this->connectionObject->getResource());
$this->assertSame('x', $this->connectionObject->getResource());
});
}

public function testConnectionSetResource(): void
{
$this->execute(function (): void {
$this->setUpConnection();
$this->assertEquals('x', $this->connectionObject->getResource());
$this->assertSame('x', $this->connectionObject->getResource());

$this->assertInstanceOf(Connection::class, $this->connectionObject->setResource('y'));

$this->assertEquals('y', $this->connectionObject->getResource());
$this->assertSame('y', $this->connectionObject->getResource());
});
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public function testConnectionGetPool(): void
}

$this->assertInstanceOf(Pool::class, $pool);
$this->assertEquals('test', $pool->getName());
$this->assertSame('test', $pool->getName());
});
}

Expand All @@ -101,23 +101,23 @@ public function testConnectionReclaim(): void
$this->execute(function (): void {
$pool = new Pool($this->getAdapter(), 'test', 2, fn () => 'x');

$this->assertEquals(2, $pool->count());
$this->assertSame(2, $pool->count());

$connection1 = $pool->pop();

$this->assertEquals(1, $pool->count());
$this->assertSame(1, $pool->count());

$connection2 = $pool->pop();

$this->assertEquals(0, $pool->count());
$this->assertSame(0, $pool->count());

$this->assertInstanceOf(Pool::class, $connection1->reclaim());

$this->assertEquals(1, $pool->count());
$this->assertSame(1, $pool->count());

$this->assertInstanceOf(Pool::class, $connection2->reclaim());

$this->assertEquals(2, $pool->count());
$this->assertSame(2, $pool->count());
});
}

Expand All @@ -139,28 +139,28 @@ public function testConnectionDestroy(): void
return $i <= 2 ? 'x' : 'y';
});

$this->assertEquals(2, $object->count());
$this->assertSame(2, $object->count());

$connection1 = $object->pop();
$connection2 = $object->pop();

$this->assertEquals(0, $object->count());
$this->assertSame(0, $object->count());

$this->assertEquals('x', $connection1->getResource());
$this->assertEquals('x', $connection2->getResource());
$this->assertSame('x', $connection1->getResource());
$this->assertSame('x', $connection2->getResource());

$connection1->destroy();
$connection2->destroy();

$this->assertEquals(2, $object->count());
$this->assertSame(2, $object->count());

$connection1 = $object->pop();
$connection2 = $object->pop();

$this->assertEquals(0, $object->count());
$this->assertSame(0, $object->count());

$this->assertEquals('y', $connection1->getResource());
$this->assertEquals('y', $connection2->getResource());
$this->assertSame('y', $connection1->getResource());
$this->assertSame('y', $connection2->getResource());
});
}
}
36 changes: 18 additions & 18 deletions tests/Pools/Scopes/GroupTestScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ public function testGroupReset(): void
$this->setUpGroup();
$this->groupObject->add(new Pool($this->getAdapter(), 'test', 5, fn () => 'x'));

$this->assertEquals(5, $this->groupObject->get('test')->count());
$this->assertSame(5, $this->groupObject->get('test')->count());

$this->groupObject->get('test')->pop();
$this->groupObject->get('test')->pop();
$this->groupObject->get('test')->pop();

$this->assertEquals(2, $this->groupObject->get('test')->count());
$this->assertSame(2, $this->groupObject->get('test')->count());

$this->groupObject->reclaim();

$this->assertEquals(5, $this->groupObject->get('test')->count());
$this->assertSame(5, $this->groupObject->get('test')->count());
});
}

Expand All @@ -84,11 +84,11 @@ public function testGroupReconnectAttempts(): void
$this->setUpGroup();
$this->groupObject->add(new Pool($this->getAdapter(), 'test', 5, fn () => 'x'));

$this->assertEquals(3, $this->groupObject->get('test')->getReconnectAttempts());
$this->assertSame(3, $this->groupObject->get('test')->getReconnectAttempts());

$this->groupObject->setReconnectAttempts(5);

$this->assertEquals(5, $this->groupObject->get('test')->getReconnectAttempts());
$this->assertSame(5, $this->groupObject->get('test')->getReconnectAttempts());
});
}

Expand All @@ -98,11 +98,11 @@ public function testGroupReconnectSleep(): void
$this->setUpGroup();
$this->groupObject->add(new Pool($this->getAdapter(), 'test', 5, fn () => 'x'));

$this->assertEquals(1, $this->groupObject->get('test')->getReconnectSleep());
$this->assertSame(1, $this->groupObject->get('test')->getReconnectSleep());

$this->groupObject->setReconnectSleep(2);

$this->assertEquals(2, $this->groupObject->get('test')->getReconnectSleep());
$this->assertSame(2, $this->groupObject->get('test')->getReconnectSleep());
});
}

Expand All @@ -118,23 +118,23 @@ public function testGroupUse(): void
$this->groupObject->add($pool2);
$this->groupObject->add($pool3);

$this->assertEquals(1, $pool1->count());
$this->assertEquals(1, $pool2->count());
$this->assertEquals(1, $pool3->count());
$this->assertSame(1, $pool1->count());
$this->assertSame(1, $pool2->count());
$this->assertSame(1, $pool3->count());

// @phpstan-ignore argument.type
$this->groupObject->use(['pool1', 'pool3'], function ($one, $three) use ($pool1, $pool2, $pool3): void {
$this->assertEquals('1', $one);
$this->assertEquals('3', $three);
$this->assertSame('1', $one);
$this->assertSame('3', $three);

$this->assertEquals(0, $pool1->count());
$this->assertEquals(1, $pool2->count());
$this->assertEquals(0, $pool3->count());
$this->assertSame(0, $pool1->count());
$this->assertSame(1, $pool2->count());
$this->assertSame(0, $pool3->count());
});

$this->assertEquals(1, $pool1->count());
$this->assertEquals(1, $pool2->count());
$this->assertEquals(1, $pool3->count());
$this->assertSame(1, $pool1->count());
$this->assertSame(1, $pool2->count());
$this->assertSame(1, $pool3->count());
});
}
}
Loading