# HG changeset patch # User Paul Boddie # Date 1441915778 -7200 # Node ID ab2df0cbc65e1bb5f9df64d880cb52a96826672c # Parent a86a95af4a2742ece415b63031fc55ae248d3e9f Added a test of multiple simultaneous requests for a resource. diff -r a86a95af4a27 -r ab2df0cbc65e tests/next_time.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/next_time.py Thu Sep 10 22:09:38 2015 +0200 @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +""" +Increment the hour in a datetime string, wrapping round within any given range. +""" + +import sys + +try: + dt_str = sys.argv[1] + first, last = (sys.argv[2:4] + [None, None])[:2] +except (IndexError, ValueError): + sys.exit(1) + +if not dt_str: + sys.exit(1) + +try: + date_str = dt_str[:9] + hour = int(dt_str[9:11]) + min_sec_str = dt_str[11:] +except ValueError: + sys.exit(1) + +if not first: + first = 0 +else: + first = int(first) + +if not last: + last = 23 +else: + last = int(last) + +hour += 1 +if hour > last: + hour = first + +print '%s%02d%s' % (date_str, hour, min_sec_str) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a86a95af4a27 -r ab2df0cbc65e tests/resource_request.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/resource_request.sh Thu Sep 10 22:09:38 2015 +0200 @@ -0,0 +1,44 @@ +#!/bin/sh + +THIS_DIR=`dirname $0` + +TEMPLATES="$THIS_DIR/templates" +RESOURCE_SCRIPT="$THIS_DIR/../imip_resource.py" +SHOWMAIL="$THIS_DIR/../tools/showmail.py" +STORE=/tmp/store +STATIC=/tmp/static +PREFS=/tmp/prefs +ARGS="-S $STORE -P $STATIC -p $PREFS -d" + +ERROR=err.tmp + +export N=$1 +export START=20141126T090000 +export END=20141126T100000 +export SENDERADDRESS="person-$N@example.com" +export SENDER="mailto:person-$N@example.com" + +# Exit if a previous result indicates acceptance of a request. + + [ -e "outP${N}.tmp" ] \ +&& `grep 'PARTSTAT' "outP${N}.tmp" | grep -q 'ACCEPTED'` \ +&& exit 0 + +FBRESULT=$2 + +# Find the end of a busy period or use the initial start. + +FBSTART=`grep 'FREEBUSY' "$FBRESULT" | grep -v 'VFREEBUSY' | tail -n 1 | cut -d: -f2 | cut -d/ -f2 | tr -d '\\r'` +FBEND=`python "$THIS_DIR/next_time.py" "$FBSTART" 09 16` +START=${FBSTART:-$START} +END=${FBEND:-$END} + +echo "Try for $N with $START and $END..." + +# Request a resource on behalf of a numbered person identity. + + envsubst < "$TEMPLATES/event-request-group.txt" \ +| tee "inP${N}.tmp" \ +| "$RESOURCE_SCRIPT" $ARGS 2>> $ERROR \ +| "$SHOWMAIL" 2>> $ERROR \ +> "outP${N}.tmp" diff -r a86a95af4a27 -r ab2df0cbc65e tests/templates/event-request-group.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/templates/event-request-group.txt Thu Sep 10 22:09:38 2015 +0200 @@ -0,0 +1,34 @@ +Content-Type: multipart/alternative; boundary="===============0047278175==" +MIME-Version: 1.0 +From: $SENDERADDRESS +To: resource-room-confroom@example.com +Subject: Invitation! + +--===============0047278175== +Content-Type: text/plain; charset="us-ascii" +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit + +This message contains an event. +--===============0047278175== +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Content-Type: text/calendar; charset="us-ascii"; method="REQUEST" + +BEGIN:VCALENDAR +PRODID:-//imip-agent/test//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:$SENDER +ATTENDEE;ROLE=CHAIR:$SENDER +ATTENDEE;RSVP=TRUE:mailto:resource-room-confroom@example.com +DTSTAMP:20141125T004600Z +DTSTART;TZID=Europe/Oslo:$START +DTEND;TZID=Europe/Oslo:$END +SUMMARY:Meeting +UID:eventP${N}@example.com +END:VEVENT +END:VCALENDAR + +--===============0047278175==-- diff -r a86a95af4a27 -r ab2df0cbc65e tests/templates/fb-request-group.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/templates/fb-request-group.txt Thu Sep 10 22:09:38 2015 +0200 @@ -0,0 +1,31 @@ +Content-Type: multipart/alternative; boundary="===============0945993647==" +MIME-Version: 1.0 +From: $SENDERADDRESS +To: resource-room-confroom@example.com + +--===============0945993647== +Content-Type: text/plain; charset="us-ascii" +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit + +This message contains a free/busy request. +--===============0945993647== +Content-Type: text/calendar; charset="us-ascii"; method="REQUEST" +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit + +BEGIN:VCALENDAR +PRODID:-//imip-agent/test//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VFREEBUSY +ORGANIZER:$SENDER +ATTENDEE:mailto:resource-room-confroom@example.com +DTSTAMP:20141125T164400Z +DTSTART;TZID=Europe/Oslo:20141126T090000 +DTEND;TZID=Europe/Oslo:20141126T180000 +UID:fbP${N}@example.com +END:VFREEBUSY +END:VCALENDAR + +--===============0945993647==-- diff -r a86a95af4a27 -r ab2df0cbc65e tests/test_resource_invitation_group.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_resource_invitation_group.sh Thu Sep 10 22:09:38 2015 +0200 @@ -0,0 +1,76 @@ +#!/bin/sh + +THIS_DIR=`dirname $0` + +TEMPLATES="$THIS_DIR/templates" +RESOURCE_SCRIPT="$THIS_DIR/../imip_resource.py" +SHOWMAIL="$THIS_DIR/../tools/showmail.py" +STORE=/tmp/store +STATIC=/tmp/static +PREFS=/tmp/prefs +ARGS="-S $STORE -P $STATIC -p $PREFS -d" +USER="mailto:resource-room-confroom@example.com" + +ERROR=err.tmp + +rm -r $STORE +rm -r $STATIC +rm -r $PREFS +rm $ERROR +rm out*.tmp + +mkdir -p "$PREFS/$USER" +echo 'Europe/Oslo' > "$PREFS/$USER/TZID" +echo 'share' > "$PREFS/$USER/freebusy_sharing" + +for N in `seq 1 5` ; do + SENDER="mailto:person-$N@example.com" + mkdir -p "$PREFS/$SENDER" + echo 'Europe/Oslo' > "$PREFS/$SENDER/TZID" +done + + "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-all.txt" 2>> $ERROR \ +| "$SHOWMAIL" \ +> out0.tmp + + grep -q 'METHOD:REPLY' out0.tmp \ +&& ! grep -q '^FREEBUSY' out0.tmp \ +&& echo "Success" \ +|| echo "Failed" + + "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request.txt" 2>> $ERROR \ +| "$SHOWMAIL" \ +> out1.tmp + + grep -q 'METHOD:REPLY' out1.tmp \ +&& ! grep -q '^FREEBUSY' out1.tmp \ +&& echo "Success" \ +|| echo "Failed" + +# Loop until all requests have been satisfied. + +while [ ! -e outP1.tmp ] || [ `grep 'PARTSTAT' outP*.tmp | grep 'ACCEPTED' | wc -l` != '5' ] ; do + + # Request free/busy information. + + FBRESULT="outfbP.tmp" + export SENDER="mailto:person-N@example.com" + export SENDERADDRESS="person-N@example.com" + + envsubst < "$TEMPLATES/fb-request-group.txt" \ + | tee "infbP.tmp" \ + | "$RESOURCE_SCRIPT" $ARGS 2>> $ERROR \ + | "$SHOWMAIL" 2>> $ERROR \ + > "$FBRESULT" + + # Set the requesters on a race to book with this information. + + seq 1 5 | xargs -P0 -I{} "$THIS_DIR/resource_request.sh" {} "$FBRESULT" + wait + echo "Accepted: `grep 'ACCEPTED' outP*.tmp | wc -l`" + +done + + [ `grep 'PARTSTAT' outP*.tmp | grep 'ACCEPTED' | wc -l` = '5' ] \ +&& echo "Success" \ +|| echo "Failed"