1--TEST-- 2MongoDB\Driver\Manager::executeReadWriteCommand() pins transaction to server 3--SKIPIF-- 4<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> 5<?php skip_if_not_mongos_with_replica_set(); ?> 6<?php skip_if_server_version('<', '4.1.6'); ?> 7<?php skip_if_not_clean(); ?> 8--FILE-- 9<?php 10require_once __DIR__ . "/../utils/basic.inc"; 11 12$manager = new MongoDB\Driver\Manager(URI); 13 14/* Create collections as that can't be (automatically) done in a transaction */ 15$manager->executeCommand( 16 DATABASE_NAME, 17 new \MongoDB\Driver\Command([ 'create' => COLLECTION_NAME ]), 18 [ 'writeConcern' => new \MongoDB\Driver\WriteConcern( \MongoDB\Driver\WriteConcern::MAJORITY ) ] 19); 20 21$session = $manager->startSession(); 22var_dump($session->getServer() instanceof \MongoDB\Driver\Server); 23 24$session->startTransaction(); 25var_dump($session->getServer() instanceof \MongoDB\Driver\Server); 26 27$command = new MongoDB\Driver\Command([ 28 'aggregate' => COLLECTION_NAME, 29 'pipeline' => [ 30 ['$group' => ['_id' => 1]], 31 /* Note: $out cannot be used in a transaction. This is technically not a 32 * write command, but it works for the purposes of this test. */ 33 ], 34 'cursor' => (object) [] 35]); 36$manager->executeReadWriteCommand(DATABASE_NAME, $command, ['session' => $session]); 37 38$pinnedServer = $session->getServer(); 39var_dump($pinnedServer instanceof \MongoDB\Driver\Server); 40 41$bulk = new MongoDB\Driver\BulkWrite(); 42$bulk->insert(['x' => 1]); 43$manager->executeBulkWrite(NS, $bulk, ['session' => $session]); 44 45$session->commitTransaction(); 46 47var_dump($session->getServer() == $pinnedServer); 48 49$bulk = new MongoDB\Driver\BulkWrite(); 50$bulk->insert(['x' => 1]); 51$manager->executeBulkWrite(NS, $bulk, ['session' => $session]); 52 53var_dump($session->getServer() instanceof \MongoDB\Driver\Server); 54 55?> 56===DONE=== 57<?php exit(0); ?> 58--EXPECT-- 59bool(false) 60bool(false) 61bool(true) 62bool(true) 63bool(false) 64===DONE=== 65