Skip to content

Commit 57192e6

Browse files
committed
replace curl based server testing with remote(HTTP.get) based testing to make CI integration easier
1 parent 9922d60 commit 57192e6

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

test/server.jl

+32-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
1+
@static if VERSION >= v"0.7.0-DEV.2915"
2+
using Distributed
3+
end
4+
while nworkers() < 5
5+
addprocs(1)
6+
end
7+
18
using HTTP
29
using HTTP.Test
310

11+
12+
using HTTP
13+
414
port = rand(8000:8999)
515

6-
function testget(url)
7-
mktempdir() do d
8-
cd(d) do
9-
cmd = `"curl -v -s $url > tmpout 2>&1"`
10-
cmd = `bash -c $cmd`
11-
#println(cmd)
12-
run(cmd)
13-
return String(read(joinpath(d, "tmpout")))
14-
end
16+
"""
17+
n: number of remotes
18+
m: number of async requests per remote
19+
"""
20+
function testget(url, n=1, m=1)
21+
r = []
22+
@sync for i in 1:n
23+
@async push!(r, remote((url, mm) -> begin
24+
rr = []
25+
@sync for ii in 1:mm
26+
l = rand([0,0,10,1000,10000])
27+
body = Vector{UInt8}(rand('A':'Z', l))
28+
@async push!(rr, HTTP.request("GET", "$url/$ii", [], body))
29+
end
30+
return rr
31+
end)("$url/$i", m))
1532
end
33+
return join([String(x) for x in vcat(r...)], "\n")
1634
end
1735

1836
@testset "HTTP.Servers.serve" begin
@@ -45,18 +63,19 @@ r = testget("http://127.0.0.1:$port/")
4563
@test ismatch(r"HTTP/1.1 200 OK", r)
4664

4765
rv = []
48-
n = 3
66+
n = 5
67+
m = 20
4968
@sync for i = 1:n
5069
@async begin
51-
r = testget(repeat("http://127.0.0.1:$port/$i ", n))
70+
r = testget("http://127.0.0.1:$port/$i", n, m)
5271
#println(r)
5372
push!(rv, r)
5473
end
5574
sleep(0.01)
5675
end
5776
for i = 1:n
5877
@test length(filter(l->ismatch(r"HTTP/1.1 200 OK", l),
59-
split(rv[i], "\n"))) == n
78+
split(rv[i], "\n"))) == n * m
6079
end
6180

6281
r = HTTP.get("http://127.0.0.1:$port/"; readtimeout=30)
@@ -85,7 +104,7 @@ tcp = connect(ip"127.0.0.1", port)
85104
write(tcp, "SOMEMETHOD HTTP/1.1\r\nContent-Length: 0\r\n\r\n")
86105
r = String(read(tcp))
87106
!HTTP.Parsers.strict && @test ismatch(r"HTTP/1.1 400 Bad Request", r)
88-
!HTTP.Parsers.strict && @test ismatch(r"invalid URL", r)
107+
!HTTP.Parsers.strict && @test ismatch(r"invalid HTTP request target", r)
89108
sleep(2.0)
90109

91110

0 commit comments

Comments
 (0)