Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
92818739
Unverified
Commit
92818739
authored
Sep 04, 2019
by
Andreas Braun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-466: Implement mongos pinning prose tests
parent
e7744342
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
0 deletions
+77
-0
TransactionsSpecTest.php
tests/SpecTests/TransactionsSpecTest.php
+77
-0
No files found.
tests/SpecTests/TransactionsSpecTest.php
View file @
92818739
...
...
@@ -4,6 +4,7 @@ namespace MongoDB\Tests\SpecTests;
use
MongoDB\BSON\Int64
;
use
MongoDB\BSON\Timestamp
;
use
MongoDB\Client
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Exception\ServerException
;
use
MongoDB\Driver\Manager
;
...
...
@@ -11,7 +12,9 @@ use MongoDB\Driver\ReadPreference;
use
MongoDB\Driver\Server
;
use
stdClass
;
use
Symfony\Bridge\PhpUnit\SetUpTearDownTrait
;
use
function
array_unique
;
use
function
basename
;
use
function
count
;
use
function
dirname
;
use
function
file_get_contents
;
use
function
get_object_vars
;
...
...
@@ -205,6 +208,80 @@ class TransactionsSpecTest extends FunctionalTestCase
return
$testArgs
;
}
/**
* Prose test 1: Test that starting a new transaction on a pinned
* ClientSession unpins the session and normal server selection is performed
* for the next operation.
*/
public
function
testStartingNewTransactionOnPinnedSessionUnpinsSession
()
{
if
(
!
$this
->
isShardedClusterUsingReplicasets
())
{
$this
->
markTestSkipped
(
'Mongos pinning tests can only run on sharded clusters using replica sets'
);
}
$client
=
new
Client
(
$this
->
getUri
(
true
));
$session
=
$client
->
startSession
();
$collection
=
$client
->
selectCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
// Create collection before transaction
$collection
->
insertOne
([]);
$session
->
startTransaction
([]);
$collection
->
insertOne
([],
[
'session'
=>
$session
]);
$session
->
commitTransaction
();
$servers
=
[];
for
(
$i
=
0
;
$i
<
50
;
$i
++
)
{
$session
->
startTransaction
([]);
$cursor
=
$collection
->
find
([],
[
'session'
=>
$session
]);
$servers
[]
=
$cursor
->
getServer
()
->
getHost
()
.
':'
.
$cursor
->
getServer
()
->
getPort
();
$this
->
assertInstanceOf
(
Server
::
class
,
$session
->
getServer
());
$session
->
commitTransaction
();
}
$servers
=
array_unique
(
$servers
);
$this
->
assertGreaterThan
(
1
,
count
(
$servers
));
$session
->
endSession
();
}
/**
* Prose test 2: Test non-transaction operations using a pinned
* ClientSession unpins the session and normal server selection is
* performed.
*/
public
function
testRunningNonTransactionOperationOnPinnedSessionUnpinsSession
()
{
if
(
!
$this
->
isShardedClusterUsingReplicasets
())
{
$this
->
markTestSkipped
(
'Mongos pinning tests can only run on sharded clusters using replica sets'
);
}
$client
=
new
Client
(
$this
->
getUri
(
true
));
$session
=
$client
->
startSession
();
$collection
=
$client
->
selectCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
// Create collection before transaction
$collection
->
insertOne
([]);
$session
->
startTransaction
([]);
$collection
->
insertOne
([],
[
'session'
=>
$session
]);
$session
->
commitTransaction
();
$servers
=
[];
for
(
$i
=
0
;
$i
<
50
;
$i
++
)
{
$cursor
=
$collection
->
find
([],
[
'session'
=>
$session
]);
$servers
[]
=
$cursor
->
getServer
()
->
getHost
()
.
':'
.
$cursor
->
getServer
()
->
getPort
();
$this
->
assertNull
(
$session
->
getServer
());
}
$servers
=
array_unique
(
$servers
);
$this
->
assertGreaterThan
(
1
,
count
(
$servers
));
$session
->
endSession
();
}
/**
* Create the collection, since it cannot be created within a transaction.
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment