2013-07-22 08:25:02 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Tests for MeshMS Messaging
|
|
|
|
#
|
|
|
|
# Copyright 2012 Serval Project, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
source "${0%/*}/../testframework.sh"
|
|
|
|
source "${0%/*}/../testdefs.sh"
|
|
|
|
source "${0%/*}/../testdefs_rhizome.sh"
|
|
|
|
|
2013-07-25 05:19:06 +00:00
|
|
|
teardown() {
|
|
|
|
stop_all_servald_servers
|
|
|
|
kill_all_servald_processes
|
|
|
|
assert_no_servald_processes
|
2013-07-22 08:25:02 +00:00
|
|
|
}
|
|
|
|
|
2013-07-26 05:06:11 +00:00
|
|
|
doc_MessageDelivery="Send messages, ack and read them in a 2 party conversation"
|
2013-07-25 05:19:06 +00:00
|
|
|
setup_MessageDelivery() {
|
2013-07-22 08:25:02 +00:00
|
|
|
setup_servald
|
|
|
|
set_instance +A
|
|
|
|
create_identities 2
|
|
|
|
executeOk_servald config \
|
|
|
|
set debug.meshms on \
|
2013-07-26 05:06:11 +00:00
|
|
|
set debug.rhizome on \
|
2013-07-22 08:25:02 +00:00
|
|
|
set log.console.level debug
|
|
|
|
}
|
2013-07-25 05:19:06 +00:00
|
|
|
test_MessageDelivery() {
|
2013-07-23 04:51:46 +00:00
|
|
|
# 1. empty list
|
2013-07-22 08:25:02 +00:00
|
|
|
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
2013-08-02 04:32:56 +00:00
|
|
|
assertStdoutIs --stdout --line=1 -e '4\n'
|
|
|
|
assertStdoutIs --stdout --line=2 -e '_id:offset:type:message\n'
|
2013-07-22 08:25:02 +00:00
|
|
|
assertStdoutLineCount '==' 2
|
2013-07-23 04:51:46 +00:00
|
|
|
# 2. create a manifest with a single message and list it back
|
2013-07-22 08:25:02 +00:00
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA2 "Hi"
|
|
|
|
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
2013-08-02 04:32:56 +00:00
|
|
|
assertStdoutGrep --stdout --matches=1 ":>:Hi\$"
|
2013-07-22 08:25:02 +00:00
|
|
|
assertStdoutLineCount '==' 3
|
2013-07-23 04:51:46 +00:00
|
|
|
# 3. append a second message and list them both
|
2013-07-22 08:25:02 +00:00
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA2 "How are you"
|
|
|
|
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
2013-08-02 04:32:56 +00:00
|
|
|
assertStdoutGrep --stdout --matches=1 ":>:How are you\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 ":>:Hi\$"
|
2013-07-22 08:25:02 +00:00
|
|
|
assertStdoutLineCount '==' 4
|
2013-07-23 04:51:46 +00:00
|
|
|
# 4. list the messages from the receivers point of view (which ACKs them)
|
2013-07-22 08:25:02 +00:00
|
|
|
executeOk_servald meshms list messages $SIDA2 $SIDA1
|
2013-08-02 04:32:56 +00:00
|
|
|
assertStdoutGrep --stdout --matches=1 "^0:19:<:How are you\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^1:5:<:Hi\$"
|
2013-07-22 08:25:02 +00:00
|
|
|
assertStdoutLineCount '==' 4
|
2013-07-26 05:06:11 +00:00
|
|
|
# 5. mark the first message as read
|
|
|
|
executeOk_servald meshms read messages $SIDA2 $SIDA1 5
|
|
|
|
executeOk_servald meshms list messages $SIDA2 $SIDA1
|
2013-08-02 04:32:56 +00:00
|
|
|
assertStdoutGrep --stdout --matches=1 "^0:19:<:How are you\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^1:5:MARK:read\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^2:5:<:Hi\$"
|
|
|
|
assertStdoutLineCount '==' 5
|
2013-07-26 05:06:11 +00:00
|
|
|
# 6. mark all messages as read
|
|
|
|
executeOk_servald meshms read messages $SIDA2
|
|
|
|
executeOk_servald meshms list messages $SIDA2 $SIDA1
|
2013-08-02 04:32:56 +00:00
|
|
|
assertStdoutGrep --stdout --matches=1 "^0:19:MARK:read\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^1:19:<:How are you\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^2:5:<:Hi\$"
|
|
|
|
assertStdoutLineCount '==' 5
|
2013-07-26 05:06:11 +00:00
|
|
|
# 7. list messages from the senders point of view after they have been delivered
|
2013-07-23 04:51:46 +00:00
|
|
|
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
2013-08-02 04:32:56 +00:00
|
|
|
assertStdoutGrep --stdout --matches=1 "^0:3:ACK:delivered\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^1:19:>:How are you\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^2:5:>:Hi\$"
|
|
|
|
assertStdoutLineCount '==' 5
|
2013-07-25 05:19:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_MessageThreading="Messages sent at the same time, thread differently"
|
|
|
|
setup_MessageThreading() {
|
|
|
|
setup_servald
|
|
|
|
foreach_instance +A +B create_single_identity
|
|
|
|
set_instance +A
|
|
|
|
executeOk_servald meshms send message $SIDA $SIDB "Hello can you hear me"
|
|
|
|
executeOk_servald meshms send message $SIDA $SIDB "Still waiting"
|
|
|
|
set_instance +B
|
|
|
|
executeOk_servald meshms send message $SIDB $SIDA "Help Im trapped in a test case factory"
|
|
|
|
executeOk_servald meshms send message $SIDB $SIDA "Never mind"
|
|
|
|
start_servald_instances +A +B
|
|
|
|
}
|
|
|
|
|
2013-07-26 05:06:11 +00:00
|
|
|
has_unread_messages() {
|
|
|
|
executeOk_servald meshms list conversations $1
|
2013-07-30 06:56:01 +00:00
|
|
|
if ! grep ":unread:" $_tfw_tmp/stdout; then
|
2013-07-26 05:06:11 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-07-26 05:10:06 +00:00
|
|
|
messages_delivered() {
|
|
|
|
executeOk_servald meshms list messages $1 $2
|
2013-08-02 04:32:56 +00:00
|
|
|
if ! grep ":ACK:" $_tfw_tmp/stdout; then
|
2013-07-26 05:10:06 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-07-26 05:06:11 +00:00
|
|
|
test_MessageThreading() {
|
2013-07-25 05:19:06 +00:00
|
|
|
set_instance +B
|
2013-07-26 05:06:11 +00:00
|
|
|
wait_until has_unread_messages $SIDB
|
2013-07-25 05:19:06 +00:00
|
|
|
executeOk_servald meshms list messages $SIDB $SIDA
|
2013-08-02 04:32:56 +00:00
|
|
|
assertStdoutGrep --stdout --matches=1 "^0:40:<:Still waiting\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^1:24:<:Hello can you hear me\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^2:54:>:Never mind\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^3:41:>:Help Im trapped in a test case factory\$"
|
2013-07-25 05:19:06 +00:00
|
|
|
assertStdoutLineCount '==' 6
|
|
|
|
|
|
|
|
set_instance +A
|
2013-07-26 05:06:11 +00:00
|
|
|
wait_until has_unread_messages $SIDA
|
2013-07-26 05:10:06 +00:00
|
|
|
wait_until messages_delivered $SIDA $SIDB
|
2013-07-25 05:19:06 +00:00
|
|
|
executeOk_servald meshms list messages $SIDA $SIDB
|
2013-08-02 04:32:56 +00:00
|
|
|
assertStdoutGrep --stdout --matches=1 "^0:54:<:Never mind\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^1:41:<:Help Im trapped in a test case factory\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^2:57:ACK:delivered\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^3:40:>:Still waiting\$"
|
|
|
|
assertStdoutGrep --stdout --matches=1 "^4:24:>:Hello can you hear me\$"
|
|
|
|
assertStdoutLineCount '==' 7
|
2013-07-25 05:19:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_listConversations="List multiple conversations, with different numbers of messages"
|
|
|
|
setup_listConversations() {
|
|
|
|
setup_servald
|
|
|
|
set_instance +A
|
|
|
|
create_identities 5
|
|
|
|
executeOk_servald config \
|
|
|
|
set debug.rhizome on \
|
|
|
|
set debug.meshms on \
|
|
|
|
set log.console.level debug
|
2013-07-26 05:43:22 +00:00
|
|
|
# create 3 threads, with all permutations of incoming and outgoing messages
|
2013-07-25 05:19:06 +00:00
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA2 "Message1"
|
|
|
|
executeOk_servald meshms send message $SIDA3 $SIDA1 "Message2"
|
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA4 "Message3"
|
|
|
|
executeOk_servald meshms send message $SIDA4 $SIDA1 "Message4"
|
|
|
|
}
|
|
|
|
test_listConversations() {
|
|
|
|
executeOk_servald meshms list conversations $SIDA1
|
2013-07-30 06:56:01 +00:00
|
|
|
tfw_cat --stdout
|
|
|
|
assertStdoutIs --stderr --line=1 -e '5\n'
|
|
|
|
assertStdoutIs --stderr --line=2 -e '_id:recipient:read:last_message:read_offset\n'
|
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA2::0:0\$"
|
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA3:unread:11:0\$"
|
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA4:unread:14:0\$"
|
2013-07-25 05:19:06 +00:00
|
|
|
assertStdoutLineCount '==' 5
|
|
|
|
executeOk_servald meshms list conversations $SIDA1 1
|
2013-07-26 05:43:22 +00:00
|
|
|
tfw_cat --stderr
|
2013-07-25 05:19:06 +00:00
|
|
|
assertStdoutLineCount '==' 4
|
|
|
|
executeOk_servald meshms list conversations $SIDA1 1 1
|
2013-07-26 05:43:22 +00:00
|
|
|
tfw_cat --stderr
|
2013-07-25 05:19:06 +00:00
|
|
|
assertStdoutLineCount '==' 3
|
2013-07-26 05:43:22 +00:00
|
|
|
# mark all incoming messages as read
|
|
|
|
executeOk_servald meshms read messages $SIDA1
|
|
|
|
tfw_cat --stderr
|
|
|
|
executeOk_servald meshms list conversations $SIDA1
|
2013-07-30 06:56:01 +00:00
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA2::0:0\$"
|
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA3::11:11\$"
|
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA4::14:14\$"
|
2013-07-26 05:43:22 +00:00
|
|
|
assertStdoutLineCount '==' 5
|
2013-07-22 08:25:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
runTests "$@"
|