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
e4a7f0a4
Commit
e4a7f0a4
authored
Feb 01, 2018
by
Katherine Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve maxAwaitTimeMS test for ChangeStreamFunctionalTest
parent
783fd434
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
8 deletions
+36
-8
ChangeStreamFunctionalTest.php
tests/Operation/ChangeStreamFunctionalTest.php
+36
-8
No files found.
tests/Operation/ChangeStreamFunctionalTest.php
View file @
e4a7f0a4
...
@@ -241,17 +241,45 @@ class ChangeStreamFunctionalTest extends FunctionalTestCase
...
@@ -241,17 +241,45 @@ class ChangeStreamFunctionalTest extends FunctionalTestCase
public
function
testMaxAwaitTimeMS
()
public
function
testMaxAwaitTimeMS
()
{
{
$this
->
collection
=
new
Collection
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$this
->
collection
=
new
Collection
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$maxAwaitTimeMS
=
10
;
/* 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
* ensure we see the write. */
$maxAwaitTimeMS
=
100
;
$changeStreamResult
=
$this
->
collection
->
watch
([],
[
'maxAwaitTimeMS'
=>
$maxAwaitTimeMS
]);
$changeStreamResult
=
$this
->
collection
->
watch
([],
[
'maxAwaitTimeMS'
=>
$maxAwaitTimeMS
]);
/* Make sure we await results for at least maxAwaitTimeMS, since no new
/* The initial change stream is empty so we should expect a delay when
* documents should be inserted to wake up the server's command thread.
* we call rewind, since it issues a getMore. Expect to wait at least
* Also ensure that we don't wait too long (server default is one
* maxAwaitTimeMS, since no new documents should be inserted to wake up
* second). */
* the server's query thread. Also ensure we don't wait too long (server
* default is one second). */
$startTime
=
microtime
(
true
);
$startTime
=
microtime
(
true
);
$changeStreamResult
->
rewind
();
$changeStreamResult
->
rewind
();
$this
->
assertGreaterThanOrEqual
(
$maxAwaitTimeMS
*
0.001
,
microtime
(
true
)
-
$startTime
);
$duration
=
microtime
(
true
)
-
$startTime
;
$this
->
assertLessThan
(
0.5
,
microtime
(
true
)
-
$startTime
);
$this
->
assertGreaterThanOrEqual
(
$maxAwaitTimeMS
*
0.001
,
$duration
);
}
$this
->
assertLessThan
(
0.5
,
$duration
);
$this
->
assertFalse
(
$changeStreamResult
->
valid
());
/* Advancing again on a change stream will issue a getMore, so we should
* expect a delay again. */
$startTime
=
microtime
(
true
);
$changeStreamResult
->
next
();
$duration
=
microtime
(
true
)
-
$startTime
;
$this
->
assertGreaterThanOrEqual
(
$maxAwaitTimeMS
*
0.001
,
$duration
);
$this
->
assertLessThan
(
0.5
,
$duration
);
$this
->
assertFalse
(
$changeStreamResult
->
valid
());
/* After inserting a document, the change stream will not issue a
* getMore so we should not expect a delay. */
$result
=
$this
->
collection
->
insertOne
([
'_id'
=>
1
]);
$this
->
assertInstanceOf
(
'MongoDB\InsertOneResult'
,
$result
);
$this
->
assertSame
(
1
,
$result
->
getInsertedCount
());
$startTime
=
microtime
(
true
);
$changeStreamResult
->
next
();
$duration
=
microtime
(
true
)
-
$startTime
;
$this
->
assertLessThan
(
$maxAwaitTimeMS
*
0.001
,
$duration
);
$this
->
assertTrue
(
$changeStreamResult
->
valid
());
}
}
}
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