2016-09-05 20:21:25 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2016-09-05 20:25:25 +00:00
|
|
|
# osync test suite 2016090502
|
2016-09-05 20:21:25 +00:00
|
|
|
# TODO: Add big fileset tests (eg: drupal 8 ?), add soft deletion tests, add deletion propagation test, add file attrib test
|
|
|
|
|
|
|
|
|
|
|
|
OSYNC_DIR="$(pwd)"
|
|
|
|
OSYNC_DIR=${OSYNC_DIR%%/dev*}
|
|
|
|
DEV_DIR="$OSYNC_DIR/dev"
|
|
|
|
TESTS_DIR="$DEV_DIR/tests"
|
|
|
|
|
|
|
|
OSYNC_EXECUTABLE="osync.sh"
|
|
|
|
|
|
|
|
if [ "$TRAVIS_RUN" == true ]; then
|
|
|
|
echo "Running with travis settings"
|
|
|
|
CONF_DIR="$TESTS_DIR/conf-travis"
|
|
|
|
SSH_PORT=22
|
|
|
|
else
|
|
|
|
echo "Running with local settings"
|
|
|
|
CONF_DIR="$TESTS_DIR/conf-local"
|
|
|
|
SSH_PORT=49999
|
|
|
|
fi
|
|
|
|
|
|
|
|
INITIATOR_DIR="${HOME}/osync/initiator"
|
|
|
|
TARGET_DIR="${HOME}/osync/target"
|
|
|
|
OSYNC_STATE_DIR=".osync_workdir/state"
|
|
|
|
|
|
|
|
function SetStableToYes () {
|
|
|
|
if grep "^IS_STABLE=YES" "$OSYNC_DIR/$OSYNC_EXECUTABLE" > /dev/null; then
|
|
|
|
IS_STABLE=yes
|
|
|
|
else
|
|
|
|
IS_STABLE=no
|
|
|
|
sed -i.tmp 's/^IS_STABLE=no/IS_STABLE=yes/' "$OSYNC_DIR/$OSYNC_EXECUTABLE"
|
|
|
|
assertEquals "Set stable to yes" "0" $?
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function SetStableToOrigin () {
|
|
|
|
if [ "$IS_STABLE" == "no" ]; then
|
|
|
|
sed -i.tmp 's/^IS_STABLE=yes/IS_STABLE=no/' "$OSYNC_DIR/$OSYNC_EXECUTABLE"
|
|
|
|
assertEquals "Set stable to origin value" "0" $?
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function SetupSSH {
|
|
|
|
echo -e 'y\n'| ssh-keygen -t rsa -b 2048 -N "" -f "${HOME}/.ssh/id_rsa_local"
|
|
|
|
cat "${HOME}/.ssh/id_rsa_local.pub" >> "${HOME}/.ssh/authorized_keys"
|
|
|
|
chmod 600 "${HOME}/.ssh/authorized_keys"
|
|
|
|
|
|
|
|
# Add localhost to known hosts so self connect works
|
|
|
|
if [ -z $(ssh-keygen -F localhost) ]; then
|
|
|
|
ssh-keyscan -H localhost >> ~/.ssh/known_hosts
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-09-05 20:25:25 +00:00
|
|
|
function setUp () {
|
2016-09-05 20:21:25 +00:00
|
|
|
if [ -d "$INITIATOR_DIR" ]; then
|
|
|
|
rm -rf "$INITIATOR_DIR"
|
|
|
|
fi
|
|
|
|
mkdir -p "$INITIATOR_DIR"
|
|
|
|
|
|
|
|
if [ -d "$TARGET_DIR" ]; then
|
|
|
|
rm -rf "$TARGET_DIR"
|
|
|
|
fi
|
|
|
|
mkdir -p "$TARGET_DIR"
|
|
|
|
}
|
|
|
|
|
2016-09-05 20:25:25 +00:00
|
|
|
function oneTimeSetUp () {
|
|
|
|
source "$DEV_DIR/ofunctions.sh"
|
|
|
|
SetupSSH
|
|
|
|
}
|
|
|
|
|
|
|
|
function oneTimeTearDown () {
|
|
|
|
SetStableToOrigin
|
|
|
|
}
|
|
|
|
|
2016-09-05 20:21:25 +00:00
|
|
|
function test_Merge () {
|
|
|
|
cd "$DEV_DIR"
|
|
|
|
./merge.sh
|
|
|
|
assertEquals "Merging code" "0" $?
|
|
|
|
SetStableToYes
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_osync_quicksync_local () {
|
|
|
|
cd "$OSYNC_DIR"
|
|
|
|
./$OSYNC_EXECUTABLE --initiator="$INITIATOR_DIR" --target="$TARGET_DIR"
|
|
|
|
assertEquals "Return code" "0" $?
|
|
|
|
|
|
|
|
[ -d "$INITIATOR_DIR/$OSYNC_STATE_DIR" ]
|
|
|
|
assertEquals "Initiator state dir exists" "0" $?
|
|
|
|
|
|
|
|
[ -d "$TARGET_DIR/$OSYNC_STATE_DIR" ]
|
|
|
|
assertEquals "Target state dir exists" "0" $?
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function test_osync_quicksync_remote () {
|
|
|
|
cd "$OSYNC_DIR"
|
2016-09-05 20:25:25 +00:00
|
|
|
./$OSYNC_EXECUTABLE --initiator="$INITIATOR_DIR" --target="ssh://localhost:$SSH_PORT/$TARGET_DIR" --rsakey="${HOME}/.ssh/id_rsa_local"
|
2016-09-05 20:21:25 +00:00
|
|
|
assertEquals "Return code" "0" $?
|
|
|
|
|
|
|
|
[ -d "$INITIATOR_DIR/$OSYNC_STATE_DIR" ]
|
|
|
|
assertEquals "Initiator state dir exists" "0" $?
|
|
|
|
|
|
|
|
[ -d "$TARGET_DIR/$OSYNC_STATE_DIR" ]
|
|
|
|
assertEquals "Target state dir exists" "0" $?
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_WaitForTaskCompletion () {
|
|
|
|
# Tests if wait for task completion works correctly
|
|
|
|
|
|
|
|
# Standard wait
|
|
|
|
sleep 1 &
|
|
|
|
pids="$!"
|
|
|
|
sleep 2 &
|
|
|
|
pids="$pids;$!"
|
|
|
|
WaitForTaskCompletion $pids 0 0 ${FUNCNAME[0]} true 0
|
|
|
|
assertEquals "WaitForTaskCompletion test 1" "0" $?
|
|
|
|
|
|
|
|
# Standard wait with warning
|
|
|
|
sleep 2 &
|
|
|
|
pids="$!"
|
|
|
|
sleep 5 &
|
|
|
|
pids="$pids;$!"
|
|
|
|
|
|
|
|
WaitForTaskCompletion $pids 3 0 ${FUNCNAME[0]} true 0
|
|
|
|
assertEquals "WaitForTaskCompletion test 2" "0" $?
|
|
|
|
|
|
|
|
# Both pids are killed
|
|
|
|
sleep 5 &
|
|
|
|
pids="$!"
|
|
|
|
sleep 5 &
|
|
|
|
pids="$pids;$!"
|
|
|
|
|
|
|
|
WaitForTaskCompletion $pids 0 2 ${FUNCNAME[0]} true 0
|
|
|
|
assertEquals "WaitForTaskCompletion test 3" "2" $?
|
|
|
|
|
|
|
|
# One of two pids are killed
|
|
|
|
sleep 2 &
|
|
|
|
pids="$!"
|
|
|
|
sleep 10 &
|
|
|
|
pids="$pids;$!"
|
|
|
|
|
|
|
|
WaitForTaskCompletion $pids 0 3 ${FUNCNAME[0]} true 0
|
|
|
|
assertEquals "WaitForTaskCompletion test 4" "1" $?
|
|
|
|
|
|
|
|
# Count since script begin, the following should output two warnings and both pids should get killed
|
|
|
|
sleep 20 &
|
|
|
|
pids="$!"
|
|
|
|
sleep 20 &
|
|
|
|
pids="$pids;$!"
|
|
|
|
|
|
|
|
WaitForTaskCompletion $pids 3 5 ${FUNCNAME[0]} false 0
|
|
|
|
assertEquals "WaitForTaskCompletion test 5" "2" $?
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_ParallelExec () {
|
|
|
|
# Test if parallelExec works correctly
|
|
|
|
|
|
|
|
cmd="sleep 2;sleep 2;sleep 2;sleep 2"
|
|
|
|
ParallelExec 4 "$cmd"
|
|
|
|
assertEquals "ParallelExec test 1" "0" $?
|
|
|
|
|
|
|
|
cmd="sleep 2;du /none;sleep 2"
|
|
|
|
ParallelExec 2 "$cmd"
|
|
|
|
assertEquals "ParallelExec test 2" "1" $?
|
|
|
|
|
|
|
|
cmd="sleep 4;du /none;sleep 3;du /none;sleep 2"
|
|
|
|
ParallelExec 3 "$cmd"
|
|
|
|
assertEquals "ParallelExec test 3" "2" $?
|
|
|
|
}
|
|
|
|
|
|
|
|
. "$TESTS_DIR/shunit2/shunit2"
|