Skip to content

Commit c97b811

Browse files
committed
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 <[email protected]>
1 parent af73c50 commit c97b811

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

test/sharness/t0235-cli-request.sh

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,31 @@ test_description="test http requests made by cli"
1010

1111
test_init_ipfs
1212

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_status nc_in && mkfifo nc_in nc_status
15+
nc -v -l 127.0.0.1 5005 < nc_in > nc_out 2>nc_status &
1516
NCPID=$!
16-
go-sleep 0.5s && kill "$NCPID" &
17-
ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005 || true
17+
18+
# Needed to "prime" nc
19+
echo -n "" > nc_in
20+
21+
# Wait for it to start
22+
head -1 nc_status
23+
'
24+
25+
test_expect_success "can make http request against nc server" '
26+
cat >nc_in <<EOF
27+
HTTP/1.1 200 OK
28+
Content-Type: text/plain
29+
Content-Length: 1
30+
31+
.
32+
EOF
33+
ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005
34+
'
35+
36+
test_expect_success "wait for nc to exit" '
37+
wait $NCPID
1838
'
1939

2040
test_expect_success "output does not contain multipart info" '

test/sharness/t0236-cli-api-dns-resolve.sh

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,31 @@ test_description="test dns resolution of api endpoint by cli"
1010

1111
test_init_ipfs
1212

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_status nc_in && mkfifo nc_in nc_status
15+
nc -v -l 127.0.0.1 5005 < nc_in > nc_out 2>nc_status &
1516
NCPID=$!
16-
go-sleep 1s && kill "$NCPID" &
17-
ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5005 || true
17+
18+
# Needed to "prime" nc
19+
echo -n "" > nc_in
20+
21+
# Wait for it to start
22+
head -1 nc_status
23+
'
24+
25+
test_expect_success "can make http request against dns resolved nc server" '
26+
cat >nc_in <<EOF
27+
HTTP/1.1 200 OK
28+
Content-Type: text/plain
29+
Content-Length: 1
30+
31+
.
32+
EOF
33+
ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5005
34+
'
35+
36+
test_expect_success "wait for nc to exit" '
37+
wait $NCPID
1838
'
1939

2040
test_expect_success "request was received by local nc server" '

0 commit comments

Comments
 (0)