MXS-1220: Simplify test creation
The tests now automatically start MaxScale before each test block and stop it and perform cleanup after the test. This is done by simply calling the `before.sh` and `after.sh` scripts before each test block.
This commit is contained in:
38
server/core/test/rest-api/after.sh
Executable file
38
server/core/test/rest-api/after.sh
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# This script is run after each test block. It kills the MaxScale process
|
||||||
|
# and cleans up the directories that contain generated files.
|
||||||
|
#
|
||||||
|
|
||||||
|
test -z "$MAXSCALE_DIR" && exit 1
|
||||||
|
|
||||||
|
maxscaledir=$MAXSCALE_DIR
|
||||||
|
|
||||||
|
pid=`cat $maxscaledir/maxscale.pid`
|
||||||
|
echo $pid
|
||||||
|
|
||||||
|
for ((i=0;i<60;i++))
|
||||||
|
do
|
||||||
|
kill -0 $pid
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]
|
||||||
|
then
|
||||||
|
# Process is still up
|
||||||
|
kill $pid
|
||||||
|
|
||||||
|
if [ $i -gt 3 ]
|
||||||
|
then
|
||||||
|
sleep 0.1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
rm -r $maxscaledir/lib/maxscale
|
||||||
|
rm -r $maxscaledir/cache/maxscale
|
||||||
|
rm -r $maxscaledir/run/maxscale
|
||||||
|
mkdir -m 0755 -p $maxscaledir/lib/maxscale
|
||||||
|
mkdir -m 0755 -p $maxscaledir/cache/maxscale
|
||||||
|
mkdir -m 0755 -p $maxscaledir/run/maxscale
|
21
server/core/test/rest-api/before.sh
Executable file
21
server/core/test/rest-api/before.sh
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# This script is run before each test block. It starts MaxScale and waits for it
|
||||||
|
# to become responsive.
|
||||||
|
#
|
||||||
|
|
||||||
|
maxscaledir=$MAXSCALE_DIR
|
||||||
|
|
||||||
|
test -z "$MAXSCALE_DIR" && exit 1
|
||||||
|
|
||||||
|
# Start MaxScale
|
||||||
|
$maxscaledir/bin/maxscale -df $maxscaledir/maxscale.cnf >& $maxscaledir/maxscale.output &
|
||||||
|
pid=$!
|
||||||
|
|
||||||
|
# Wait for MaxScale to start
|
||||||
|
for ((i=0;i<60;i++))
|
||||||
|
do
|
||||||
|
$maxscaledir/bin/maxadmin help >& /dev/null && break
|
||||||
|
sleep 0.1
|
||||||
|
done
|
@ -4,7 +4,7 @@
|
|||||||
"repository": "https://github.com/mariadb-corporation/MaxScale",
|
"repository": "https://github.com/mariadb-corporation/MaxScale",
|
||||||
"description": "MaxScale REST API tests",
|
"description": "MaxScale REST API tests",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha"
|
"test": "mocha --timeout 60000 --slow 10000"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "SEE LICENSE IN ../../../../LICENSE.txt",
|
"license": "SEE LICENSE IN ../../../../LICENSE.txt",
|
||||||
|
@ -50,24 +50,12 @@ chmod 0755 $maxscaledir/lib/maxscale
|
|||||||
chmod 0755 $maxscaledir/cache/maxscale
|
chmod 0755 $maxscaledir/cache/maxscale
|
||||||
chmod 0755 $maxscaledir/run/maxscale
|
chmod 0755 $maxscaledir/run/maxscale
|
||||||
|
|
||||||
# Start MaxScale
|
# This variable is used to start and stop MaxScale before each test
|
||||||
$maxscaledir/bin/maxscale -df $maxscaledir/maxscale.cnf >& $maxscaledir/maxscale.output &
|
export MAXSCALE_DIR=$maxscaledir
|
||||||
pid=$!
|
|
||||||
|
|
||||||
# Wait for MaxScale to start
|
|
||||||
for ((i=0;i<60;i++))
|
|
||||||
do
|
|
||||||
$maxscaledir/bin/maxadmin help >& /dev/null && break
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
|
|
||||||
# Run tests
|
# Run tests
|
||||||
cd $testdir
|
cd $testdir
|
||||||
npm test
|
npm test
|
||||||
rval=$?
|
rval=$?
|
||||||
|
|
||||||
# Stop MaxScale
|
|
||||||
kill $pid
|
|
||||||
wait
|
|
||||||
|
|
||||||
exit $rval
|
exit $rval
|
||||||
|
@ -405,6 +405,8 @@ function validate_json(data) {
|
|||||||
return validate_func(JSON.parse(data))
|
return validate_func(JSON.parse(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var child_process = require("child_process")
|
||||||
|
|
||||||
module.exports = function() {
|
module.exports = function() {
|
||||||
this.fs = require("fs")
|
this.fs = require("fs")
|
||||||
this.request = require("request-promise-native")
|
this.request = require("request-promise-native")
|
||||||
@ -419,4 +421,18 @@ module.exports = function() {
|
|||||||
this.validate_func = ajv.compile(json_api_schema)
|
this.validate_func = ajv.compile(json_api_schema)
|
||||||
this.validate = validate_json
|
this.validate = validate_json
|
||||||
this.base_url = "http://localhost:8989/v1"
|
this.base_url = "http://localhost:8989/v1"
|
||||||
|
this.before(function(done) {
|
||||||
|
child_process.execFile("./before.sh", function(err, stdout, stderr) {
|
||||||
|
if (process.env.MAXSCALE_DIR == null) {
|
||||||
|
throw new Error("MAXSCALE_DIR is not set");
|
||||||
|
}
|
||||||
|
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
});
|
||||||
|
this.after(function(done) {
|
||||||
|
child_process.execFile("./after.sh", function(err, stdout, stderr) {
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user