blob: e0a92dca0c5244a71a5042cc9e60abae950cd057 (
plain) (
blame)
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
|
#!/bin/sh
set -eu
. tests/lib.sh
test_exits_when_upstream_errors() {
testing 'exits when upstream errors'
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
trap 'rm -f "$OUT" "$ERR" s1.socket client.txt' EXIT
rm -f s1.socket
./binder.bin localhost:1234 s1.socket 1>"$OUT" 2>"$ERR" &
pid=$!
while ! lsof -s TCP:LISTEN -i :1234 > /dev/null; do
true
done
echo request | socat tcp-connect:localhost:1234 stdio > client.txt
kill $pid
wait
assert_fgrep_stdout 'listen-start'
assert_fgrep_stdout 'active-connections'
assert_fgrep_stdout 'dial-connection'
assert_empty_stderr
assert_empty_stream 'client.txt' client.txt
rm -f "$OUT" "$ERR" s1.socket client.txt
test_ok
}
test_works_from_client_to_server() {
testing 'works from client to server'
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
trap 'rm -f "$OUT" "$ERR" s2.socket client.txt server.txt' EXIT
rm -f s2.socket
./binder.bin localhost:1234 s2.socket 1>"$OUT" 2>"$ERR" &
pid=$!
while ! lsof -s TCP:LISTEN -i :1234 > /dev/null; do
true
done
echo response | socat unix-listen:s2.socket stdio > server.txt &
while [ ! -S s2.socket ]; do
true
done
echo request | socat tcp-connect:localhost:1234 stdio > client.txt
kill $pid
wait
assert_fgrep_stdout 'listen-start'
assert_fgrep_stdout 'active-connections'
assert_empty_stderr
assert_fgrep_stream 'client.txt' client.txt 'response'
assert_fgrep_stream 'server.txt' server.txt 'request'
rm -f "$OUT" "$ERR" s2.socket client.txt server.txt
test_ok
}
exit # FIXME
test_exits_when_upstream_errors
test_works_from_client_to_server
|