3
3
namespace MongoDB \Tests \UnifiedSpecTests ;
4
4
5
5
use MongoDB \Client ;
6
- use MongoDB \Driver \Command ;
7
6
use MongoDB \Driver \Exception \ServerException ;
8
7
use MongoDB \Driver \ReadPreference ;
9
8
use MongoDB \Driver \Server ;
9
+ use MongoDB \Operation \DatabaseCommand ;
10
10
use MongoDB \Tests \FunctionalTestCase ;
11
11
use stdClass ;
12
12
use Symfony \Bridge \PhpUnit \SetUpTearDownTrait ;
@@ -45,16 +45,23 @@ private static function doSetUpBeforeClass()
45
45
{
46
46
parent ::setUpBeforeClass ();
47
47
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 ));
51
51
self ::killAllSessions ();
52
52
}
53
53
54
54
private function doSetUp ()
55
55
{
56
56
parent ::setUp ();
57
57
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
+
58
65
$ this ->failPointObserver = new FailPointObserver ();
59
66
$ this ->failPointObserver ->start ();
60
67
}
@@ -68,6 +75,10 @@ private function doTearDown()
68
75
$ this ->failPointObserver ->stop ();
69
76
$ this ->failPointObserver ->disableFailPoints ();
70
77
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
+
71
82
parent ::tearDown ();
72
83
}
73
84
@@ -299,7 +310,9 @@ private static function killAllSessions()
299
310
if (! isset ($ server ->getInfo ()['logicalSessionTimeoutMinutes ' ])) {
300
311
continue ;
301
312
}
302
- $ server ->executeCommand ('admin ' , new Command (['killAllSessions ' => []]));
313
+
314
+ $ command = new DatabaseCommand ('admin ' , ['killAllSessions ' => []]);
315
+ $ command ->execute ($ server );
303
316
} catch (ServerException $ e ) {
304
317
// Interrupted error is safe to ignore (see: SERVER-38335)
305
318
if ($ e ->getCode () != self ::SERVER_ERROR_INTERRUPTED ) {
0 commit comments