Skip to content

Commit 9a03d18

Browse files
committed
Note cycling references and killAllSessions before each test
1 parent 9b97ee4 commit 9a03d18

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

tests/UnifiedSpecTests/Constraint/Matches.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Bridge\PhpUnit\ConstraintTrait;
1717
use function array_keys;
1818
use function assertInternalType;
19+
use function assertNotNull;
1920
use function assertRegExp;
2021
use function assertThat;
2122
use function containsOnly;

tests/UnifiedSpecTests/Constraint/MatchesTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
use MongoDB\Tests\UnifiedSpecTests\EntityMap;
88
use PHPUnit\Framework\ExpectationFailedException;
99
use stdClass;
10-
use function fopen;
11-
use function fwrite;
1210
use function hex2bin;
13-
use function rewind;
1411
use function version_compare;
1512

1613
class MatchesTest extends FunctionalTestCase

tests/UnifiedSpecTests/EntityMap.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ class EntityMap implements ArrayAccess
4141
public function __destruct()
4242
{
4343
/* TODO: Determine if this is actually necessary. References to session
44-
* entities should not persist between tests. */
44+
* entities should not persist between tests.
45+
*
46+
* Note: This does not appear to trigger after a test due to cyclic
47+
* references (see comment in UnifiedSpecTest.php). */
4548
foreach ($this->map as $entity) {
4649
if ($entity->value instanceof Session) {
4750
$entity->value->endSession();

tests/UnifiedSpecTests/UnifiedSpecTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace MongoDB\Tests\UnifiedSpecTests;
44

55
use MongoDB\Client;
6-
use MongoDB\Driver\Command;
76
use MongoDB\Driver\Exception\ServerException;
87
use MongoDB\Driver\ReadPreference;
98
use MongoDB\Driver\Server;
9+
use MongoDB\Operation\DatabaseCommand;
1010
use MongoDB\Tests\FunctionalTestCase;
1111
use stdClass;
1212
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
@@ -45,16 +45,23 @@ private static function doSetUpBeforeClass()
4545
{
4646
parent::setUpBeforeClass();
4747

48-
/* TODO: FunctionalTestCase::getUri() restricts to a single mongos by
49-
* default. Determine if there's a need to override that. */
50-
self::$internalClient = new Client(static::getUri());
48+
/* Provide internal client unmodified URI, since it may need to execute
49+
* commands on multiple mongoses (e.g. killAllSessions) */
50+
self::$internalClient = new Client(static::getUri(true));
5151
self::killAllSessions();
5252
}
5353

5454
private function doSetUp()
5555
{
5656
parent::setUp();
5757

58+
/* TODO: The transactions spec advises calling killAllSessions only at
59+
* the start of the test suite and after failed tests; however, the
60+
* "unpin after transient error within a transaction" pinning test
61+
* causes the subsequent transaction test to block. This can be removed
62+
* once that is addressed. */
63+
self::killAllSessions();
64+
5865
$this->failPointObserver = new FailPointObserver();
5966
$this->failPointObserver->start();
6067
}
@@ -68,6 +75,10 @@ private function doTearDown()
6875
$this->failPointObserver->stop();
6976
$this->failPointObserver->disableFailPoints();
7077

78+
/* TODO: Consider manually invoking gc_collect_cycles since each test is
79+
* prone to create cycles (perhaps due to EntityMap), which can leak and
80+
* prevent sessions from being released back into the pool. */
81+
7182
parent::tearDown();
7283
}
7384

@@ -299,7 +310,9 @@ private static function killAllSessions()
299310
if (! isset($server->getInfo()['logicalSessionTimeoutMinutes'])) {
300311
continue;
301312
}
302-
$server->executeCommand('admin', new Command(['killAllSessions' => []]));
313+
314+
$command = new DatabaseCommand('admin', ['killAllSessions' => []]);
315+
$command->execute($server);
303316
} catch (ServerException $e) {
304317
// Interrupted error is safe to ignore (see: SERVER-38335)
305318
if ($e->getCode() != self::SERVER_ERROR_INTERRUPTED) {

0 commit comments

Comments
 (0)