Skip to content

Commit 3370bfc

Browse files
PHPLIB-761: Disable client persistence when creating clients in test runners (mongodb#905)
Replacing old random ids for new clients with special flag "disableClientPersistence" to maintain tests same behavior.
1 parent a5c1bf8 commit 3370bfc

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

tests/SpecTests/Context.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use function array_keys;
1616
use function getenv;
1717
use function implode;
18-
use function mt_rand;
1918
use function uniqid;
2019

2120
/**
@@ -239,12 +238,10 @@ public static function fromTransactions(stdClass $test, $databaseName, $collecti
239238

240239
$clientOptions = isset($test->clientOptions) ? (array) $test->clientOptions : [];
241240

242-
/* Transaction spec tests expect a new client for each test so that
243-
* txnNumber values are deterministic. Append a random option to avoid
244-
* re-using a previously persisted libmongoc client object. */
245-
$clientOptions += ['p' => mt_rand()];
241+
// Transaction spec tests expect a new client for each test so that txnNumber values are deterministic.
242+
$driverOptions = ['disableClientPersistence' => true];
246243

247-
$o->client = FunctionalTestCase::createTestClient(FunctionalTestCase::getUri($useMultipleMongoses), $clientOptions);
244+
$o->client = FunctionalTestCase::createTestClient(FunctionalTestCase::getUri($useMultipleMongoses), $clientOptions, $driverOptions);
248245

249246
$session0Options = isset($test->sessionOptions->session0) ? (array) $test->sessionOptions->session0 : [];
250247
$session1Options = isset($test->sessionOptions->session1) ? (array) $test->sessionOptions->session1 : [];

tests/UnifiedSpecTests/Context.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,8 @@ private function createClient(string $id, stdClass $o): void
294294
}
295295
}
296296

297-
/* TODO: Remove this once PHPC-1645 is implemented. Each client needs
298-
* its own libmongoc client to facilitate txnNumber assertions. */
299-
static $i = 0;
300-
$driverOptions = isset($observeEvents) ? ['i' => $i++] : [];
297+
// Transaction tests expect a new client for each test so that txnNumber values are deterministic.
298+
$driverOptions = isset($observeEvents) ? ['disableClientPersistence' => true] : [];
301299

302300
if ($serverApi !== null) {
303301
assertIsObject($serverApi);

0 commit comments

Comments
 (0)