diff options
author | Joas Schilling <coding@schilljs.com> | 2020-11-05 12:50:53 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-11-09 14:28:17 +0300 |
commit | 8027dcbc6f6b1653f5ebcf04b1862ac1e1f51d32 (patch) | |
tree | 1bf182f477bfbead7b75ae14a8cd0fce5bb38ada /apps/federation | |
parent | 72545ffd07a07f142c9c18b3e4afc9ae1b5c8da2 (diff) |
Don't leave cursors open when tests fail
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/federation')
-rw-r--r-- | apps/federation/lib/DbHandler.php | 6 | ||||
-rw-r--r-- | apps/federation/tests/DbHandlerTest.php | 50 |
2 files changed, 44 insertions, 12 deletions
diff --git a/apps/federation/lib/DbHandler.php b/apps/federation/lib/DbHandler.php index c30bbf51ad8..5499b4547b6 100644 --- a/apps/federation/lib/DbHandler.php +++ b/apps/federation/lib/DbHandler.php @@ -120,8 +120,10 @@ class DbHandler { $query->select('*')->from($this->dbTable) ->where($query->expr()->eq('id', $query->createParameter('id'))) ->setParameter('id', $id); - $query->execute(); - $result = $query->execute()->fetchAll(); + + $qResult = $query->execute(); + $result = $qResult->fetchAll(); + $qResult->closeCursor(); if (empty($result)) { throw new \Exception('No Server found with ID: ' . $id); diff --git a/apps/federation/tests/DbHandlerTest.php b/apps/federation/tests/DbHandlerTest.php index 7a06b2c9daa..ee972458747 100644 --- a/apps/federation/tests/DbHandlerTest.php +++ b/apps/federation/tests/DbHandlerTest.php @@ -62,7 +62,10 @@ class DbHandlerTest extends TestCase { ); $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); - $result = $query->execute()->fetchAll(); + + $qResult = $query->execute(); + $result = $qResult->fetchAll(); + $qResult->closeCursor(); $this->assertEmpty($result, 'we need to start with a empty trusted_servers table'); } @@ -83,7 +86,10 @@ class DbHandlerTest extends TestCase { $id = $this->dbHandler->addServer($url); $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); - $result = $query->execute()->fetchAll(); + + $qResult = $query->execute(); + $result = $qResult->fetchAll(); + $qResult->closeCursor(); $this->assertSame(1, count($result)); $this->assertSame($expectedUrl, $result[0]['url']); $this->assertSame($id, (int)$result[0]['id']); @@ -104,7 +110,10 @@ class DbHandlerTest extends TestCase { $id2 = $this->dbHandler->addServer('server2'); $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); - $result = $query->execute()->fetchAll(); + + $qResult = $query->execute(); + $result = $qResult->fetchAll(); + $qResult->closeCursor(); $this->assertSame(2, count($result)); $this->assertSame('server1', $result[0]['url']); $this->assertSame('server2', $result[1]['url']); @@ -113,7 +122,10 @@ class DbHandlerTest extends TestCase { $this->dbHandler->removeServer($id2); $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); - $result = $query->execute()->fetchAll(); + + $qResult = $query->execute(); + $result = $qResult->fetchAll(); + $qResult->closeCursor(); $this->assertSame(1, count($result)); $this->assertSame('server1', $result[0]['url']); $this->assertSame($id1, (int)$result[0]['id']); @@ -165,12 +177,18 @@ class DbHandlerTest extends TestCase { public function XtestAddToken() { $this->dbHandler->addServer('server1'); $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); - $result = $query->execute()->fetchAll(); + + $qResult = $query->execute(); + $result = $qResult->fetchAll(); + $qResult->closeCursor(); $this->assertSame(1, count($result)); $this->assertSame(null, $result[0]['token']); $this->dbHandler->addToken('http://server1', 'token'); $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); - $result = $query->execute()->fetchAll(); + + $qResult = $query->execute(); + $result = $qResult->fetchAll(); + $qResult->closeCursor(); $this->assertSame(1, count($result)); $this->assertSame('token', $result[0]['token']); } @@ -186,12 +204,18 @@ class DbHandlerTest extends TestCase { public function XtestAddSharedSecret() { $this->dbHandler->addServer('server1'); $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); - $result = $query->execute()->fetchAll(); + + $qResult = $query->execute(); + $result = $qResult->fetchAll(); + $qResult->closeCursor(); $this->assertSame(1, count($result)); $this->assertSame(null, $result[0]['shared_secret']); $this->dbHandler->addSharedSecret('http://server1', 'secret'); $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); - $result = $query->execute()->fetchAll(); + + $qResult = $query->execute(); + $result = $qResult->fetchAll(); + $qResult->closeCursor(); $this->assertSame(1, count($result)); $this->assertSame('secret', $result[0]['shared_secret']); } @@ -207,12 +231,18 @@ class DbHandlerTest extends TestCase { public function testSetServerStatus() { $this->dbHandler->addServer('server1'); $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); - $result = $query->execute()->fetchAll(); + + $qResult = $query->execute(); + $result = $qResult->fetchAll(); + $qResult->closeCursor(); $this->assertSame(1, count($result)); $this->assertSame(TrustedServers::STATUS_PENDING, (int)$result[0]['status']); $this->dbHandler->setServerStatus('http://server1', TrustedServers::STATUS_OK); $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); - $result = $query->execute()->fetchAll(); + + $qResult = $query->execute(); + $result = $qResult->fetchAll(); + $qResult->closeCursor(); $this->assertSame(1, count($result)); $this->assertSame(TrustedServers::STATUS_OK, (int)$result[0]['status']); } |