forked from Kitura/Kitura-WebSocket-NIO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.autobahn.sh
executable file
·107 lines (86 loc) · 3.02 KB
/
.autobahn.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# A script that runs swift test followed by the autobahn test suite.
# Generate the fuzzingclient.json file for the given tests
fuzzing_client() {
TESTS=$1
echo "{\"outdir\": \"./reports/servers\", \"servers\": [{ \"url\": \"ws://127.0.0.1:9001\" }], \"cases\": [$TESTS],\"exclude-cases\": []}" > fuzzingclient.json
}
# Launch the WebSocket service and run a subset of Autobahn tests. On failures or unclean closures, exit with a non-zero code.
run_autobahn()
{
# The first argument holds the lists of tests to be run
TESTS=$1
NTESTS=$2
if [ `uname` == "Linux" ]; then
PLATFORM_SUBDIR="x86_64-unknown-linux"
else
PLATFORM_SUBDIR="x86_64-apple-macosx"
fi
# Launch the TestWebSocketService, save its pid
./.build/$PLATFORM_SUBDIR/release/TestWebSocketService &
PID=$!
# Make sure the server has enough time to be up and running
sleep 5
# Generate the fuzzingclient.json
fuzzing_client $TESTS
# Run the autobahn fuzzingclient
wstest -m fuzzingclient
# Count the total number of tests that executed
TOTAL_TESTS=`grep behaviorClose reports/servers/index.json | wc -l`
echo "Executed $TOTAL_TESTS out of $NTESTS tests"
# Check if all tests completed
if [ $TOTAL_TESTS -ne $NTESTS ]; then
echo "All of the configured tests were not executed, possibly because the server wasn't available."
exit 1
fi
# Count the number of failed tests or unclean connection closures
FAILED_OR_UNCLEAN=`grep behavior reports/servers/index.json | cut -d':' -f2 | cut -d'"' -f2 | sort -u | xargs | grep -E "FAILED|UNCLEAN" | wc -l`
if [ $FAILED_OR_UNCLEAN -ne "0" ]; then
echo "$FAILED_OR_UNCLEAN out of $NTESTS tests failed or resulted in unclean connection closures."
exit 1
fi
# Kill the service
kill $PID
# Remove the reports and the generated json file
rm -rf reports fuzzingclient.json
}
install_autobahn() {
if [ `uname` == "Linux" ]; then
apt-get update \
&& apt-get -y upgrade \
&& apt-get -y install sudo \
&& sudo apt-get -y install python-pip \
&& pip install --upgrade pip \
&& pip install autobahntestsuite
else
pip install --upgrade pip
pip install autobahntestsuite
fi
}
# Run swift test
travis_start "swift_test"
swift test
SWIFT_TEST_STATUS=$?
travis_end
if [ $SWIFT_TEST_STATUS -ne 0 ]; then
return $SWIFT_TEST_STATUS
fi
# Build TestWebSocketService
echo "Building in release mode for autobahn testing"
travis_start "swift_build"
swift build -c release
travis_end
# Install python, pip and autobahn
travis_start "autobahn_install"
install_autobahn
travis_end
travis_start "autobahn_run"
# Run tests 1-4
run_autobahn \"1.*\",\"2.*\",\"3.*\",\"4.*\" 44
# Run tests 5-8
run_autobahn \"5.*\",\"6.*\",\"7.*\",\"8.*\" 202
# Run tests 9-10
run_autobahn \"9.*\",\"10.*\" 55
# Run tests 12-13, disabled due to a hang that happens only in the CI
# run_autobahn \"12.*\",\"13.*\"
travis_end
# All tests have passed