aboutsummaryrefslogtreecommitdiffstats
path: root/tests/sync-live
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2019-11-13 06:24:07 +0100
committerGuilhem Moulin <guilhem@fripost.org>2019-11-13 06:24:07 +0100
commitc6bbdd8aa697b2d42be1ac0839189da32d437a8f (patch)
treecd1b8d19d99557fbebe33344d0d23f6ac826da57 /tests/sync-live
parent87d947df1b837514a0f1efa3bc36b58088bd2564 (diff)
parentdac4ab1c9306bf2035bc1547d2ed27ab09850120 (diff)
Merge branch 'master' into debian
Diffstat (limited to 'tests/sync-live')
-rw-r--r--tests/sync-live/local.conf3
-rw-r--r--tests/sync-live/remote.conf3
-rw-r--r--tests/sync-live/t76
3 files changed, 82 insertions, 0 deletions
diff --git a/tests/sync-live/local.conf b/tests/sync-live/local.conf
new file mode 100644
index 0000000..b56cc70
--- /dev/null
+++ b/tests/sync-live/local.conf
@@ -0,0 +1,3 @@
+namespace inbox {
+ separator = .
+}
diff --git a/tests/sync-live/remote.conf b/tests/sync-live/remote.conf
new file mode 100644
index 0000000..2d08a24
--- /dev/null
+++ b/tests/sync-live/remote.conf
@@ -0,0 +1,3 @@
+namespace inbox {
+ separator = ^
+}
diff --git a/tests/sync-live/t b/tests/sync-live/t
new file mode 100644
index 0000000..19d1e08
--- /dev/null
+++ b/tests/sync-live/t
@@ -0,0 +1,76 @@
+TIMEOUT=60
+
+# mailbox list and alphabet (exclude &, / and ~, which dovecot treats specially)
+declare -a MAILBOXES=( "INBOX" ) ALPHABET=()
+str="!\"#\$'()+,-0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]_\`abcdefghijklmnopqrstuvwxyz{|}"
+for ((i=0; i < ${#str}; i++)); do
+ ALPHABET[i]="${str:i:1}"
+done
+
+interimap_init
+
+# start a long-lived interimap process
+interimap --watch=1 & PID=$!
+trap "ptree_abort $PID" EXIT INT TERM
+
+timer=$(( $(date +%s) + TIMEOUT ))
+while [ $(date +%s) -le $timer ]; do
+ # create new mailbox with 10% probability
+ if [ $(shuf -n1 -i0-9) -eq 0 ]; then
+ 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+=( "$m" )
+ u="$(shuf -n1 -e "local" "remote")" # choose target at random
+ [ "$u" = "local" ] || m="${m//./^}"
+ doveadm -u "$u" mailbox create -- "$m"
+ fi
+
+ # EXPUNGE some messages
+ u="$(shuf -n1 -e "local" "remote")" # 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 "local" "remote")" # 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[@]}")"
+ [ "$u" = "local" ] || m="${m//./^}"
+
+ # 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 process we started
+# above
+sleep 2
+
+ptree_abort $PID
+trap - EXIT INT TERM
+
+check_mailbox_list
+check_mailboxes_status "${MAILBOXES[@]}"
+
+# vim: set filetype=sh :