aboutsummaryrefslogtreecommitdiffstats
path: root/tests/sync-live-multi
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2019-11-09 03:13:45 +0100
committerGuilhem Moulin <guilhem@fripost.org>2019-11-13 06:23:56 +0100
commit67440844c422ee30b31df9a46a7f99ac0e833add (patch)
tree989381e5b94d5939dafdd1e99c7db2ada95355ec /tests/sync-live-multi
parentb9da6cc7ecf71026d1023dc3354b820c7518426e (diff)
Refactor and improve test suite.
Diffstat (limited to 'tests/sync-live-multi')
-rw-r--r--tests/sync-live-multi/interimap1.local1
-rw-r--r--tests/sync-live-multi/interimap2.local1
-rw-r--r--tests/sync-live-multi/interimap3.local1
-rw-r--r--tests/sync-live-multi/local.conf30
-rw-r--r--tests/sync-live-multi/remote1.conf3
-rw-r--r--tests/sync-live-multi/remote2.conf3
-rw-r--r--tests/sync-live-multi/remote3.conf3
-rw-r--r--tests/sync-live-multi/remotes1
-rw-r--r--tests/sync-live-multi/t127
9 files changed, 170 insertions, 0 deletions
diff --git a/tests/sync-live-multi/interimap1.local b/tests/sync-live-multi/interimap1.local
new file mode 100644
index 0000000..a013813
--- /dev/null
+++ b/tests/sync-live-multi/interimap1.local
@@ -0,0 +1 @@
+list-reference = foo/
diff --git a/tests/sync-live-multi/interimap2.local b/tests/sync-live-multi/interimap2.local
new file mode 100644
index 0000000..8f10633
--- /dev/null
+++ b/tests/sync-live-multi/interimap2.local
@@ -0,0 +1 @@
+list-reference = bar/
diff --git a/tests/sync-live-multi/interimap3.local b/tests/sync-live-multi/interimap3.local
new file mode 100644
index 0000000..31dee55
--- /dev/null
+++ b/tests/sync-live-multi/interimap3.local
@@ -0,0 +1 @@
+list-reference = baz/
diff --git a/tests/sync-live-multi/local.conf b/tests/sync-live-multi/local.conf
new file mode 100644
index 0000000..baae39d
--- /dev/null
+++ b/tests/sync-live-multi/local.conf
@@ -0,0 +1,30 @@
+namespace inbox {
+ separator = /
+ location = dbox:~/inbox:LAYOUT=index
+ inbox = yes
+ list = yes
+}
+
+namespace foo {
+ separator = /
+ prefix = foo/
+ location = dbox:~/foo:LAYOUT=index
+ inbox = no
+ list = yes
+}
+
+namespace bar {
+ separator = /
+ prefix = bar/
+ location = dbox:~/bar:LAYOUT=index
+ inbox = no
+ list = yes
+}
+
+namespace baz {
+ separator = /
+ prefix = baz/
+ location = dbox:~/baz:LAYOUT=index
+ inbox = no
+ list = yes
+}
diff --git a/tests/sync-live-multi/remote1.conf b/tests/sync-live-multi/remote1.conf
new file mode 100644
index 0000000..2d08a24
--- /dev/null
+++ b/tests/sync-live-multi/remote1.conf
@@ -0,0 +1,3 @@
+namespace inbox {
+ separator = ^
+}
diff --git a/tests/sync-live-multi/remote2.conf b/tests/sync-live-multi/remote2.conf
new file mode 100644
index 0000000..9657e89
--- /dev/null
+++ b/tests/sync-live-multi/remote2.conf
@@ -0,0 +1,3 @@
+namespace inbox {
+ separator = "\\"
+}
diff --git a/tests/sync-live-multi/remote3.conf b/tests/sync-live-multi/remote3.conf
new file mode 100644
index 0000000..0b6aafd
--- /dev/null
+++ b/tests/sync-live-multi/remote3.conf
@@ -0,0 +1,3 @@
+namespace inbox {
+ separator = "?"
+}
diff --git a/tests/sync-live-multi/remotes b/tests/sync-live-multi/remotes
new file mode 100644
index 0000000..00750ed
--- /dev/null
+++ b/tests/sync-live-multi/remotes
@@ -0,0 +1 @@
+3
diff --git a/tests/sync-live-multi/t b/tests/sync-live-multi/t
new file mode 100644
index 0000000..9b129ec
--- /dev/null
+++ b/tests/sync-live-multi/t
@@ -0,0 +1,127 @@
+TIMEOUT=60
+
+# mailbox list (as seen on local) and alphabet
+declare -a MAILBOXES=( "INBOX" ) ALPHABET=()
+str="#+-0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
+for ((i=0; i < ${#str}; i++)); do
+ ALPHABET[i]="${str:i:1}"
+done
+
+declare -a TARGETS=( "local" "remote1" "remote2" "remote3" )
+
+
+# create databases
+interimap_init "remote1"
+interimap_init "remote2"
+interimap_init "remote3"
+
+# start long-lived interimap processes
+declare -a PID=()
+trap 'ptree_abort ${PID[@]}' EXIT INT TERM
+interimap --config="config1" --watch=1 & PID+=( $! )
+interimap --config="config2" --watch=1 & PID+=( $! )
+interimap --config="config3" --watch=1 & PID+=( $! )
+
+timer=$(( $(date +%s) + TIMEOUT ))
+while [ $(date +%s) -le $timer ]; do
+ # create new mailbox with 10% probability
+ if [ $(shuf -n1 -i0-9) -eq 0 ]; then
+ u="$(shuf -n1 -e -- "${TARGETS[@]}")" # choose target at random
+ case "$u" in
+ local) ns="$(shuf -n1 -e "foo/" "bar/" "baz/")";;
+ remote1) ns="foo/";;
+ remote2) ns="bar/";;
+ remote3) ns="baz/";;
+ *) error "Uh?";;
+ esac
+
+ m=
+ d=$(shuf -n1 -i1-3) # random depth
+ for (( i=0; i < d; i++)); do
+ l=$(shuf -n1 -i1-16)
+ m="${m:+$m/}$(shuf -n "$l" -e -- "${ALPHABET[@]}" | tr -d '\n')"
+ done
+ MAILBOXES+=( "$ns$m" )
+ case "$u" in
+ local) m="$ns$m";;
+ remote1) m="${m//\//^}";;
+ remote2) m="${m//\//\\}";;
+ remote3) m="${m//\//\?}";;
+ *) error "Uh?";;
+ esac
+ doveadm -u "$u" mailbox create -- "$m"
+ fi
+
+ # EXPUNGE some messages
+ u="$(shuf -n1 -e -- "${TARGETS[@]}")" # choose target at random
+ n="$(shuf -n1 -i0-3)"
+ while read guid uid; do
+ doveadm -u "$u" expunge mailbox-guid "$guid" uid "$uid"
+ done < <(doveadm -u "$u" search all | shuf -n "$n")
+
+ # mark some existing messages as read (toggle \Seen flag as unlike other
+ # flags it's easier to query and check_mailboxes_status checks it)
+ u="$(shuf -n1 -e -- "${TARGETS[@]}")" # choose target at random
+ n="$(shuf -n1 -i0-9)"
+ while read guid uid; do
+ a="$(shuf -n1 -e add remove replace)"
+ doveadm -u "$u" flags "$a" "\\Seen" mailbox-guid "$guid" uid "$uid"
+ done < <(doveadm -u "$u" search all | shuf -n "$n")
+
+ # select at random a mailbox where to deliver some messages
+ u="$(shuf -n1 -e "local" "remote")" # choose target at random
+ m="$(shuf -n1 -e -- "${MAILBOXES[@]}")"
+ if [ "$u" = "remote" ]; then
+ case "$m" in
+ foo/*) u="remote1"; m="${m#foo/}"; m="${m//\//^}";;
+ bar/*) u="remote2"; m="${m#bar/}"; m="${m//\//\\}";;
+ baz/*) u="remote3"; m="${m#baz/}"; m="${m//\//\?}";;
+ INBOX) u="$(shuf -n1 -e "remote1" "remote2" "remote3")";;
+ *) error "Uh? $m";;
+ esac
+ fi
+
+ # deliver between 1 and 5 messages to the chosen mailbox
+ n="$(shuf -n1 -i1-5)"
+ for (( i=0; i < n; i++)); do
+ sample_message | deliver -u "$u" -- -m "$m"
+ done
+
+ # sleep a little bit (sometimes beyond --watch timer, sometimes not)
+ s=$(shuf -n1 -i1-1500)
+ [ $s -ge 1000 ] && s="$(printf "1.%03d" $((s-1000)))" || s="$(printf "0.%03d" $s)"
+ sleep "$s"
+done
+
+# wait a little longer so interimap has time to run loop() again and
+# synchronize outstanding changes, then terminate the processes we
+# started above
+sleep 2
+
+ptree_abort ${PID[@]}
+trap - EXIT INT TERM
+
+# check that the mailbox lists match
+diff -u --label="local/mailboxes" --label="remote1/mailboxes" \
+ <( doveadm -u "local" mailbox list | sed -n "s,^foo/,,p" | sort ) \
+ <( doveadm -u "remote1" mailbox list | tr '^' '/' | sort )
+diff -u --label="local/mailboxes" --label="remote2/mailboxes" \
+ <( doveadm -u "local" mailbox list | sed -n "s,^bar/,,p" | sort ) \
+ <( doveadm -u "remote2" mailbox list | tr '\\' '/' | sort )
+diff -u --label="local/mailboxes" --label="remote3/mailboxes" \
+ <( doveadm -u "local" mailbox list | sed -n "s,^baz/,,p" | sort ) \
+ <( doveadm -u "remote3" mailbox list | tr '?' '/' | sort )
+
+for m in "${MAILBOXES[@]}"; do
+ case "$m" in
+ foo/*) u="remote1"; mb="${m#foo/}"; mr="${mb//\//^}";;
+ bar/*) u="remote2"; mb="${m#bar/}"; mr="${mb//\//\\}";;
+ baz/*) u="remote3"; mb="${m#baz/}"; mr="${mb//\//\?}";;
+ INBOX) continue;;
+ *) error "Uh? $m";;
+ esac
+ blob="x'$(printf "%s" "$mb" | tr "/" "\\0" | xxd -c256 -ps)'"
+ check_mailbox_status2 "$blob" "$m" "$u" "$mr"
+done
+
+# vim: set filetype=sh :