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
a949df52
Commit
a949df52
authored
Aug 22, 2018
by
Derick Rethans
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-384: Allow ModifyCollection test to work in sharded environment
parent
75cbc782
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
6 deletions
+38
-6
DatabaseFunctionalTest.php
tests/Database/DatabaseFunctionalTest.php
+22
-4
ModifyCollectionFunctionalTest.php
tests/Operation/ModifyCollectionFunctionalTest.php
+16
-2
No files found.
tests/Database/DatabaseFunctionalTest.php
View file @
a949df52
...
@@ -161,11 +161,29 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -161,11 +161,29 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$createIndexes
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$indexes
);
$createIndexes
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$indexes
);
$createIndexes
->
execute
(
$this
->
getPrimaryServer
());
$createIndexes
->
execute
(
$this
->
getPrimaryServer
());
$commandResult
=
$this
->
database
->
modifyCollection
(
$this
->
getCollectionName
(),
[
'index'
=>
[
'keyPattern'
=>
[
'lastAccess'
=>
1
],
'expireAfterSeconds'
=>
1000
]]);
$commandResult
=
$this
->
database
->
modifyCollection
(
$this
->
getCollectionName
(),
[
'index'
=>
[
'keyPattern'
=>
[
'lastAccess'
=>
1
],
'expireAfterSeconds'
=>
1000
]],
[
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
]]
);
$this
->
assertCommandSucceeded
(
$commandResult
);
$this
->
assertCommandSucceeded
(
$commandResult
);
$this
->
assertSame
(
3
,
$commandResult
[
'expireAfterSeconds_old'
]);
$this
->
assertSame
(
1000
,
$commandResult
[
'expireAfterSeconds_new'
]);
$commandResult
=
(
array
)
$commandResult
;
if
(
array_key_exists
(
'raw'
,
$commandResult
))
{
/* Sharded environment, where we only assert if a shard had a successful update. For
* non-primary shards that don't have chunks for the collection, the result contains a
* "ns does not exist" error. */
foreach
(
$commandResult
[
'raw'
]
as
$shard
)
{
if
(
array_key_exists
(
'ok'
,
$shard
)
&&
$shard
[
'ok'
]
==
1
)
{
$this
->
assertSame
(
3
,
$shard
[
'expireAfterSeconds_old'
]);
$this
->
assertSame
(
1000
,
$shard
[
'expireAfterSeconds_new'
]);
}
}
}
else
{
$this
->
assertSame
(
3
,
$commandResult
[
'expireAfterSeconds_old'
]);
$this
->
assertSame
(
1000
,
$commandResult
[
'expireAfterSeconds_new'
]);
}
}
}
...
...
tests/Operation/ModifyCollectionFunctionalTest.php
View file @
a949df52
...
@@ -25,7 +25,21 @@ class ModifyCollectionFunctionalTest extends FunctionalTestCase
...
@@ -25,7 +25,21 @@ class ModifyCollectionFunctionalTest extends FunctionalTestCase
);
);
$result
=
$modifyCollection
->
execute
(
$this
->
getPrimaryServer
());
$result
=
$modifyCollection
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertSame
(
3
,
$result
[
'expireAfterSeconds_old'
]);
if
(
array_key_exists
(
'raw'
,
$result
))
{
$this
->
assertSame
(
1000
,
$result
[
'expireAfterSeconds_new'
]);
/* Sharded environment, where we only assert if a shard had a successful update. For
* non-primary shards that don't have chunks for the collection, the result contains a
* "ns does not exist" error. */
foreach
(
$result
[
'raw'
]
as
$shard
)
{
$shard
=
(
array
)
$shard
;
if
(
array_key_exists
(
'ok'
,
$shard
)
&&
$shard
[
'ok'
]
==
1
)
{
$this
->
assertSame
(
3
,
$shard
[
'expireAfterSeconds_old'
]);
$this
->
assertSame
(
1000
,
$shard
[
'expireAfterSeconds_new'
]);
}
}
}
else
{
$this
->
assertSame
(
3
,
$result
[
'expireAfterSeconds_old'
]);
$this
->
assertSame
(
1000
,
$result
[
'expireAfterSeconds_new'
]);
}
}
}
}
}
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