Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pistache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
pistache
Commits
8a585386
Unverified
Commit
8a585386
authored
Mar 18, 2019
by
Dennis Jenkins
Committed by
GitHub
Mar 18, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #500 from knowledge4igor/first_step_of_fixing_client_problems
Fixing error handling in client and payload test
parents
4931e1bd
7f242603
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
30 deletions
+25
-30
src/client/client.cc
src/client/client.cc
+6
-5
tests/payload_test.cc
tests/payload_test.cc
+19
-25
No files found.
src/client/client.cc
View file @
8a585386
...
...
@@ -165,17 +165,17 @@ Transport::onReady(const Aio::FdSet& fds) {
auto
fd
=
tag
.
value
();
auto
connIt
=
connections
.
find
(
fd
);
if
(
connIt
!=
std
::
end
(
connections
))
{
auto
&
conn
=
connIt
->
second
;
auto
&
conn
ectionEntry
=
connIt
->
second
;
if
(
entry
.
isHangup
())
conn
.
reject
(
Error
::
system
(
"Could not connect"
));
conn
ectionEntry
.
reject
(
Error
::
system
(
"Could not connect"
));
else
{
conn
.
resolve
();
// We are connected, we can start reading data now
auto
connection
=
connIt
->
second
.
connection
.
lock
();
if
(
connection
)
{
connectionEntry
.
resolve
();
// We are connected, we can start reading data now
reactor
()
->
modifyFd
(
key
(),
connection
->
fd
(),
NotifyOn
::
Read
);
}
else
{
throw
std
::
runtime_error
(
"Connection error"
);
connectionEntry
.
reject
(
Error
::
system
(
"Connection lost"
)
);
}
}
}
else
{
...
...
@@ -490,6 +490,7 @@ Connection::handleError(const char* error) {
void
Connection
::
handleTimeout
()
{
if
(
requestEntry
)
{
requestEntry
->
timer
->
disarm
();
timerPool_
.
releaseTimer
(
requestEntry
->
timer
);
auto
onDone
=
requestEntry
->
onDone
;
...
...
tests/payload_test.cc
View file @
8a585386
...
...
@@ -36,20 +36,28 @@ struct TestSet {
using
PayloadTestSets
=
std
::
vector
<
TestSet
>
;
void
testPayloads
(
Http
::
Client
&
client
,
const
std
::
string
&
url
,
const
PayloadTestSets
&
testPayloads
)
{
// Client tests to make sure the payload is enforced
void
testPayloads
(
const
std
::
string
&
url
,
const
PayloadTestSets
&
testPayloads
)
{
// Client tests to make sure the payload is enforced
PayloadTestSets
testResults
;
std
::
mutex
resultsetMutex
;
PayloadTestSets
test_results
;
Http
::
Client
client
;
auto
client_opts
=
Http
::
Client
::
options
()
.
threads
(
3
)
.
maxConnectionsPerHost
(
3
);
client
.
init
(
client_opts
);
std
::
vector
<
Async
::
Promise
<
Http
::
Response
>>
responses
;
responses
.
reserve
(
testPayloads
.
size
());
for
(
auto
&
t
:
testPayloads
)
{
std
::
string
payload
(
t
.
bytes
,
'A'
);
auto
response
=
client
.
post
(
url
).
body
(
payload
).
timeout
(
std
::
chrono
::
seconds
(
wait_time
)).
send
();
response
.
then
([
t
,
&
test
_r
esults
,
&
resultsetMutex
](
Http
::
Response
rsp
)
{
response
.
then
([
t
,
&
test
R
esults
,
&
resultsetMutex
](
Http
::
Response
rsp
)
{
TestSet
res
(
t
);
res
.
actualCode
=
rsp
.
code
();
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
resultsetMutex
);
test
_r
esults
.
push_back
(
res
);
test
R
esults
.
push_back
(
res
);
}
},
Async
::
IgnoreException
);
responses
.
push_back
(
std
::
move
(
response
));
...
...
@@ -59,9 +67,11 @@ void testPayloads(Http::Client& client, const std::string& url, const PayloadTes
Async
::
Barrier
<
std
::
vector
<
Http
::
Response
>>
barrier
(
sync
);
barrier
.
wait_for
(
std
::
chrono
::
seconds
(
2
*
wait_time
));
for
(
auto
&
result
:
test
_r
esults
)
{
for
(
auto
&
result
:
test
R
esults
)
{
ASSERT_EQ
(
result
.
expectedCode
,
result
.
actualCode
);
}
client
.
shutdown
();
}
void
handleEcho
(
const
Rest
::
Request
&
/*request*/
,
Http
::
ResponseWriter
response
)
{
...
...
@@ -95,13 +105,6 @@ TEST(payload, from_description)
endpoint
->
setHandler
(
router
.
handler
());
endpoint
->
serveThreaded
();
Http
::
Client
client
;
auto
client_opts
=
Http
::
Client
::
options
()
.
threads
(
3
)
.
maxConnectionsPerHost
(
3
);
client
.
init
(
client_opts
);
// TODO: Remove temp hack once 'serveThreaded()' waits for socket to be
// created before returning.
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
150
));
...
...
@@ -113,9 +116,8 @@ TEST(payload, from_description)
,{
2048
,
Http
::
Code
::
Request_Entity_Too_Large
}
};
testPayloads
(
client
,
"127.0.0.1:"
+
std
::
to_string
(
port
),
payloads
);
testPayloads
(
"127.0.0.1:"
+
std
::
to_string
(
port
),
payloads
);
client
.
shutdown
();
endpoint
->
shutdown
();
}
...
...
@@ -156,22 +158,14 @@ TEST(payload, manual_construction) {
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
150
));
const
auto
port
=
endpoint
->
getPort
();
// Create http client.
Http
::
Client
client
;
auto
client_opts
=
Http
::
Client
::
options
()
.
threads
(
3
)
.
maxConnectionsPerHost
(
3
);
client
.
init
(
client_opts
);
PayloadTestSets
payloads
{
{
1024
,
Http
::
Code
::
Ok
}
,
{
1800
,
Http
::
Code
::
Ok
}
,
{
2048
,
Http
::
Code
::
Request_Entity_Too_Large
}
,
{
4096
,
Http
::
Code
::
Request_Entity_Too_Large
}
};
testPayloads
(
client
,
"127.0.0.1:"
+
std
::
to_string
(
port
),
payloads
);
// Cleanup
client
.
shutdown
();
testPayloads
(
"127.0.0.1:"
+
std
::
to_string
(
port
),
payloads
);
endpoint
->
shutdown
();
}
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