From 9a3f6e7f717ecfa2778814f730acac70e698887a Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 9 Apr 2024 20:27:30 +1200 Subject: [PATCH] Add connections test --- tests/unit/Utopia/Pools/ConnectionsTest.php | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/unit/Utopia/Pools/ConnectionsTest.php diff --git a/tests/unit/Utopia/Pools/ConnectionsTest.php b/tests/unit/Utopia/Pools/ConnectionsTest.php new file mode 100644 index 0000000000..fb9c8bcc09 --- /dev/null +++ b/tests/unit/Utopia/Pools/ConnectionsTest.php @@ -0,0 +1,40 @@ +add($connection); + $this->assertEquals(1, $connections->count()); + } + + public function testRemove() + { + $connections = new Connections(); + $connection = new Connection('resource'); + $connections->add($connection); + $connections->remove($connection->getID()); + $this->assertEquals(0, $connections->count()); + } + + public function testReclaim() + { + $connections = new Connections(); + $pool = new Pool('test', 1, function () { + return 'resource'; + }); + $connection = $pool->pop(); + $connections->add($connection); + $connections->reclaim(); + $this->assertEquals(1, $pool->count()); + } +}