Skip to content

Commit

Permalink
really fix netcat race
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Stebalien committed Nov 30, 2018
1 parent af73c50 commit c0f979d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 8 deletions.
40 changes: 36 additions & 4 deletions test/sharness/t0235-cli-request.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,43 @@ test_description="test http requests made by cli"

test_init_ipfs

test_expect_success "can make http request against nc server" '
nc -ld 5005 > nc_out &
test_expect_success "start nc" '
rm -f nc_out nc_outp nc_inp && mkfifo nc_inp nc_outp
nc -k -l 127.0.0.1 5005 <nc_inp >nc_outp &
NCPID=$!
go-sleep 0.5s && kill "$NCPID" &
ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005 || true
exec 6>nc_inp 7<nc_outp
while ! nc -z 127.0.0.1 5005; do
go-sleep 100ms
done
'

test_expect_success "can make http request against nc server" '
ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005 &
IPFSPID=$!
# handle request
while read line; do
if [[ "$line" == "$(echo -e "\r")" ]]; then
break
fi
echo "$line"
done <&7 >nc_out &&
echo -e "HTTP/1.1 200 OK\r" >&6 &&
echo -e "Content-Type: text/plain\r" >&6 &&
echo -e "Content-Length: 0\r" >&6 &&
echo -e "\r" >&6 &&
exec 6<&- &&
# Wait for IPFS
wait $IPFSPID
'

test_expect_success "stop nc" '
kill "$NCPID" && wait "$NCPID" || true
'

test_expect_success "output does not contain multipart info" '
Expand Down
40 changes: 36 additions & 4 deletions test/sharness/t0236-cli-api-dns-resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,43 @@ test_description="test dns resolution of api endpoint by cli"

test_init_ipfs

test_expect_success "can make http request against dns resolved nc server" '
nc -ld 5005 > nc_out &
test_expect_success "start nc" '
rm -f nc_out nc_outp nc_inp && mkfifo nc_inp nc_outp
nc -k -l 127.0.0.1 5006 <nc_inp >nc_outp &
NCPID=$!
go-sleep 1s && kill "$NCPID" &
ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5005 || true
exec 6>nc_inp 7<nc_outp
while ! nc -z 127.0.0.1 5006; do
go-sleep 100ms
done
'

test_expect_success "can make http request against dns resolved nc server" '
ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5006 &
IPFSPID=$!
# handle request
while read line; do
if [[ "$line" == "$(echo -e "\r")" ]]; then
break
fi
echo "$line"
done <&7 >nc_out &&
echo -e "HTTP/1.1 200 OK\r" >&6 &&
echo -e "Content-Type: text/plain\r" >&6 &&
echo -e "Content-Length: 0\r" >&6 &&
echo -e "\r" >&6 &&
exec 6<&- &&
# Wait for IPFS
wait $IPFSPID
'

test_expect_success "stop nc" '
kill "$NCPID" && wait "$NCPID" || true
'

test_expect_success "request was received by local nc server" '
Expand Down

0 comments on commit c0f979d

Please sign in to comment.