-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest
executable file
·153 lines (129 loc) · 4.01 KB
/
test
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env bash
#
# manual tests
#
# * connect punch-client-forwarder to a server that doesn't respond like a web server
#
# ./zig-out/bin/punch-client-forwarder 127.0.0.1 80 127.0.0.1 1234
#
# make sure it keeps reconnecting waiting for magic value
#
set -euo pipefail
trap 'for job in $(jobs -p); do kill -n 9 $job; done' EXIT
wait_for_port() {
host=$1
port=$2
attempt=0
# todo: increase sleep time
while true; do
attempt=$((attempt+1))
if netstat -tln | grep -q ":$port"; then
break
fi
if [ "$attempt" == "6" ]; then
echo "ERROR: Port '$port' on host '$host' did not open after $attempt attempts"
return 1
fi
echo "Port '$port' on host '$host' not open on attempt $attempt, waiting..."
sleep 0.2
done
echo "Port '$port' on host '$host' is open ($attempt attempts)"
}
wait_for_pid() {
tail --pid=$1 -f /dev/null
}
clean_scratch() {
rm -rf scratch
mkdir scratch
}
clean_scratch
bin=./zig-out/bin
if [ -z "${START_PORT+x}" ]; then
start_port=9281
else
start_port=$START_PORT
fi
port0=$start_port
port1=$(expr $start_port + 1)
port2=$(expr $start_port + 2)
echo Using Ports: $port0 $port1 $port2
###$bin/reverse-tunnel-client 127.0.0.1 > scratch/reverse-tunnel-client.log 2>&1 &
###reverse_tunnel_client_pid=$! ###
###$bin/config-server > scratch/config-server1.log 2>&1 &
###config_server_pid=$!
#### wait for server to start
###sleep 1
###kill -n 9 $config_server_pid
#### wait for server to exit
###sleep 1
###
###$bin/config-server > scratch/config-server2.log 2>&1 &
###config_server_pid=$!
#### wait for server to start
###sleep 1
###
test_punch() {
echo "test_punch"
clean_scratch
$bin/punch-client-forwarder 127.0.0.1 $port0 127.0.0.1 $port2 > scratch/punch-client-forwarder.log 2>&1 &
punch_client_forwarder_pid=$!
$bin/punch-server-initiator 127.0.0.1 $port0 127.0.0.1 $port1 > scratch/punch-server-initiator.log 2>&1 &
punch_server_initiator_pid=$!
$bin/nc -l $port2 > scratch/inside-server.log 2>&1 &
inside_server_pid=$!
wait_for_port 127.0.0.1 $port2
wait_for_port 127.0.0.1 $port1
echo "hello from outside-client" | $bin/nc 127.0.0.1 $port1 > scratch/outside-client.log 2>&1
wait_for_pid $inside_server_pid
grep -q "hello from outside-client" scratch/inside-server.log
}
test_socat() {
echo "test_socat"
clean_scratch
for i in {1..5}; do
$bin/socat tcp-listen:1280 tcp-listen:1281 > scratch/temp-socat-double-server-$i.log 2>&1 &
socat_double_server_pid=$!
wait_for_port 127.0.0.1 1280
# kill and restart to make sure immediate restart works
kill -n 9 $socat_double_server_pid
done
# disable throttling so the test runs fast
$bin/socat --no-throttle tcp-listen:1280 tcp-listen:1281 > scratch/socat-double-server-main.log 2>&1 &
socat_double_server_pid=$!
wait_for_port 127.0.0.1 1280
for i in {1..20}; do
mkfifo scratch/nc-1280.fifo
cat scratch/nc-1280.fifo | $bin/nc 127.0.0.1 1280 > scratch/nc-1280.log 2>&1 &
wait_for_port 127.0.0.1 1281
$bin/nc 127.0.0.1 1281 > scratch/nc-1281.log 2>&1 &
nc_1281_pid=$!
echo "what" > scratch/nc-1280.fifo
wait_for_pid $nc_1281_pid
grep -q what scratch/nc-1281.log
rm scratch/nc-128*
done
kill -n 9 $socat_double_server_pid
}
#$bin/config-server > scratch/config-server1.log 2>&1 &
#config_server_pid=$!
## wait for server to start
#sleep 1
#kill -n 9 $config_server_pid
## wait for server to exit
#sleep 1
#$bin/config-server > scratch/config-server2.log 2>&1 &
#config_server_pid=$!
## wait for server to start
#sleep 1
#echo "" | $bin/nc 127.0.0.1 $port0 | hexdump -C
#kill -n 9 $config_server_pid
#$bin/double-server > scratch/double-server.log 2>&1 &
#double_server_pid=$!
## wait for server to start
#sleep 1
#echo "" | $bin/nc 127.0.0.1 $port1
#echo "killing double-server pid=$double_server_pid..."
#kill -n 9 $double_server_pid
test_punch
test_socat
echo Success