Add basic daemon tests

This commit is contained in:
deajan 2016-11-17 23:40:17 +01:00
parent 2488b1ece7
commit 8314116c52
1 changed files with 55 additions and 10 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# osync test suite 2016111701 # osync test suite 2016111703
# 4 tests: # 4 tests:
# quicklocal # quicklocal
@ -22,11 +22,7 @@
# function test # function test
# WaitForTaskCompletion # WaitForTaskCompletion
# ParallelExec # ParallelExec
# daemon mode tests for both config files
# daemon mode tests
#TODO: daemon mode tests
#TODO: enable teardown after tests
LARGE_FILESET_URL="http://ftp.drupal.org/files/projects/drupal-8.1.9.tar.gz" LARGE_FILESET_URL="http://ftp.drupal.org/files/projects/drupal-8.1.9.tar.gz"
@ -77,8 +73,10 @@ osyncParameters[quickLocal]="--initiator=$INITIATOR_DIR --target=$TARGET_DIR --i
osyncParameters[quickRemote]="--initiator=$INITIATOR_DIR --target=ssh://localhost:$SSH_PORT/$TARGET_DIR --rsakey=${HOME}/.ssh/id_rsa_local --instance-id=quickremote" osyncParameters[quickRemote]="--initiator=$INITIATOR_DIR --target=ssh://localhost:$SSH_PORT/$TARGET_DIR --rsakey=${HOME}/.ssh/id_rsa_local --instance-id=quickremote"
osyncParameters[confLocal]="$CONF_DIR/$LOCAL_CONF" osyncParameters[confLocal]="$CONF_DIR/$LOCAL_CONF"
osyncParameters[confRemote]="$CONF_DIR/$REMOTE_CONF" osyncParameters[confRemote]="$CONF_DIR/$REMOTE_CONF"
#osyncParameters[daemonlocal]="$CONF_DIR/$LOCAL_CONF --on-changes"
#osyncParameters[daemonlocal]="$CONF_DIR/$REMOTE_CONF --on-changes" declare -Ag osyncDaemonParameters
osyncDaemonParameters[daemonlocal]="$CONF_DIR/$LOCAL_CONF --on-changes"
osyncDaemonParameters[daemonremote]="$CONF_DIR/$REMOTE_CONF --on-changes"
function GetConfFileValue () { function GetConfFileValue () {
local file="${1}" local file="${1}"
@ -182,7 +180,7 @@ function oneTimeTearDown () {
SetConfFileValue "$OSYNC_DIR/$OSYNC_EXECUTABLE" "IS_STABLE" "$OSYNC_IS_STABLE" SetConfFileValue "$OSYNC_DIR/$OSYNC_EXECUTABLE" "IS_STABLE" "$OSYNC_IS_STABLE"
#TODO: uncomment this when dev is done #TODO: uncomment this when dev is done
#rm -rf "$OSYNC_TESTS_DIR" rm -rf "$OSYNC_TESTS_DIR"
} }
function setUp () { function setUp () {
@ -868,7 +866,6 @@ function test_UpgradeConfRun () {
# Basic return code tests. Need to go deep into file presence testing # Basic return code tests. Need to go deep into file presence testing
cd "$OSYNC_DIR" cd "$OSYNC_DIR"
PrepareLocalDirs PrepareLocalDirs
# Make a security copy of the old config file # Make a security copy of the old config file
@ -883,5 +880,53 @@ function test_UpgradeConfRun () {
rm -f "$CONF_DIR/$TMP_OLD_CONF.save" rm -f "$CONF_DIR/$TMP_OLD_CONF.save"
} }
function test_DaemonMode () {
for i in "${osyncDaemonParameters[@]}"; do
cd "$OSYNC_DIR"
PrepareLocalDirs
FileA="FileA"
FileB="FileB"
FileC="FileC"
touch "$INITIATOR_DIR/$FileA"
touch "$TARGET_DIR/$FileB"
./$OSYNC_EXECUTABLE "$CONF_DIR/$LOCAL_CONF" --on-changes &
pid=$!
# Trivial value of 2xMIN_WAIT from config files
echo "Sleeping for 120s"
sleep 120
[ -f "$TARGET_DIR/$FileB" ]
assertEquals "File [$TARGET_DIR/$FileB] should be synced." "0" $?
[ -f "$INITIATOR_DIR/$FileA" ]
assertEquals "File [$INITIATOR_DIR/$FileB] should be synced." "0" $?
touch "$INITIATOR_DIR/$FileC"
rm -f "$INITIATOR_DIR/$FileA"
rm -f "$TARGET_DIR/$FileB"
echo "Sleeping for 120s"
sleep 120
[ ! -f "$TARGET_DIR/$FileB" ]
assertEquals "File [$TARGET_DIR/$FileB] should be deleted." "0" $?
[ ! -f "$INITIATOR_DIR/$FileA" ]
assertEquals "File [$INITIATOR_DIR/$FileA] should be deleted." "0" $?
[ -f "$TARGET_DIR/$OSYNC_DELETE_DIR/$FileA" ]
assertEquals "File [$TARGET_DIR/$OSYNC_DELETE_DIR/$FileA] should be in soft deletion dir." "0" $?
[ -f "$INITIATOR_DIR/$OSYNC_DELETE_DIR/$FileB" ]
assertEquals "File [$INITIATOR_DIR/$OSYNC_DELETE_DIR/$FileB] should be in soft deletion dir." "0" $?
[ -f "$TARGET_DIR/$FileC" ]
assertEquals "$File [$TARGET_DIR/$FileC] should be synced." "0" $?
kill $pid
done
}
. "$TESTS_DIR/shunit2/shunit2" . "$TESTS_DIR/shunit2/shunit2"