really fix netcat race
We hit this once every few Jenkins runs. This: 1. Ensures netcat has started before we try to use it. 2. Waits for it to actually write the request before trying to read it. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Nov 29, 2018 at 01:09 UTC
c0f979dfe186fd1dc13e85d1818b1bc1bb7db74a
2 files changed
+72
-8
test/sharness/t0235-cli-request.sh
+36
-4
@@ -10,11 +10,43 @@ test_description="test http requests made by cli"
10
11
test_init_ipfs
12
13
-test_expect_success "can make http request against nc server" '
14
- nc -ld 5005 > nc_out &
13
+test_expect_success "start nc" '
14
+ rm -f nc_out nc_outp nc_inp && mkfifo nc_inp nc_outp
15
+
16
+ nc -k -l 127.0.0.1 5005 <nc_inp >nc_outp &
17
NCPID=$!
16
- go-sleep 0.5s && kill "$NCPID" &
17
- ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005 || true
18
+
19
+ exec 6>nc_inp 7<nc_outp
20
+
21
+ while ! nc -z 127.0.0.1 5005; do
22
+ go-sleep 100ms
23
+ done
24
+'
25
+
26
+test_expect_success "can make http request against nc server" '
27
+ ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005 &
28
+ IPFSPID=$!
29
+
30
+ # handle request
31
+ while read line; do
32
+ if [[ "$line" == "$(echo -e "\r")" ]]; then
33
+ break
34
+ fi
35
+ echo "$line"
36
+ done <&7 >nc_out &&
37
+
38
+ echo -e "HTTP/1.1 200 OK\r" >&6 &&
39
+ echo -e "Content-Type: text/plain\r" >&6 &&
40
+ echo -e "Content-Length: 0\r" >&6 &&
41
+ echo -e "\r" >&6 &&
42
+ exec 6<&- &&
43
+
44
+ # Wait for IPFS
45
+ wait $IPFSPID
46
+'
47
+
48
+test_expect_success "stop nc" '
49
+ kill "$NCPID" && wait "$NCPID" || true
50
'
51
52
test_expect_success "output does not contain multipart info" '
test/sharness/t0236-cli-api-dns-resolve.sh
+36
-4
@@ -10,11 +10,43 @@ test_description="test dns resolution of api endpoint by cli"
10
11
test_init_ipfs
12
13
-test_expect_success "can make http request against dns resolved nc server" '
14
- nc -ld 5005 > nc_out &
13
+test_expect_success "start nc" '
14
+ rm -f nc_out nc_outp nc_inp && mkfifo nc_inp nc_outp
15
+
16
+ nc -k -l 127.0.0.1 5006 <nc_inp >nc_outp &
17
NCPID=$!
16
- go-sleep 1s && kill "$NCPID" &
17
- ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5005 || true
18
+
19
+ exec 6>nc_inp 7<nc_outp
20
+
21
+ while ! nc -z 127.0.0.1 5006; do
22
+ go-sleep 100ms
23
+ done
24
+'
25
+
26
+test_expect_success "can make http request against dns resolved nc server" '
27
+ ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5006 &
28
+ IPFSPID=$!
29
+
30
+ # handle request
31
+ while read line; do
32
+ if [[ "$line" == "$(echo -e "\r")" ]]; then
33
+ break
34
+ fi
35
+ echo "$line"
36
+ done <&7 >nc_out &&
37
+
38
+ echo -e "HTTP/1.1 200 OK\r" >&6 &&
39
+ echo -e "Content-Type: text/plain\r" >&6 &&
40
+ echo -e "Content-Length: 0\r" >&6 &&
41
+ echo -e "\r" >&6 &&
42
+ exec 6<&- &&
43
+
44
+ # Wait for IPFS
45
+ wait $IPFSPID
46
+'
47
+
48
+test_expect_success "stop nc" '
49
+ kill "$NCPID" && wait "$NCPID" || true
50
'
51
52
test_expect_success "request was received by local nc server" '