blob: cf6609934ba97941eb3ef27c1b702ab9386e1532 [file] [log] [blame]
Roger Meier8909cbd2014-01-26 11:44:27 +01001#! /bin/sh
2
jfarrelldabdf652014-10-08 23:41:47 -04003
Roger Meier8909cbd2014-01-26 11:44:27 +01004# Licensed to the Apache Software Foundation (ASF) under one
5# or more contributor license agreements. See the NOTICE file
6# distributed with this work for additional information
7# regarding copyright ownership. The ASF licenses this file
8# to you under the Apache License, Version 2.0 (the
9# "License"); you may not use this file except in compliance
10# with the License. You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing,
15# software distributed under the License is distributed on an
16# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17# KIND, either express or implied. See the License for the
18# specific language governing permissions and limitations
19# under the License.
20#
21
Randy Abernethy8e731372015-02-03 00:04:40 -080022if [ -n "${1}" ]; then
23 COVER=${1};
24fi
25
Roger Meier8909cbd2014-01-26 11:44:27 +010026DIR="$( cd "$( dirname "$0" )" && pwd )"
27
Randy Abernethy8e731372015-02-03 00:04:40 -080028ISTANBUL="$DIR/../../../node_modules/istanbul/lib/cli.js"
29NODEUNIT="${DIR}/../../../node_modules/nodeunit/bin/nodeunit"
30
31REPORT_PREFIX="${DIR}/../coverage/report"
32
33COUNT=0
34
Roger Meier8909cbd2014-01-26 11:44:27 +010035export NODE_PATH="${DIR}:${DIR}/../lib:${NODE_PATH}"
36
37testClientServer()
38{
Roger Meier57b354b2014-02-22 01:01:58 +010039 echo " Testing Client/Server with protocol $1 and transport $2 $3";
Roger Meier8909cbd2014-01-26 11:44:27 +010040 RET=0
Randy Abernethy8e731372015-02-03 00:04:40 -080041 if [ -n "${COVER}" ]; then
42 ${ISTANBUL} cover ${DIR}/server.js --dir ${REPORT_PREFIX}${COUNT} --handle-sigint -- -p $1 -t $2 $3 &
43 COUNT=$((COUNT+1))
44 else
45 node ${DIR}/server.js -p $1 -t $2 $3 &
46 fi
Roger Meier8909cbd2014-01-26 11:44:27 +010047 SERVERPID=$!
48 sleep 1
Randy Abernethy8e731372015-02-03 00:04:40 -080049 if [ -n "${COVER}" ]; then
50 ${ISTANBUL} cover ${DIR}/client.js --dir ${REPORT_PREFIX}${COUNT} -- -p $1 -t $2 $3 || RET=1
51 COUNT=$((COUNT+1))
52 else
53 node ${DIR}/client.js -p $1 -t $2 $3 || RET=1
54 fi
55 kill -2 $SERVERPID || RET=1
Roger Meier8909cbd2014-01-26 11:44:27 +010056 return $RET
57}
58
59testMultiplexedClientServer()
60{
Roger Meier57b354b2014-02-22 01:01:58 +010061 echo " Testing Multiplexed Client/Server with protocol $1 and transport $2 $3";
Roger Meier8909cbd2014-01-26 11:44:27 +010062 RET=0
Randy Abernethy8e731372015-02-03 00:04:40 -080063 if [ -n "${COVER}" ]; then
64 ${ISTANBUL} cover ${DIR}/multiplex_server.js --dir ${REPORT_PREFIX}${COUNT} --handle-sigint -- -p $1 -t $2 $3 &
65 COUNT=$((COUNT+1))
66 else
67 node ${DIR}/multiplex_server.js -p $1 -t $2 $3 &
68 fi
Roger Meier8909cbd2014-01-26 11:44:27 +010069 SERVERPID=$!
70 sleep 1
Randy Abernethy8e731372015-02-03 00:04:40 -080071 if [ -n "${COVER}" ]; then
72 ${ISTANBUL} cover ${DIR}/multiplex_client.js --dir ${REPORT_PREFIX}${COUNT} -- -p $1 -t $2 $3 || RET=1
73 COUNT=$((COUNT+1))
74 else
75 node ${DIR}/multiplex_client.js -p $1 -t $2 $3 || RET=1
76 fi
77 kill -2 $SERVERPID || RET=1
Roger Meier8909cbd2014-01-26 11:44:27 +010078 return $RET
79}
80
ra8f697cb2014-04-23 02:23:18 -070081testHttpClientServer()
82{
83 echo " Testing HTTP Client/Server with protocol $1 and transport $2 $3";
84 RET=0
Randy Abernethy8e731372015-02-03 00:04:40 -080085 if [ -n "${COVER}" ]; then
86 ${ISTANBUL} cover ${DIR}/http_server.js --dir ${REPORT_PREFIX}${COUNT} --handle-sigint -- -p $1 -t $2 $3 &
87 COUNT=$((COUNT+1))
88 else
89 node ${DIR}/http_server.js -p $1 -t $2 $3 &
90 fi
ra8f697cb2014-04-23 02:23:18 -070091 SERVERPID=$!
92 sleep 1
Randy Abernethy8e731372015-02-03 00:04:40 -080093 if [ -n "${COVER}" ]; then
94 ${ISTANBUL} cover ${DIR}/http_client.js --dir ${REPORT_PREFIX}${COUNT} -- -p $1 -t $2 $3 || RET=1
95 COUNT=$((COUNT+1))
96 else
97 node ${DIR}/http_client.js -p $1 -t $2 $3 || RET=1
98 fi
99
100 kill -2 $SERVERPID || RET=1
101 sleep 1
ra8f697cb2014-04-23 02:23:18 -0700102 return $RET
103}
104
Randy Abernethy2e091f62014-11-15 23:05:22 -0800105testWSClientServer()
106{
107 echo " Testing WebSocket Client/Server with protocol $1 and transport $2 $3";
108 RET=0
Randy Abernethy8e731372015-02-03 00:04:40 -0800109 if [ -n "${COVER}" ]; then
110 ${ISTANBUL} cover ${DIR}/http_server.js --dir ${REPORT_PREFIX}${COUNT} --handle-sigint -- -p $1 -t $2 $3 &
111 COUNT=$((COUNT+1))
112 else
113 node ${DIR}/http_server.js -p $1 -t $2 $3 &
114 fi
Randy Abernethy2e091f62014-11-15 23:05:22 -0800115 SERVERPID=$!
116 sleep 1
Randy Abernethy8e731372015-02-03 00:04:40 -0800117 if [ -n "${COVER}" ]; then
118 ${ISTANBUL} cover ${DIR}/ws_client.js --dir ${REPORT_PREFIX}${COUNT} -- -p $1 -t $2 $3 || RET=1
119 COUNT=$((COUNT+1))
120 else
121 node ${DIR}/ws_client.js -p $1 -t $2 $3 || RET=1
122 fi
123
124 kill -2 $SERVERPID || RET=1
Randy Abernethy2e091f62014-11-15 23:05:22 -0800125 return $RET
126}
127
Roger Meier8909cbd2014-01-26 11:44:27 +0100128TESTOK=0
129
130#generating thrift code
131
132${DIR}/../../../compiler/cpp/thrift -o ${DIR} --gen js:node ${DIR}/../../../test/ThriftTest.thrift
133
134#unit tests
135
Randy Abernethy8e731372015-02-03 00:04:40 -0800136${NODEUNIT} ${DIR}/binary.test.js || TESTOK=1
Roger Meier8909cbd2014-01-26 11:44:27 +0100137
138#integration tests
139
ra8f697cb2014-04-23 02:23:18 -0700140#TCP connection tests
ra20aeba32014-05-11 00:25:01 -0700141testClientServer compact buffered || TESTOK=1
142testClientServer compact framed || TESTOK=1
Roger Meier8909cbd2014-01-26 11:44:27 +0100143testClientServer binary buffered || TESTOK=1
144testClientServer json buffered || TESTOK=1
145testClientServer binary framed || TESTOK=1
146testClientServer json framed || TESTOK=1
147
Roger Meier57b354b2014-02-22 01:01:58 +0100148#tests for multiplexed services
Roger Meier8909cbd2014-01-26 11:44:27 +0100149testMultiplexedClientServer binary buffered || TESTOK=1
150testMultiplexedClientServer json buffered || TESTOK=1
151testMultiplexedClientServer binary framed || TESTOK=1
ra20aeba32014-05-11 00:25:01 -0700152testMultiplexedClientServer compact framed || TESTOK=1
Roger Meier8909cbd2014-01-26 11:44:27 +0100153
Roger Meier57b354b2014-02-22 01:01:58 +0100154#test ssl connection
155testClientServer binary framed --ssl || TESTOK=1
156testMultiplexedClientServer binary framed --ssl || TESTOK=1
157
henrique31236232014-02-23 20:16:44 +0100158#test promise style
159testClientServer binary framed --promise || TESTOK=1
ra20aeba32014-05-11 00:25:01 -0700160testClientServer compact buffered --promise || TESTOK=1
Roger Meier57b354b2014-02-22 01:01:58 +0100161
ra8f697cb2014-04-23 02:23:18 -0700162#HTTP tests
ra20aeba32014-05-11 00:25:01 -0700163testHttpClientServer compact buffered || TESTOK=1
164testHttpClientServer compact framed || TESTOK=1
ra8f697cb2014-04-23 02:23:18 -0700165testHttpClientServer json buffered || TESTOK=1
166testHttpClientServer json framed || TESTOK=1
167testHttpClientServer binary buffered || TESTOK=1
168testHttpClientServer binary framed || TESTOK=1
ra779b9ac2014-04-23 20:04:23 -0700169testHttpClientServer json buffered --promise || TESTOK=1
170testHttpClientServer binary framed --ssl || TESTOK=1
ra8f697cb2014-04-23 02:23:18 -0700171
Randy Abernethy2e091f62014-11-15 23:05:22 -0800172#WebSocket tests
173testWSClientServer compact buffered || TESTOK=1
174testWSClientServer compact framed || TESTOK=1
175testWSClientServer json buffered || TESTOK=1
176testWSClientServer json framed || TESTOK=1
177testWSClientServer binary buffered || TESTOK=1
178testWSClientServer binary framed || TESTOK=1
179testWSClientServer json buffered --promise || TESTOK=1
180testWSClientServer binary framed --ssl || TESTOK=1
181
Randy Abernethy8e731372015-02-03 00:04:40 -0800182if [ -n "${COVER}" ]; then
183 echo "${DIR}/../coverage/report*/coverage.json"
184 ${ISTANBUL} report --dir "${DIR}/../coverage" --include "${DIR}/../coverage/report*/coverage.json" lcov cobertura html
185 rm -r ${DIR}/../coverage/report*/*
186 rmdir ${DIR}/../coverage/report*
187fi
188
Roger Meier8909cbd2014-01-26 11:44:27 +0100189exit $TESTOK