Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
cb2628ec
Commit
cb2628ec
authored
Apr 28, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initialize HTTP test cases on first use to work around MSVC initialization ordering.
parent
01917db9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
12 deletions
+50
-12
http-test.c++
c++/src/kj/compat/http-test.c++
+50
-12
No files found.
c++/src/kj/compat/http-test.c++
View file @
cb2628ec
...
...
@@ -555,13 +555,14 @@ void testHttpServerRequest(kj::AsyncIoContext& io,
KJ_EXPECT
(
service
.
getRequestCount
()
==
1
);
}
auto
HUGE_STRING
=
kj
::
strArray
(
kj
::
repeat
(
"abcdefgh"
,
4096
),
""
);
auto
HUGE_REQUEST
=
kj
::
str
(
kj
::
ArrayPtr
<
const
HttpRequestTestCase
>
requestTestCases
()
{
static
const
auto
HUGE_STRING
=
kj
::
strArray
(
kj
::
repeat
(
"abcdefgh"
,
4096
),
""
);
static
const
auto
HUGE_REQUEST
=
kj
::
str
(
"GET / HTTP/1.1
\r\n
"
"Host: "
,
HUGE_STRING
,
"
\r\n
"
"
\r\n
"
);
static
const
HttpRequestTestCase
REQUEST_TEST_CASES
[]
{
static
const
HttpRequestTestCase
REQUEST_TEST_CASES
[]
{
{
"GET /foo/bar HTTP/1.1
\r\n
"
"Host: example.com
\r\n
"
...
...
@@ -651,9 +652,13 @@ static const HttpRequestTestCase REQUEST_TEST_CASES[] {
{{
HttpHeaderId
::
HOST
,
HUGE_STRING
}},
nullptr
,
{}
},
};
};
return
REQUEST_TEST_CASES
;
}
static
const
HttpResponseTestCase
RESPONSE_TEST_CASES
[]
{
kj
::
ArrayPtr
<
const
HttpResponseTestCase
>
responseTestCases
()
{
static
const
HttpResponseTestCase
RESPONSE_TEST_CASES
[]
{
{
"HTTP/1.1 200 OK
\r\n
"
"Content-Type: text/plain
\r\n
"
...
...
@@ -710,12 +715,15 @@ static const HttpResponseTestCase RESPONSE_TEST_CASES[] {
{{
HttpHeaderId
::
CONTENT_TYPE
,
"text/plain"
}},
nullptr
,
{
"qux"
,
"corge"
}
},
};
};
return
RESPONSE_TEST_CASES
;
}
KJ_TEST
(
"HttpClient requests"
)
{
auto
io
=
kj
::
setupAsyncIo
();
for
(
auto
&
testCase
:
REQUEST_TEST_CASES
)
{
for
(
auto
&
testCase
:
requestTestCases
()
)
{
if
(
testCase
.
side
==
SERVER_ONLY
)
continue
;
KJ_CONTEXT
(
testCase
.
raw
);
testHttpClientRequest
(
io
,
testCase
);
...
...
@@ -726,7 +734,7 @@ KJ_TEST("HttpClient responses") {
auto
io
=
kj
::
setupAsyncIo
();
size_t
FRAGMENT_SIZES
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
16
,
31
,
kj
::
maxValue
};
for
(
auto
&
testCase
:
RESPONSE_TEST_CASES
)
{
for
(
auto
&
testCase
:
responseTestCases
()
)
{
if
(
testCase
.
side
==
SERVER_ONLY
)
continue
;
for
(
size_t
fragmentSize
:
FRAGMENT_SIZES
)
{
KJ_CONTEXT
(
testCase
.
raw
,
fragmentSize
);
...
...
@@ -759,7 +767,7 @@ KJ_TEST("HttpServer requests") {
auto
io
=
kj
::
setupAsyncIo
();
for
(
auto
&
testCase
:
REQUEST_TEST_CASES
)
{
for
(
auto
&
testCase
:
requestTestCases
()
)
{
if
(
testCase
.
side
==
CLIENT_ONLY
)
continue
;
KJ_CONTEXT
(
testCase
.
raw
);
testHttpServerRequest
(
io
,
testCase
,
...
...
@@ -790,7 +798,7 @@ KJ_TEST("HttpServer responses") {
auto
io
=
kj
::
setupAsyncIo
();
for
(
auto
&
testCase
:
RESPONSE_TEST_CASES
)
{
for
(
auto
&
testCase
:
responseTestCases
()
)
{
if
(
testCase
.
side
==
CLIENT_ONLY
)
continue
;
KJ_CONTEXT
(
testCase
.
raw
);
testHttpServerRequest
(
io
,
...
...
@@ -800,7 +808,8 @@ KJ_TEST("HttpServer responses") {
// -----------------------------------------------------------------------------
static
const
HttpTestCase
PIPELINE_TESTS
[]
=
{
kj
::
ArrayPtr
<
const
HttpTestCase
>
pipelineTestCases
()
{
static
const
HttpTestCase
PIPELINE_TESTS
[]
=
{
{
{
"GET / HTTP/1.1
\r\n
"
...
...
@@ -881,9 +890,14 @@ static const HttpTestCase PIPELINE_TESTS[] = {
200
,
"OK"
,
{},
7
,
{
"foo bar"
}
},
},
};
};
return
PIPELINE_TESTS
;
}
KJ_TEST
(
"HttpClient pipeline"
)
{
auto
PIPELINE_TESTS
=
pipelineTestCases
();
auto
io
=
kj
::
setupAsyncIo
();
auto
pipe
=
io
.
provider
->
newTwoWayPipe
();
...
...
@@ -933,6 +947,8 @@ KJ_TEST("HttpClient pipeline") {
}
KJ_TEST
(
"HttpClient parallel pipeline"
)
{
auto
PIPELINE_TESTS
=
pipelineTestCases
();
auto
io
=
kj
::
setupAsyncIo
();
auto
pipe
=
io
.
provider
->
newTwoWayPipe
();
...
...
@@ -986,6 +1002,8 @@ KJ_TEST("HttpClient parallel pipeline") {
}
KJ_TEST
(
"HttpServer pipeline"
)
{
auto
PIPELINE_TESTS
=
pipelineTestCases
();
auto
io
=
kj
::
setupAsyncIo
();
auto
pipe
=
io
.
provider
->
newTwoWayPipe
();
...
...
@@ -1011,6 +1029,8 @@ KJ_TEST("HttpServer pipeline") {
}
KJ_TEST
(
"HttpServer parallel pipeline"
)
{
auto
PIPELINE_TESTS
=
pipelineTestCases
();
auto
io
=
kj
::
setupAsyncIo
();
auto
pipe
=
io
.
provider
->
newTwoWayPipe
();
...
...
@@ -1037,6 +1057,8 @@ KJ_TEST("HttpServer parallel pipeline") {
}
KJ_TEST
(
"HttpClient <-> HttpServer"
)
{
auto
PIPELINE_TESTS
=
pipelineTestCases
();
auto
io
=
kj
::
setupAsyncIo
();
auto
pipe
=
io
.
provider
->
newTwoWayPipe
();
...
...
@@ -1082,6 +1104,8 @@ KJ_TEST("HttpClient <-> HttpServer") {
// -----------------------------------------------------------------------------
KJ_TEST
(
"HttpServer request timeout"
)
{
auto
PIPELINE_TESTS
=
pipelineTestCases
();
auto
io
=
kj
::
setupAsyncIo
();
auto
pipe
=
io
.
provider
->
newTwoWayPipe
();
...
...
@@ -1100,6 +1124,8 @@ KJ_TEST("HttpServer request timeout") {
}
KJ_TEST
(
"HttpServer pipeline timeout"
)
{
auto
PIPELINE_TESTS
=
pipelineTestCases
();
auto
io
=
kj
::
setupAsyncIo
();
auto
pipe
=
io
.
provider
->
newTwoWayPipe
();
...
...
@@ -1146,6 +1172,8 @@ private:
};
KJ_TEST
(
"HttpServer no response"
)
{
auto
PIPELINE_TESTS
=
pipelineTestCases
();
auto
io
=
kj
::
setupAsyncIo
();
auto
pipe
=
io
.
provider
->
newTwoWayPipe
();
...
...
@@ -1170,6 +1198,8 @@ KJ_TEST("HttpServer no response") {
}
KJ_TEST
(
"HttpServer disconnected"
)
{
auto
PIPELINE_TESTS
=
pipelineTestCases
();
auto
io
=
kj
::
setupAsyncIo
();
auto
pipe
=
io
.
provider
->
newTwoWayPipe
();
...
...
@@ -1188,6 +1218,8 @@ KJ_TEST("HttpServer disconnected") {
}
KJ_TEST
(
"HttpServer overloaded"
)
{
auto
PIPELINE_TESTS
=
pipelineTestCases
();
auto
io
=
kj
::
setupAsyncIo
();
auto
pipe
=
io
.
provider
->
newTwoWayPipe
();
...
...
@@ -1206,6 +1238,8 @@ KJ_TEST("HttpServer overloaded") {
}
KJ_TEST
(
"HttpServer unimplemented"
)
{
auto
PIPELINE_TESTS
=
pipelineTestCases
();
auto
io
=
kj
::
setupAsyncIo
();
auto
pipe
=
io
.
provider
->
newTwoWayPipe
();
...
...
@@ -1224,6 +1258,8 @@ KJ_TEST("HttpServer unimplemented") {
}
KJ_TEST
(
"HttpServer threw exception"
)
{
auto
PIPELINE_TESTS
=
pipelineTestCases
();
auto
io
=
kj
::
setupAsyncIo
();
auto
pipe
=
io
.
provider
->
newTwoWayPipe
();
...
...
@@ -1264,6 +1300,8 @@ private:
};
KJ_TEST
(
"HttpServer threw exception after starting response"
)
{
auto
PIPELINE_TESTS
=
pipelineTestCases
();
auto
io
=
kj
::
setupAsyncIo
();
auto
pipe
=
io
.
provider
->
newTwoWayPipe
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment