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
72508634
Commit
72508634
authored
Mar 13, 2018
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'v1.3'
parents
5eb04b64
d42c3b4a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
16 deletions
+23
-16
WatchFunctionalTest.php
tests/Operation/WatchFunctionalTest.php
+23
-16
No files found.
tests/Operation/WatchFunctionalTest.php
View file @
72508634
...
@@ -18,6 +18,8 @@ use ReflectionClass;
...
@@ -18,6 +18,8 @@ use ReflectionClass;
class
WatchFunctionalTest
extends
FunctionalTestCase
class
WatchFunctionalTest
extends
FunctionalTestCase
{
{
private
$defaultOptions
=
[
'maxAwaitTimeMS'
=>
500
];
public
function
setUp
()
public
function
setUp
()
{
{
parent
::
setUp
();
parent
::
setUp
();
...
@@ -35,7 +37,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -35,7 +37,7 @@ class WatchFunctionalTest extends FunctionalTestCase
{
{
$this
->
insertDocument
([
'_id'
=>
1
,
'x'
=>
'foo'
]);
$this
->
insertDocument
([
'_id'
=>
1
,
'x'
=>
'foo'
]);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'maxAwaitTimeMS'
=>
100
]
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
->
rewind
();
$changeStream
->
rewind
();
...
@@ -82,7 +84,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -82,7 +84,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$manager
=
new
Manager
(
$this
->
getUri
(),
[
'socketTimeoutMS'
=>
50
]);
$manager
=
new
Manager
(
$this
->
getUri
(),
[
'socketTimeoutMS'
=>
50
]);
$primaryServer
=
$manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
$primaryServer
=
$manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
$operation
=
new
Watch
(
$manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'maxAwaitTimeMS'
=>
100
]
);
$operation
=
new
Watch
(
$manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$primaryServer
);
$changeStream
=
$operation
->
execute
(
$primaryServer
);
/* Note: we intentionally do not start iteration with rewind() to ensure
/* Note: we intentionally do not start iteration with rewind() to ensure
...
@@ -135,7 +137,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -135,7 +137,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$manager
=
new
Manager
(
$this
->
getUri
(),
[
'socketTimeoutMS'
=>
50
]);
$manager
=
new
Manager
(
$this
->
getUri
(),
[
'socketTimeoutMS'
=>
50
]);
$primaryServer
=
$manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
$primaryServer
=
$manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
$operation
=
new
Watch
(
$manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'maxAwaitTimeMS'
=>
100
]
);
$operation
=
new
Watch
(
$manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$primaryServer
);
$changeStream
=
$operation
->
execute
(
$primaryServer
);
$commands
=
[];
$commands
=
[];
...
@@ -181,7 +183,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -181,7 +183,7 @@ class WatchFunctionalTest extends FunctionalTestCase
{
{
$this
->
insertDocument
([
'_id'
=>
1
,
'x'
=>
'foo'
]);
$this
->
insertDocument
([
'_id'
=>
1
,
'x'
=>
'foo'
]);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'maxAwaitTimeMS'
=>
100
]
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
->
rewind
();
$changeStream
->
rewind
();
...
@@ -226,7 +228,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -226,7 +228,7 @@ class WatchFunctionalTest extends FunctionalTestCase
public
function
testKey
()
public
function
testKey
()
{
{
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'maxAwaitTimeMS'
=>
100
]
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertFalse
(
$changeStream
->
valid
());
$this
->
assertFalse
(
$changeStream
->
valid
());
...
@@ -263,7 +265,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -263,7 +265,7 @@ class WatchFunctionalTest extends FunctionalTestCase
{
{
$pipeline
=
[[
'$project'
=>
[
'foo'
=>
[
0
]]]];
$pipeline
=
[[
'$project'
=>
[
'foo'
=>
[
0
]]]];
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$pipeline
,
[
'maxAwaitTimeMS'
=>
100
]
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$pipeline
,
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
insertDocument
([
'_id'
=>
1
]);
$this
->
insertDocument
([
'_id'
=>
1
]);
...
@@ -313,7 +315,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -313,7 +315,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$this
->
expectException
(
ResumeTokenException
::
class
);
$this
->
expectException
(
ResumeTokenException
::
class
);
$this
->
expectExceptionMessage
(
'Resume token not found in change document'
);
$this
->
expectExceptionMessage
(
'Resume token not found in change document'
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$pipeline
,
[
'maxAwaitTimeMS'
=>
100
]
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$pipeline
,
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
/* Note: we intentionally do not start iteration with rewind() to ensure
/* Note: we intentionally do not start iteration with rewind() to ensure
...
@@ -330,7 +332,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -330,7 +332,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$this
->
expectException
(
ResumeTokenException
::
class
);
$this
->
expectException
(
ResumeTokenException
::
class
);
$this
->
expectExceptionMessage
(
'Resume token not found in change document'
);
$this
->
expectExceptionMessage
(
'Resume token not found in change document'
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$pipeline
,
[
'maxAwaitTimeMS'
=>
100
]
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$pipeline
,
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
insertDocument
([
'x'
=>
1
]);
$this
->
insertDocument
([
'x'
=>
1
]);
...
@@ -345,7 +347,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -345,7 +347,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$this
->
expectException
(
ResumeTokenException
::
class
);
$this
->
expectException
(
ResumeTokenException
::
class
);
$this
->
expectExceptionMessage
(
'Expected resume token to have type "array or object" but found "string"'
);
$this
->
expectExceptionMessage
(
'Expected resume token to have type "array or object" but found "string"'
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$pipeline
,
[
'maxAwaitTimeMS'
=>
100
]
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$pipeline
,
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
/* Note: we intentionally do not start iteration with rewind() to ensure
/* Note: we intentionally do not start iteration with rewind() to ensure
...
@@ -362,7 +364,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -362,7 +364,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$this
->
expectException
(
ResumeTokenException
::
class
);
$this
->
expectException
(
ResumeTokenException
::
class
);
$this
->
expectExceptionMessage
(
'Expected resume token to have type "array or object" but found "string"'
);
$this
->
expectExceptionMessage
(
'Expected resume token to have type "array or object" but found "string"'
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$pipeline
,
[
'maxAwaitTimeMS'
=>
100
]
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$pipeline
,
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
insertDocument
([
'x'
=>
1
]);
$this
->
insertDocument
([
'x'
=>
1
]);
...
@@ -375,13 +377,18 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -375,13 +377,18 @@ class WatchFunctionalTest extends FunctionalTestCase
/* On average, an acknowledged write takes about 20 ms to appear in a
/* On average, an acknowledged write takes about 20 ms to appear in a
* change stream on the server so we'll use a higher maxAwaitTimeMS to
* change stream on the server so we'll use a higher maxAwaitTimeMS to
* ensure we see the write. */
* ensure we see the write. */
$maxAwaitTimeMS
=
1
00
;
$maxAwaitTimeMS
=
5
00
;
/* Calculate an approximate pivot to use for time assertions. We will
/* Calculate an approximate pivot to use for time assertions. We will
* assert that the duration of blocking responses is greater than this
* assert that the duration of blocking responses is greater than this
* value, and vice versa. */
* value, and vice versa. */
$pivot
=
(
$maxAwaitTimeMS
*
0.001
)
*
0.9
;
$pivot
=
(
$maxAwaitTimeMS
*
0.001
)
*
0.9
;
/* Calculate an approximate upper bound to use for time assertions. We
* will assert that the duration of blocking responses is less than this
* value. */
$upperBound
=
(
$maxAwaitTimeMS
*
0.001
)
*
1.5
;
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'maxAwaitTimeMS'
=>
$maxAwaitTimeMS
]);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'maxAwaitTimeMS'
=>
$maxAwaitTimeMS
]);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
...
@@ -394,7 +401,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -394,7 +401,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$changeStream
->
rewind
();
$changeStream
->
rewind
();
$duration
=
microtime
(
true
)
-
$startTime
;
$duration
=
microtime
(
true
)
-
$startTime
;
$this
->
assertGreaterThan
(
$pivot
,
$duration
);
$this
->
assertGreaterThan
(
$pivot
,
$duration
);
$this
->
assertLessThan
(
0.5
,
$duration
);
$this
->
assertLessThan
(
$upperBound
,
$duration
);
$this
->
assertFalse
(
$changeStream
->
valid
());
$this
->
assertFalse
(
$changeStream
->
valid
());
...
@@ -404,7 +411,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -404,7 +411,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$changeStream
->
next
();
$changeStream
->
next
();
$duration
=
microtime
(
true
)
-
$startTime
;
$duration
=
microtime
(
true
)
-
$startTime
;
$this
->
assertGreaterThan
(
$pivot
,
$duration
);
$this
->
assertGreaterThan
(
$pivot
,
$duration
);
$this
->
assertLessThan
(
0.5
,
$duration
);
$this
->
assertLessThan
(
$upperBound
,
$duration
);
$this
->
assertFalse
(
$changeStream
->
valid
());
$this
->
assertFalse
(
$changeStream
->
valid
());
...
@@ -421,7 +428,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -421,7 +428,7 @@ class WatchFunctionalTest extends FunctionalTestCase
public
function
testRewindResumesAfterCursorNotFound
()
public
function
testRewindResumesAfterCursorNotFound
()
{
{
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'maxAwaitTimeMS'
=>
100
]
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
killChangeStreamCursor
(
$changeStream
);
$this
->
killChangeStreamCursor
(
$changeStream
);
...
@@ -433,7 +440,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -433,7 +440,7 @@ class WatchFunctionalTest extends FunctionalTestCase
public
function
testRewindExtractsResumeTokenAndNextResumes
()
public
function
testRewindExtractsResumeTokenAndNextResumes
()
{
{
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'maxAwaitTimeMS'
=>
100
]
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
insertDocument
([
'_id'
=>
1
,
'x'
=>
'foo'
]);
$this
->
insertDocument
([
'_id'
=>
1
,
'x'
=>
'foo'
]);
...
@@ -470,7 +477,7 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -470,7 +477,7 @@ class WatchFunctionalTest extends FunctionalTestCase
*/
*/
public
function
testTypeMapOption
(
array
$typeMap
,
$expectedChangeDocument
)
public
function
testTypeMapOption
(
array
$typeMap
,
$expectedChangeDocument
)
{
{
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'
maxAwaitTimeMS'
=>
100
,
'typeMap'
=>
$typeMap
]
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'
typeMap'
=>
$typeMap
]
+
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$changeStream
->
rewind
();
$changeStream
->
rewind
();
...
...
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