Skip to content

Commit 4f0f1f7

Browse files
committed
Merge pull request #87 from plotly/jun_supervisor
Improve docker container reliability
2 parents 9c5221e + b4aa68b commit 4f0f1f7

File tree

5 files changed

+44
-29
lines changed

5 files changed

+44
-29
lines changed

circle.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ dependencies:
1515
- docker pull plotly/imageserver:latest
1616
post:
1717
- npm run cibuild
18-
- docker run -d --name myimageserver -v $PWD:/var/www/streambed/image_server/plotly.js -p 9010:9010 plotly/imageserver:latest; sleep 20
19-
18+
- docker run -d --name myimageserver -v $PWD:/var/www/streambed/image_server/plotly.js -p 9010:9010 plotly/imageserver:latest
19+
- wget --server-response --spider --tries=8 --retry-connrefused http://localhost:9010/ping
2020
test:
2121
override:
2222
- sudo lxc-attach -n "$(docker inspect --format '{{.Id}}' myimageserver)" -- bash -c "cd /var/www/streambed/image_server/plotly.js && node test/image/compare_pixels_test.js"

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ dev:
1818
- .:/var/www/streambed/image_server/plotly.js
1919
ports:
2020
- "9010:9010"
21-
- "2022:22"
21+
- "2022:22"

tasks/baseline.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ CONTAINER_NAME="imagetest" # same as in docker-compose.yml
1212
CMD=(
1313
"cd /var/www/streambed/image_server/plotly.js &&"
1414
"cp -f test/image/index.html ../server_app/index.html &&"
15-
"monit restart nw1 &&"
16-
"sleep 5 &&"
15+
"supervisorctl restart nw1 &&"
16+
"wget --server-response --spider --tries=8 --retry-connrefused http://localhost:9010/ping &&"
1717
"node test/image/make_baseline.js $1"
1818
)
1919

tasks/test_image.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ CONTAINER_NAME="imagetest" # same as in docker-compose.yml
1212
CMD=(
1313
"cd /var/www/streambed/image_server/plotly.js &&"
1414
"cp -f test/image/index.html ../server_app/index.html &&"
15-
"monit restart nw1 &&"
16-
"sleep 5 &&"
15+
"supervisorctl restart nw1 && "
16+
"wget --server-response --spider --tries=8 --retry-connrefused http://localhost:9010/ping &&"
1717
"node test/image/compare_pixels_test.js $1"
1818
)
1919

test/image/compare_pixels_test.js

+37-22
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,29 @@ var request = require('request');
99
var test = require('tape');
1010
var gm = require('gm');
1111

12+
var touch = function(fileName) {
13+
fs.closeSync(fs.openSync(fileName, 'w'));
14+
};
15+
1216

1317
// make artifact folders
14-
if(!fs.existsSync(constants.pathToTestImagesDiff)) fs.mkdirSync(constants.pathToTestImagesDiff);
15-
if(!fs.existsSync(constants.pathToTestImages)) fs.mkdirSync(constants.pathToTestImages);
18+
if(!fs.existsSync(constants.pathToTestImagesDiff)) {
19+
fs.mkdirSync(constants.pathToTestImagesDiff);
20+
}
21+
if(!fs.existsSync(constants.pathToTestImages)) {
22+
fs.mkdirSync(constants.pathToTestImages);
23+
}
1624

1725
var userFileName = process.argv[2];
1826

19-
var touch = function(fileName) {
20-
fs.closeSync(fs.openSync(fileName, 'w'));
21-
};
22-
23-
if (!userFileName) runAll();
27+
// run the test(s)
28+
if(!userFileName) runAll();
2429
else runSingle(userFileName);
2530

2631
function runAll () {
2732
test('testing mocks', function (t) {
2833

29-
var files = fs.readdirSync(constants.pathToTestImageMocks);
34+
var allMocks = fs.readdirSync(constants.pathToTestImageMocks);
3035

3136
/*
3237
* Some test cases exhibit run-to-run randomness;
@@ -35,15 +40,34 @@ function runAll () {
3540
* More info:
3641
* https://github.com/plotly/plotly.js/issues/62
3742
*
38-
* 40 test cases are removed:
43+
* 41 test cases are removed:
3944
* - font-wishlist (1 test case)
4045
* - all gl2d (38)
41-
* - gl2d_bunny-hull (1)
46+
* - gl3d_bunny-hull (1)
47+
* - polar_scatter (1)
4248
*/
43-
t.plan(files.length - 40);
49+
var mocks = allMocks.filter(function(mock) {
50+
return !(
51+
mock === 'font-wishlist.json' ||
52+
mock.indexOf('gl2d') !== -1 ||
53+
mock === 'gl3d_bunny-hull.json' ||
54+
mock === 'polar_scatter.json'
55+
);
56+
});
57+
58+
var BASE_TIMEOUT = 500, // base timeout time
59+
BATCH_SIZE = 5, // size of each test 'batch'
60+
cnt = 0;
61+
62+
function testFunction() {
63+
testMock(mocks[cnt++], t);
64+
}
65+
66+
t.plan(mocks.length);
4467

45-
for (var i = 0; i < files.length; i ++) {
46-
testMock(files[i], t);
68+
for(var i = 0; i < mocks.length; i++) {
69+
setTimeout(testFunction,
70+
BASE_TIMEOUT * Math.floor(i / BATCH_SIZE) * BATCH_SIZE);
4771
}
4872

4973
});
@@ -57,15 +81,6 @@ function runSingle (userFileName) {
5781
}
5882

5983
function testMock (fileName, t) {
60-
if(path.extname(fileName) !== '.json') return;
61-
if(fileName === 'font-wishlist.json' && !userFileName) return;
62-
63-
// TODO fix race condition in gl2d image generation
64-
if(fileName.indexOf('gl2d_') !== -1) return;
65-
66-
// TODO fix run-to-run randomness
67-
if(fileName === 'gl3d_bunny-hull.json') return;
68-
6984
var figure = require(path.join(constants.pathToTestImageMocks, fileName));
7085
var bodyMock = {
7186
figure: figure,

0 commit comments

Comments
 (0)