Browse Source

actually test results in shadow tests

Justin Tracey 1 year ago
parent
commit
2ff00b718f
2 changed files with 78 additions and 2 deletions
  1. 39 1
      shadow/client/run.sh
  2. 39 1
      shadow/peer/run.sh

+ 39 - 1
shadow/client/run.sh

@@ -1,4 +1,42 @@
-#!/bin/sh
+#!/bin/bash
 
 rm -rf shadow.data/
 shadow --template-directory shadow.data.template shadow.yaml > shadow.log
+
+declare -A groups
+groups[group1]="Alice Bob Carol"
+groups[group2]="Alice Bob Dave"
+
+ret=0
+
+check_instances() {
+    counts="$(grep -Ec "$1" shadow.data/hosts/*/*.stdout | cut -d: -f2 | sort -n)"
+    top=$(echo "$counts" | tail -1)
+    if [[ $top -lt $2 ]] ; then
+        echo "Not enough matches of pattern: $1"
+        ret=1
+    fi
+    if [[ $(echo "$counts" | tail -2 | head -1) -gt 0 ]] ; then
+        echo "Found matches of pattern in multiple logs: $1"
+        ret=1
+    fi
+}
+
+for group in ${!groups[@]} ; do
+    for name in ${groups[$group]} ; do
+        echo "$group,$name"
+        # user sent at least 10 messages to the group
+        check_instances "$name,$group,send," 10
+        # user got at least 10 receipts from the group
+        check_instances "$name,$group,receive,.*,receipt" 10
+        # user got at least 10 normal messages from the group
+        check_instances "$name,$group,receive,.*,[0-9]+" 10
+    done
+done
+
+if [ $ret == 0 ] ; then
+    echo "All tests passed."
+else
+    echo "At least one test failed."
+    exit $ret
+fi

+ 39 - 1
shadow/peer/run.sh

@@ -1,4 +1,42 @@
-#!/bin/sh
+#!/bin/bash
 
 rm -rf shadow.data/
 shadow --template-directory shadow.data.template shadow.yaml > shadow.log
+
+declare -A groups
+groups[group1]="Alice Bob Carol"
+groups[group2]="Alice Bob Dave"
+
+ret=0
+
+check_instances() {
+    counts="$(grep -Ec "$1" shadow.data/hosts/*/*.stdout | cut -d: -f2 | sort -n)"
+    top=$(echo "$counts" | tail -1)
+    if [[ $top -lt $2 ]] ; then
+        echo "Not enough matches of pattern: $1"
+        ret=1
+    fi
+    if [[ $(echo "$counts" | tail -2 | head -1) -gt 0 ]] ; then
+        echo "Found matches of pattern in multiple logs: $1"
+        ret=1
+    fi
+}
+
+for group in ${!groups[@]} ; do
+    for name in ${groups[$group]} ; do
+        echo "$group,$name"
+        # user sent at least 10 messages to the group
+        check_instances "$name,$group,send," 10
+        # user got at least 10 receipts from the group
+        check_instances "$name,$group,receive,.*,receipt" 10
+        # user got at least 10 normal messages from the group
+        check_instances "$name,$group,receive,.*,[0-9]+" 10
+    done
+done
+
+if [ $ret == 0 ] ; then
+    echo "All tests passed."
+else
+    echo "At least one test failed."
+    exit $ret
+fi