Skip to content

Commit f69dae3

Browse files
committed
test_multiple_syncs.sh: verify sequential syncs change nothing
Test multiple dsyncs, and test dsync against rsync. 1. Running dsync twice, the second time no changes should be reported. 2. Running rsync followed by dsync, the dsync should report no changes. 3. Running dsync followed by rsync, the rsync should report no changes. rsync is run with -av -HAX to copy hard links, ACLs, and xattrs. However, the test data copied is created with dfilemaker, which does not create ACLs or xattrs, or named pipes, and may not create files with multiple hard links. This should be improved. Signed-off-by: Olaf Faaland <[email protected]>
1 parent 4409800 commit f69dae3

File tree

1 file changed

+194
-0
lines changed

1 file changed

+194
-0
lines changed
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#!/bin/bash
2+
3+
. utility/set_funcs.sh
4+
5+
##############################################################################
6+
# Description:
7+
#
8+
# Check sequential syncs for unexpected changes
9+
# - after dsync between src and dest, a second dsync copies nothing
10+
# - after rsync between src and dest, a dsync copies nothing
11+
# - after dsync between src and dest, a rsync copies nothing
12+
#
13+
# Notes:
14+
#
15+
##############################################################################
16+
17+
# Turn on verbose output
18+
#set -x
19+
20+
MFU_TEST_BIN=${MFU_TEST_BIN:-${1}}
21+
DSYNC_SRC_BASE=${DSYNC_SRC_BASE:-${2}}
22+
DSYNC_DEST_BASE=${DSYNC_DEST_BASE:-${3}}
23+
DSYNC_TREE_NAME=${DSYNC_TREE_NAME:-${4}}
24+
25+
rsync=$(which rsync 2>/dev/null)
26+
if [[ -z $rsync ]]; then
27+
echo "test_rsync.sh: unable to find rsync in path, exiting"
28+
exit 1
29+
fi
30+
31+
mpirun=$(which mpirun 2>/dev/null)
32+
mopts=""
33+
if [[ -n $mpirun ]]; then
34+
procs=$(( $(nproc ) / 8 ))
35+
if [[ $procs -gt 16 ]]; then
36+
procs=16
37+
fi
38+
mopts="-c $procs"
39+
40+
echo "Using mpirun: $mpirun $mopts"
41+
fi
42+
43+
echo "Using MFU binaries at: $MFU_TEST_BIN"
44+
echo "Using src parent directory at: $DSYNC_SRC_BASE"
45+
echo "Using dest parent directory at: $DSYNC_DEST_BASE"
46+
echo "Using rsync at: $rsync"
47+
48+
DSYNC_SRC=$(mktemp --directory ${DSYNC_SRC_BASE}/${DSYNC_TREE_NAME}.XXXXX)
49+
DSYNC_DEST=$(mktemp --directory ${DSYNC_DEST_BASE}/${DSYNC_TREE_NAME}.XXXXX)
50+
51+
function fs_type()
52+
{
53+
fname=$1
54+
df -T ${fname} | awk '$1 != "Filesystem" {print $2}'
55+
}
56+
57+
function list_all_files()
58+
{
59+
find $1 -printf '%P\n' | sort | grep -v '^$'
60+
}
61+
62+
function dsync_and_verify()
63+
{
64+
local src=$1
65+
local dest=$2
66+
local name=$3
67+
local expectation=$4
68+
69+
local rc=0
70+
local result=0
71+
local dest_type=""
72+
73+
dsync_output=$(mktemp /tmp/test_multiple_syncs.dsync_output.XXXXX)
74+
if [[ -n $mpirun ]]; then
75+
$mpirun $mopts ${MFU_TEST_BIN}/dsync --delete $src $dest > $dsync_output 2>&1
76+
else
77+
${MFU_TEST_BIN}/dsync --delete $src $dest > $dsync_output 2>&1
78+
fi
79+
rc=$?
80+
81+
if [[ $rc -ne 0 ]]; then
82+
echo "dsync failed with rc $rc"
83+
result=1
84+
fi
85+
86+
if [[ $expectation = "initial_sync" ]]; then
87+
rm $dsync_output
88+
return $result
89+
fi
90+
91+
unexpected_changes=$(mktemp /tmp/test_multiple_syncs.unexpected.XXXXX)
92+
if [[ $rc -eq 0 ]]; then
93+
grep -E -e "Creating [0-9][0-9]* (files|directories)" \
94+
-e "Copy data:" \
95+
-e "Updated [0-9][0-9]* items" \
96+
$dsync_output > $unexpected_changes
97+
if [[ $? -eq 0 ]]; then
98+
result=1
99+
fi
100+
fi
101+
102+
if [ "$result" -eq 0 ]; then
103+
echo "PASSED verify of option $name for $dest type $dest_type"
104+
else
105+
echo "FAILED verify of option $name for $dest type $dest_type"
106+
echo =======================
107+
echo "unexpected changes:"
108+
cat $unexpected_changes
109+
echo =======================
110+
fi
111+
112+
rm $dsync_output $unexpected_changes
113+
114+
return $result
115+
}
116+
117+
function rsync_and_verify()
118+
{
119+
local src=$1
120+
local dest=$2
121+
local name=$3
122+
local expectation=$4
123+
124+
local rc=0
125+
local result=0
126+
local dest_type=""
127+
128+
rsync_output=$(mktemp /tmp/test_multiple_syncs.rsync_output.XXXXX)
129+
$rsync -av -HAX $src $dest > $rsync_output 2>&1
130+
rc=$?
131+
132+
if [[ $rc -ne 0 ]]; then
133+
echo "rsync failed with rc $rc"
134+
result=1
135+
fi
136+
137+
if [[ $expectation = "initial_sync" ]]; then
138+
rm $rsync_output
139+
return $result
140+
fi
141+
142+
unexpected_changes=$(mktemp /tmp/test_multiple_syncs.unexpected.XXXXX)
143+
if [[ $rc -eq 0 ]]; then
144+
grep -v -e "^sending incremental" \
145+
-e "^sent [1-9][0-9,]* bytes" \
146+
-e "^total size is" \
147+
-e "^$" \
148+
$rsync_output > $unexpected_changes
149+
if [[ $? -eq 0 ]]; then
150+
result=1
151+
fi
152+
fi
153+
154+
if [ "$result" -eq 0 ]; then
155+
echo "PASSED verify of option $name for $dest type $dest_type"
156+
else
157+
echo "FAILED verify of option $name for $dest type $dest_type"
158+
echo =======================
159+
echo "unexpected changes:"
160+
cat $unexpected_changes
161+
echo =======================
162+
fi
163+
164+
rm $rsync_output $unexpected_changes
165+
166+
return $result
167+
}
168+
169+
# generate test data
170+
# dfilemaker options: -d/--depth , -s/--size, -n/--nitems
171+
rm -fr $DSYNC_SRC/stuff
172+
mkdir $DSYNC_SRC/stuff
173+
${MFU_TEST_BIN}/dfilemaker -d 5-10 -n 100-300 -s 1MB-10MB $DSYNC_SRC/stuff
174+
175+
# after dsync between src and dest, a second dsync copies nothing
176+
rm -fr $DSYNC_DEST/stuff
177+
dsync_and_verify $DSYNC_SRC/stuff $DSYNC_DEST/stuff multi-dsync initial_sync
178+
dsync_and_verify $DSYNC_SRC/stuff $DSYNC_DEST/stuff multi-dsync no_change
179+
180+
# after rsync between src and dest, a dsync copies nothing
181+
rm -fr $DSYNC_DEST/stuff
182+
rsync_and_verify $DSYNC_SRC/stuff/ $DSYNC_DEST/stuff rsync_then_dsync initial_sync
183+
dsync_and_verify $DSYNC_SRC/stuff $DSYNC_DEST/stuff rsync_then_dsync no_change
184+
185+
# after dsync between src and dest, a rsync copies nothing
186+
rm -fr $DSYNC_DEST/stuff
187+
dsync_and_verify $DSYNC_SRC/stuff $DSYNC_DEST/stuff dsync_then_rsync initial_sync
188+
rsync_and_verify $DSYNC_SRC/stuff/ $DSYNC_DEST/stuff dsync_then_rsync no_change
189+
190+
# clean up
191+
rm -fr $DSYNC_SRC/stuff
192+
rm -fr $DSYNC_DEST/stuff
193+
194+
exit 0

0 commit comments

Comments
 (0)