test for app configuration - disable test pmx autoinject for http

This commit is contained in:
Unitech 2015-09-01 16:21:57 +02:00
parent 3ff1b6ddb6
commit 7b9380c5dc
4 changed files with 124 additions and 2 deletions

View File

@ -0,0 +1,56 @@
#!/usr/bin/env bash
SRC=$(cd $(dirname "$0"); pwd)
source "${SRC}/include.sh"
echo -e "\033[1mRunning tests:\033[0m"
cd $file_path
$pm2 unset echo
spec "Should unset echo variables"
$pm2 start echo.js --name "echo"
should 'should app be online' 'online' 1
should 'should not have config variable' "config_var: 'false'" 0
$pm2 set echo.config_var false
exists 'should NOW have config variable' "config_var: 'false'"
$pm2 set echo.probes false
exists 'should NOW have config variable' "config_var: 'false'"
$pm2 delete all
#
#
#
#
$pm2 unset "probe-test"
$pm2 start probes.js --name "probe-test"
echo "Wait for init..."
sleep 1
exists 'probe test-probe exist' "test-probe"
exists 'probe Loop delay exist' "Loop delay"
exists 'probe Loop delay default value' "agg_type: 'avg', alert: {} }"
# Set new value for alert probe
$pm2 set probe-test.probes.Loop\ delay.value 25
sleep 1
exists 'probe Loop delay alerted' "alert: { mode: 'threshold', value: 25, cmp: '>' } } }"
# Override value for test-probe
$pm2 set probe-test.probes.test-probe.value 30
sleep 2
exists 'probe Loop delay alerted' "alert: { mode: 'threshold', value: 30, cmp: '>' } }"

View File

@ -72,3 +72,11 @@ function shouldnot {
[ $OUT -ne $3 ] || fail "$1"
success "$1"
}
function exists {
sleep 0.5
$pm2 prettylist > /tmp/tmp_out.txt
OUT=`cat /tmp/tmp_out.txt | grep -o "$2" | wc -l`
[ $OUT -ge 1 ] || fail "$1"
success "$1"
}

55
test/fixtures/probes.js vendored Normal file
View File

@ -0,0 +1,55 @@
var pmx = require('pmx');
var conf = pmx.init();
var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200);
res.end('hey');
}).listen(8000);
var Probe = pmx.probe();
var value_to_inspect = 0;
/**
* .metric, .counter, .meter, .histogram are also available (cf doc)
*/
var val = Probe.metric({
name : 'test-probe',
value : function() {
return value_to_inspect;
},
/**
* Here we set a default value threshold, to receive a notification
* These options can be overriden via Keymetrics or via pm2
* More: http://bit.ly/1O02aap
*/
alert : {
mode : 'threshold',
value : 20,
msg : 'test-probe alert!',
action : function(val) {
// Besides the automatic alert sent via Keymetrics
// You can also configure your own logic to do something
console.log('Value has reached %d', val);
}
}
});
setInterval(function() {
// Then we can see that this value increase over the time in Keymetrics
value_to_inspect++;
}, 30);
process.on('message', function(msg) {
if (msg == 'shutdown') {
console.log('Closing all connections...');
setTimeout(function() {
console.log('Finished closing connections');
process.exit(0);
}, 500);
}
});

View File

@ -21,8 +21,9 @@ echo "###################### !DEBUG! ###########################"
bash ./test/bash/file-descriptor.sh
spec "testing file descriptors"
bash ./test/bash/pmx_injection.sh
spec "automatic pmx injection"
# Automatic PMX http disabled
# bash ./test/bash/pmx_injection.sh
# spec "automatic pmx injection"
bash ./test/bash/log-timestamp.sh
spec "timetstamp prefix of pm2.log"
bash ./test/bash/smart-start.sh
@ -77,6 +78,8 @@ bash ./test/bash/vizion.sh
spec "vizion features (versioning control)"
bash ./test/bash/wrapped_fork.sh
spec "wrapped fork"
bash ./test/bash/app_configuration.sh
spec "App configuration"
bash ./test/bash/inside-pm2.sh
spec "Starting a process inside a PM2 process"