Skip to content

Commit d39d20b

Browse files
committed
sharness: try handling nc requests a different way...
License: MIT Signed-off-by: Steven Allen <[email protected]>
1 parent 84c5af3 commit d39d20b

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

test/sharness/t0235-cli-request.sh

+18-19
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,30 @@ test_description="test http requests made by cli"
1111
test_init_ipfs
1212

1313
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 &
14+
rm -f nc_outp nc_inp nc_statusp && mkfifo nc_inp nc_outp nc_statusp
15+
nc -v -l 127.0.0.1 5005 <nc_inp >nc_outp 2>nc_statusp &
1616
NCPID=$!
17+
exec 6>nc_inp 7<nc_outp
1718
18-
# Needed to "prime" nc
19-
echo -n "" > nc_in &&
20-
21-
# Wait for it to start
22-
head -1 nc_status
19+
head -1 <nc_statusp
2320
'
2421

2522
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-
head -1 nc_status & # consume "connected message"
34-
ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005
35-
'
23+
ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005 &
24+
IPFSPID=$!
25+
26+
head -1 <nc_statusp
27+
28+
# handle request
29+
echo "HTTP/1.1 200 OK" >&6 &&
30+
echo "Content-Type: text/plain" >&6 &&
31+
echo "Content-Length: 0" >&6 &&
32+
echo "" >&6 &&
33+
sed -n "0,/^$/p" <&7 > nc_out &&
34+
exec 6<&- # Keep connection open till *after* we have the full request.
3635
37-
test_expect_success "wait for nc to exit" '
38-
wait $NCPID
36+
# Wait for IPFS and netcat
37+
wait $IPFSPID $NCPID
3938
'
4039

4140
test_expect_success "output does not contain multipart info" '

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

+20-16
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,35 @@ test_description="test dns resolution of api endpoint by cli"
1111
test_init_ipfs
1212

1313
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 5006 < nc_in > nc_out 2>nc_status &
14+
rm -f nc_outp nc_inp nc_statusp && mkfifo nc_inp nc_outp nc_statusp
15+
nc -v -l 127.0.0.1 5005 <nc_inp >nc_outp 2>nc_statusp &
1616
NCPID=$!
17+
exec 6>nc_inp 7<nc_outp
1718
18-
# Needed to "prime" nc
19-
echo -n "" > nc_in &&
20-
21-
# Wait for it to start
22-
head -1 nc_status
19+
head -1 <nc_statusp
2320
'
2421

2522
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-
head -1 nc_status & # consume "connected message"
34-
ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5006
23+
ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5006 &
24+
IPFSPID=$!
25+
26+
head -1 <nc_statusp
27+
28+
# handle request
29+
echo "HTTP/1.1 200 OK" >&6 &&
30+
echo "Content-Type: text/plain" >&6 &&
31+
echo "Content-Length: 0" >&6 &&
32+
echo "" >&6 &&
33+
sed -n "0,/^$/p" <&7 > nc_out &&
34+
exec 6<&- # Keep connection open till *after* we have the full request.
35+
36+
# Wait for IPFS and netcat
37+
wait $IPFSPID $NCPID
3538
'
3639

3740
test_expect_success "wait for nc to exit" '
3841
wait $NCPID
42+
cat nc_out
3943
'
4044

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

0 commit comments

Comments
 (0)