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 29, 2018
1 parent af73c50 commit c97b811
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
28 changes: 24 additions & 4 deletions test/sharness/t0235-cli-request.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,31 @@ 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_status nc_in && mkfifo nc_in nc_status
nc -v -l 127.0.0.1 5005 < nc_in > nc_out 2>nc_status &
NCPID=$!
go-sleep 0.5s && kill "$NCPID" &
ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005 || true
# Needed to "prime" nc
echo -n "" > nc_in
# Wait for it to start
head -1 nc_status
'

test_expect_success "can make http request against nc server" '
cat >nc_in <<EOF
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 1
.
EOF
ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005
'

test_expect_success "wait for nc to exit" '
wait $NCPID
'

test_expect_success "output does not contain multipart info" '
Expand Down
28 changes: 24 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,31 @@ 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_status nc_in && mkfifo nc_in nc_status
nc -v -l 127.0.0.1 5005 < nc_in > nc_out 2>nc_status &
NCPID=$!
go-sleep 1s && kill "$NCPID" &
ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5005 || true
# Needed to "prime" nc
echo -n "" > nc_in
# Wait for it to start
head -1 nc_status
'

test_expect_success "can make http request against dns resolved nc server" '
cat >nc_in <<EOF
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 1
.
EOF
ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5005
'

test_expect_success "wait for nc to exit" '
wait $NCPID
'

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

0 comments on commit c97b811

Please sign in to comment.