Skip to content

Commit 7792421

Browse files
committed
Merge pull request #481
2 parents a46774d + 2fb35cb commit 7792421

File tree

5 files changed

+180
-41
lines changed

5 files changed

+180
-41
lines changed

.travis.yml

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,69 @@
11
language: php
22
dist: trusty
3-
sudo: false
4-
5-
services:
6-
- mongodb
3+
sudo: false
74

85
addons:
96
apt:
10-
packages: &common_packages
7+
packages:
118
- gdb
129

10+
cache:
11+
directories:
12+
- ${HOME}/.cache/pip
13+
- ${HOME}/.composer/cache/files
14+
1315
env:
1416
global:
1517
- DRIVER_VERSION=1.4.0RC1
16-
- SERVER_VERSION=3.4
18+
- SERVER_VERSION=3.6.2
1719

1820
matrix:
1921
fast_finish: true
2022
include:
2123
- php: 5.5
22-
addons: &common_addons
23-
apt:
24-
sources: [ mongodb-3.4-precise ]
25-
packages: [ mongodb-org, *common_packages ]
2624
- php: 5.6
27-
addons: *common_addons
2825
- php: 7.0
29-
addons: *common_addons
3026
- php: 7.1
31-
addons: *common_addons
3227
- php: 7.2
33-
addons: *common_addons
3428
- php: 7.0
3529
env:
36-
- SERVER_VERSION=2.6
37-
addons:
38-
apt:
39-
sources: [ mongodb-upstart ]
40-
packages: [ mongodb-org, *common_packages ]
30+
- SERVER_VERSION=2.6.12
4131
- php: 7.0
4232
env:
43-
- SERVER_VERSION=3.0
44-
addons:
45-
apt:
46-
sources: [ mongodb-3.0-precise ]
47-
packages: [ mongodb-org, *common_packages ]
33+
- SERVER_VERSION=3.0.15
4834
- php: 7.0
4935
env:
50-
- SERVER_VERSION=3.2
51-
addons:
52-
apt:
53-
sources: [ mongodb-3.2-precise ]
54-
packages: [ mongodb-org, *common_packages ]
36+
- SERVER_VERSION=3.2.18
37+
- php: 7.0
38+
env:
39+
- SERVER_VERSION=3.4.11
5540

56-
before_script:
41+
before_install:
42+
- pip install "mongo-orchestration>=0.6.7,<1.0" --user `whoami`
43+
- wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-${SERVER_VERSION}.tgz
44+
- tar zxf mongodb-linux-x86_64-${SERVER_VERSION}.tgz
45+
- export PATH=${PWD}/mongodb-linux-x86_64-${SERVER_VERSION}/bin/:${PATH}
5746
- mongod --version
47+
- mongo-orchestration --version
48+
- export MO_PATH=`python -c 'import mongo_orchestration; from os import path; print(path.dirname(mongo_orchestration.__file__));'`
49+
50+
before_script:
51+
- mongo-orchestration start
52+
- pushd ${MO_PATH} && ${TRAVIS_BUILD_DIR}/.travis/mo.sh configurations/servers/clean.json start && popd
5853
- pecl install -f mongodb-${DRIVER_VERSION}
5954
- php --ri mongodb
60-
- composer install --dev --no-interaction --prefer-source
55+
- composer install --no-interaction --no-progress --no-suggest
6156
- ulimit -c
6257
- ulimit -c unlimited -S
6358

6459
script:
65-
- ./vendor/bin/phpunit --debug || RESULT=$?
66-
- for i in $(find ./ -maxdepth 1 -name 'core*' -print); do gdb `php -r 'echo PHP_BINARY;'` core* -ex "thread apply all bt" -ex "set pagination 0" -batch; done;
67-
- if [[ ${RESULT} != 0 ]]; then exit $RESULT ; fi;
60+
- vendor/bin/phpunit -v
61+
62+
before_cache:
63+
- rm -f ${HOME}/.cache/pip/log/debug.log
64+
65+
after_failure:
66+
- find . -name 'core*' -exec ${TRAVIS_BUILD_DIR}/.travis/debug-core.sh {} \;
67+
68+
after_script:
69+
- mongo-orchestration stop

.travis/debug-core.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
if [ "${TRAVIS_OS_NAME}" != "osx" ]; then
4+
# https://www.ics.uci.edu/~pattis/common/handouts/macmingweclipse/allexperimental/mac-gdb-install.html
5+
echo "Cannot debug core files on macOS: ${1}"
6+
exit 1
7+
fi
8+
9+
PHP_BINARY=`which php`
10+
gdb -batch -ex "bt full" -ex "quit" "${PHP_BINARY}" "${1}"

.travis/mo.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash
2+
# Copyright 2012-2014 MongoDB, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
function eval_params {
17+
local params=$(sed -e 's|["]|\\\"|g' $1)
18+
echo $(eval echo \"$params\")
19+
}
20+
21+
function r {
22+
echo $1| cut -d'/' -f 2
23+
}
24+
25+
function a {
26+
echo $(cd $(dirname $1); pwd)/$(basename $1)
27+
}
28+
29+
function id {
30+
local id_line=$(grep id $1 | head -n 1)
31+
echo $(expr "$id_line" : '.*: *"\(.*\)" *,*')
32+
}
33+
34+
function get {
35+
echo "GET $1 $(curl --header 'Accept: application/json' --include --silent --request GET $1)"
36+
}
37+
38+
function post {
39+
echo "POST $1 $(curl --header 'Accept: application/json' --include --silent --request POST --data "$2" $1)"
40+
}
41+
42+
function delete {
43+
echo "DELETE $1 $(curl --header 'Accept: application/json' --include --silent --request DELETE $1)"
44+
}
45+
46+
function code {
47+
expr "$1" : '.*HTTP/1.[01] \([0-9]*\)'
48+
}
49+
50+
function usage {
51+
echo "usage: $0 configurations/cluster/file.json action"
52+
echo "cluster: servers|replica_sets|sharded_clusters"
53+
echo "action: start|status|stop"
54+
exit 1
55+
}
56+
57+
SSL_FILES=$(a ./ssl-files)
58+
BASE_URL=${MONGO_ORCHESTRATION:-'http://localhost:8889'}
59+
60+
if [ $# -ne 2 ]; then usage; fi
61+
if [ ! -f "$1" ]; then echo "configuration file '$1' not found"; exit 1; fi
62+
63+
ID=$(id $1)
64+
if [ ! "$ID" ]; then echo "id field not found in configuration file '$1'"; exit 1; fi
65+
R=$(r $1)
66+
67+
GET=$(get $BASE_URL/$R/$ID)
68+
HTTP_CODE=$(code "$GET")
69+
EXIT_CODE=0
70+
71+
case $2 in
72+
start)
73+
if [ "$HTTP_CODE" != "200" ]
74+
then
75+
WORKSPACE=~/tmp/orchestrations
76+
rm -fr $WORKSPACE
77+
mkdir $WORKSPACE
78+
LOGPATH=$WORKSPACE
79+
DBPATH=$WORKSPACE
80+
POST_DATA=$(eval_params $1)
81+
echo "DBPATH=$DBPATH"
82+
echo "LOGPATH=$LOGPATH"
83+
echo "POST_DATA='$POST_DATA'"
84+
echo
85+
POST=$(post $BASE_URL/$R "$POST_DATA")
86+
echo "$POST"
87+
HTTP_CODE=$(code "$POST")
88+
if [ "$HTTP_CODE" != 200 ]; then EXIT_CODE=1; fi
89+
else
90+
echo "$GET"
91+
fi
92+
;;
93+
stop)
94+
if [ "$HTTP_CODE" == "200" ]
95+
then
96+
DELETE=$(delete $BASE_URL/$R/$ID)
97+
echo "$DELETE"
98+
HTTP_CODE=$(code "$DELETE")
99+
if [ "$HTTP_CODE" != 204 ]; then EXIT_CODE=1; fi
100+
else
101+
echo "$GET"
102+
fi
103+
;;
104+
status)
105+
if [ "$HTTP_CODE" == "200" ]
106+
then
107+
echo "$GET"
108+
else
109+
echo "$GET"
110+
EXIT_CODE=1
111+
fi
112+
;;
113+
*)
114+
usage
115+
;;
116+
esac
117+
exit $EXIT_CODE

tests/Operation/FindFunctionalTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,12 @@ public function testMaxAwaitTimeMS()
154154
$this->markTestSkipped('maxAwaitTimeMS option is not supported');
155155
}
156156

157-
$maxAwaitTimeMS = 10;
157+
$maxAwaitTimeMS = 100;
158+
159+
/* Calculate an approximate pivot to use for time assertions. We will
160+
* assert that the duration of blocking responses is greater than this
161+
* value, and vice versa. */
162+
$pivot = ($maxAwaitTimeMS * 0.001) * 0.9;
158163

159164
// Create a capped collection.
160165
$databaseName = $this->getDatabaseName();
@@ -183,7 +188,7 @@ public function testMaxAwaitTimeMS()
183188
$startTime = microtime(true);
184189
$it->rewind();
185190
$duration = microtime(true) - $startTime;
186-
$this->assertLessThan($maxAwaitTimeMS * 0.001, $duration);
191+
$this->assertLessThan($pivot, $duration);
187192

188193
$this->assertTrue($it->valid());
189194
$this->assertSameDocument(['_id' => 1], $it->current());
@@ -193,7 +198,7 @@ public function testMaxAwaitTimeMS()
193198
$startTime = microtime(true);
194199
$it->next();
195200
$duration = microtime(true) - $startTime;
196-
$this->assertLessThan($maxAwaitTimeMS * 0.001, $duration);
201+
$this->assertLessThan($pivot, $duration);
197202

198203
$this->assertTrue($it->valid());
199204
$this->assertSameDocument(['_id' => 2], $it->current());
@@ -206,7 +211,7 @@ public function testMaxAwaitTimeMS()
206211
$startTime = microtime(true);
207212
$it->next();
208213
$duration = microtime(true) - $startTime;
209-
$this->assertGreaterThanOrEqual($maxAwaitTimeMS * 0.001, $duration);
214+
$this->assertGreaterThan($pivot, $duration);
210215
$this->assertLessThan(0.5, $duration);
211216

212217
$this->assertFalse($it->valid());

tests/Operation/WatchFunctionalTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ public function testMaxAwaitTimeMS()
380380
* ensure we see the write. */
381381
$maxAwaitTimeMS = 100;
382382

383+
/* Calculate an approximate pivot to use for time assertions. We will
384+
* assert that the duration of blocking responses is greater than this
385+
* value, and vice versa. */
386+
$pivot = ($maxAwaitTimeMS * 0.001) * 0.9;
387+
383388
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], ['maxAwaitTimeMS' => $maxAwaitTimeMS]);
384389
$changeStream = $operation->execute($this->getPrimaryServer());
385390

@@ -391,7 +396,7 @@ public function testMaxAwaitTimeMS()
391396
$startTime = microtime(true);
392397
$changeStream->rewind();
393398
$duration = microtime(true) - $startTime;
394-
$this->assertGreaterThanOrEqual($maxAwaitTimeMS * 0.001, $duration);
399+
$this->assertGreaterThan($pivot, $duration);
395400
$this->assertLessThan(0.5, $duration);
396401

397402
$this->assertFalse($changeStream->valid());
@@ -401,7 +406,7 @@ public function testMaxAwaitTimeMS()
401406
$startTime = microtime(true);
402407
$changeStream->next();
403408
$duration = microtime(true) - $startTime;
404-
$this->assertGreaterThanOrEqual($maxAwaitTimeMS * 0.001, $duration);
409+
$this->assertGreaterThan($pivot, $duration);
405410
$this->assertLessThan(0.5, $duration);
406411

407412
$this->assertFalse($changeStream->valid());
@@ -413,7 +418,7 @@ public function testMaxAwaitTimeMS()
413418
$startTime = microtime(true);
414419
$changeStream->next();
415420
$duration = microtime(true) - $startTime;
416-
$this->assertLessThan($maxAwaitTimeMS * 0.001, $duration);
421+
$this->assertLessThan($pivot, $duration);
417422
$this->assertTrue($changeStream->valid());
418423
}
419424

0 commit comments

Comments
 (0)