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
31dca64f
Commit
31dca64f
authored
Sep 18, 2018
by
Ian Roddis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refining test to capture behaviour that is broken
parent
576db850
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
60 deletions
+48
-60
tests/streaming_test.cc
tests/streaming_test.cc
+48
-60
No files found.
tests/streaming_test.cc
View file @
31dca64f
...
@@ -11,30 +11,36 @@
...
@@ -11,30 +11,36 @@
using
namespace
std
;
using
namespace
std
;
using
namespace
Pistache
;
using
namespace
Pistache
;
static
const
size_t
N_LETTERS
=
26
;
static
const
size_t
LETTER_REPEATS
=
100000
;
static
const
size_t
SET_REPEATS
=
10
;
static
const
uint16_t
PORT
=
9080
;
void
dumpData
(
const
Rest
::
Request
&
req
,
Http
::
ResponseWriter
response
)
{
void
dumpData
(
const
Rest
::
Request
&
req
,
Http
::
ResponseWriter
response
)
{
UNUSED
(
req
);
UNUSED
(
req
);
auto
stream
=
response
.
stream
(
Http
::
Code
::
Ok
);
auto
stream
=
response
.
stream
(
Http
::
Code
::
Ok
);
std
::
streamsize
n
=
1000
;
char
letter
=
'A'
;
char
letter
=
'A'
;
std
::
mutex
responseGuard
;
std
::
mutex
responseGuard
;
std
::
vector
<
std
::
thread
>
workers
;
std
::
vector
<
std
::
thread
>
workers
;
auto
sendPayload
=
[
&
responseGuard
,
&
stream
,
n
](
char
let
)
->
void
{
size_t
chunk_size
=
n
/
10
;
{
std
::
unique_lock
<
std
::
mutex
>
l
(
responseGuard
);
for
(
size_t
chunk
=
0
;
chunk
<
10
;
++
chunk
)
{
std
::
string
payload
(
chunk_size
*
chunk
,
let
);
stream
.
write
(
payload
.
c_str
(),
n
);
stream
.
flush
();
}
}
};
for
(
size_t
i
;
i
<
26
;
++
i
)
{
for
(
size_t
s
=
0
;
s
<
SET_REPEATS
;
++
s
)
{
workers
.
emplace_back
(
std
::
thread
(
sendPayload
,
letter
+
i
));
for
(
size_t
i
=
0
;
i
<
N_LETTERS
;
++
i
)
{
std
::
thread
job
([
&
,
i
]()
->
void
{
const
size_t
nchunks
=
10
;
size_t
chunk_size
=
LETTER_REPEATS
/
nchunks
;
std
::
string
payload
(
chunk_size
,
letter
+
i
);
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
responseGuard
);
for
(
size_t
chunk
=
0
;
chunk
<
nchunks
;
++
chunk
)
{
stream
.
write
(
payload
.
c_str
(),
chunk_size
);
stream
.
flush
();
}
}
});
workers
.
push_back
(
std
::
move
(
job
));
}
}
}
for
(
auto
&
w
:
workers
)
{
w
.
join
();
}
for
(
auto
&
w
:
workers
)
{
w
.
join
();
}
...
@@ -43,50 +49,38 @@ void dumpData(const Rest::Request&req, Http::ResponseWriter response) {
...
@@ -43,50 +49,38 @@ void dumpData(const Rest::Request&req, Http::ResponseWriter response) {
TEST
(
stream
,
from_description
)
TEST
(
stream
,
from_description
)
{
{
Http
::
Client
client
;
Address
addr
(
Ipv4
::
any
(),
PORT
);
auto
client_opts
=
Http
::
Client
::
options
()
.
threads
(
3
)
.
maxConnectionsPerHost
(
3
);
client
.
init
(
client_opts
);
Address
addr
(
Ipv4
::
any
(),
9080
);
const
size_t
threads
=
20
;
const
size_t
threads
=
20
;
auto
pid
=
fork
();
std
::
shared_ptr
<
Http
::
Endpoint
>
endpoint
;
if
(
pid
==
0
)
{
Rest
::
Description
desc
(
"Rest Description Test"
,
"v1"
);
std
::
shared_ptr
<
Http
::
Endpoint
>
endpoint
;
Rest
::
Router
router
;
Rest
::
Description
desc
(
"Rest Description Test"
,
"v1"
);
Rest
::
Router
router
;
desc
.
route
(
desc
.
get
(
"/"
))
desc
.
bind
(
&
dumpData
)
.
route
(
desc
.
get
(
"/"
))
.
response
(
Http
::
Code
::
Ok
,
"Response to the /ready call"
);
.
bind
(
&
dumpData
)
.
response
(
Http
::
Code
::
Ok
,
"Response to the /ready call"
);
router
.
initFromDescription
(
desc
);
router
.
initFromDescription
(
desc
);
auto
flags
=
Tcp
::
Options
::
InstallSignalHandler
|
Tcp
::
Options
::
ReuseAddr
;
auto
flags
=
Tcp
::
Options
::
InstallSignalHandler
|
Tcp
::
Options
::
ReuseAddr
;
auto
opts
=
Http
::
Endpoint
::
options
()
.
threads
(
threads
)
auto
opts
=
Http
::
Endpoint
::
options
()
.
flags
(
flags
)
.
threads
(
threads
)
.
maxPayload
(
1024
*
1024
)
.
flags
(
flags
)
;
.
maxPayload
(
1024
*
1024
)
;
endpoint
=
std
::
make_shared
<
Pistache
::
Http
::
Endpoint
>
(
addr
);
endpoint
->
init
(
opts
);
endpoint
=
std
::
make_shared
<
Pistache
::
Http
::
Endpoint
>
(
addr
);
endpoint
->
setHandler
(
router
.
handler
());
endpoint
->
init
(
opts
);
endpoint
->
serveThreaded
();
endpoint
->
setHandler
(
router
.
handler
());
endpoint
->
serve
();
endpoint
->
shutdown
();
return
;
}
std
::
stringstream
ss
;
std
::
stringstream
ss
;
// from https://stackoverflow.com/questions/6624667/can-i-use-libcurls-curlopt-writefunction-with-a-c11-lambda-expression#14720398
// from https://stackoverflow.com/questions/6624667/can-i-use-libcurls-curlopt-writefunction-with-a-c11-lambda-expression#14720398
typedef
size_t
(
*
CURL_WRITEFUNCTION_PTR
)(
void
*
,
size_t
,
size_t
,
void
*
);
typedef
size_t
(
*
CURL_WRITEFUNCTION_PTR
)(
void
*
,
size_t
,
size_t
,
void
*
);
auto
curl_callback
=
[](
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
stream
)
->
size_t
{
auto
curl_callback
=
[](
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
stream
)
->
size_t
{
std
::
cout
.
write
((
char
*
)
ptr
,
size
*
nmemb
);
auto
ss
=
static_cast
<
std
::
stringstream
*>
(
stream
);
auto
ss
=
static_cast
<
std
::
stringstream
*>
(
stream
);
(
*
ss
).
write
(
static_cast
<
char
*>
(
ptr
),
size
*
nmemb
);
(
*
ss
).
write
(
static_cast
<
char
*>
(
ptr
),
size
*
nmemb
);
return
size
*
nmemb
;
return
size
*
nmemb
;
...
@@ -100,16 +94,10 @@ TEST(stream, from_description)
...
@@ -100,16 +94,10 @@ TEST(stream, from_description)
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
static_cast
<
CURL_WRITEFUNCTION_PTR
>
(
curl_callback
));
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
static_cast
<
CURL_WRITEFUNCTION_PTR
>
(
curl_callback
));
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
&
ss
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
&
ss
);
res
=
curl_easy_perform
(
curl
);
res
=
curl_easy_perform
(
curl
);
if
(
res
!=
CURLE_OK
)
{
throw
std
::
runtime_error
(
curl_easy_strerror
(
res
));
}
curl_easy_cleanup
(
curl
);
curl_easy_cleanup
(
curl
);
}
}
endpoint
->
shutdown
();
ASSERT_EQ
(
ss
.
str
().
size
(),
26000
);
ASSERT_EQ
(
res
,
CURLE_OK
);
ASSERT_EQ
(
ss
.
str
().
size
(),
SET_REPEATS
*
LETTER_REPEATS
*
N_LETTERS
);
kill
(
pid
,
SIGTERM
);
int
r
;
waitpid
(
pid
,
&
r
,
0
);
client
.
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