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
ffd44ec3
Commit
ffd44ec3
authored
Jan 01, 2019
by
Dennis Jenkins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
All unit test now use ephemeral ports.
parent
ac856c32
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
78 deletions
+71
-78
tests/net_test.cc
tests/net_test.cc
+9
-9
tests/payload_test.cc
tests/payload_test.cc
+58
-64
tests/streaming_test.cc
tests/streaming_test.cc
+4
-5
No files found.
tests/net_test.cc
View file @
ffd44ec3
...
...
@@ -39,7 +39,7 @@ TEST(net_test, address_creation)
Address
address3
(
Ipv4
(
127
,
0
,
0
,
1
),
Port
(
8080
));
ASSERT_EQ
(
address3
.
host
(),
"127.0.0.1"
);
ASSERT_EQ
(
address3
.
port
(),
8080
);
ASSERT_EQ
(
address3
.
port
(),
8080
);
Address
address4
(
Ipv4
::
any
(),
Port
(
8080
));
ASSERT_EQ
(
address4
.
host
(),
"0.0.0.0"
);
...
...
@@ -48,7 +48,7 @@ TEST(net_test, address_creation)
Address
address5
(
"*:8080"
);
ASSERT_EQ
(
address5
.
host
(),
"0.0.0.0"
);
ASSERT_EQ
(
address5
.
port
(),
8080
);
Address
address6
(
"[::1]:8080"
);
ASSERT_EQ
(
address6
.
host
(),
"::1"
);
ASSERT_EQ
(
address6
.
port
(),
8080
);
...
...
@@ -60,7 +60,7 @@ TEST(net_test, address_creation)
Address
address8
(
Ipv6
(
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
),
Port
(
8080
));
ASSERT_EQ
(
address8
.
host
(),
"::1"
);
ASSERT_EQ
(
address8
.
port
(),
8080
);
ASSERT_EQ
(
address8
.
port
(),
8080
);
Address
address9
(
Ipv6
::
any
(),
Port
(
8080
));
ASSERT_EQ
(
address9
.
host
(),
"::"
);
...
...
@@ -69,18 +69,18 @@ TEST(net_test, address_creation)
Address
address10
(
"[::]:8080"
);
ASSERT_EQ
(
address10
.
host
(),
"::"
);
ASSERT_EQ
(
address10
.
port
(),
8080
);
Address
address11
(
"[2001:0DB8:AABB:CCDD:EEFF:0011:2233:4455]:8080"
);
ASSERT_EQ
(
address11
.
host
(),
"2001:0DB8:AABB:CCDD:EEFF:0011:2233:4455"
);
ASSERT_EQ
(
address11
.
port
(),
8080
);
Address
address12
(
Ipv4
::
loopback
(),
Port
(
8080
));
ASSERT_EQ
(
address12
.
host
(),
"127.0.0.1"
);
ASSERT_EQ
(
address12
.
port
(),
8080
);
ASSERT_EQ
(
address12
.
port
(),
8080
);
Address
address13
(
Ipv6
::
loopback
(),
Port
(
8080
));
ASSERT_EQ
(
address13
.
host
(),
"::1"
);
ASSERT_EQ
(
address13
.
port
(),
8080
);
ASSERT_EQ
(
address13
.
port
(),
8080
);
}
TEST
(
net_test
,
invalid_address
)
...
...
@@ -89,7 +89,7 @@ TEST(net_test, invalid_address)
ASSERT_THROW
(
Address
(
"127.0.0.1:9999999"
),
std
::
invalid_argument
);
ASSERT_THROW
(
Address
(
"127.0.0.1:"
),
std
::
invalid_argument
);
ASSERT_THROW
(
Address
(
"127.0.0.1:-10"
),
std
::
invalid_argument
);
/* Due to an error in GLIBC these tests don't fail as expected, further research needed */
// ASSERT_THROW(Address("[GGGG:GGGG:GGGG:GGGG:GGGG:GGGG:GGGG:GGGG]:8080");, std::invalid_argument);
// ASSERT_THROW(Address("[::GGGG]:8080");, std::invalid_argument);
...
...
tests/payload_test.cc
View file @
ffd44ec3
...
...
@@ -28,8 +28,6 @@ struct TestSet {
typedef
std
::
vector
<
TestSet
>
PayloadTestSets
;
static
const
uint16_t
PORT
=
9080
;
void
testPayloads
(
Http
::
Client
&
client
,
std
::
string
url
,
PayloadTestSets
&
testPayloads
)
{
// Client tests to make sure the payload is enforced
std
::
mutex
resultsetMutex
;
...
...
@@ -65,56 +63,53 @@ void handleEcho(const Rest::Request&req, Http::ResponseWriter response) {
TEST
(
payload
,
from_description
)
{
const
Address
addr
(
Ipv4
::
any
(),
Port
(
0
));
const
size_t
threads
=
20
;
const
size_t
maxPayload
=
1024
;
// very small
Rest
::
Description
desc
(
"Rest Description Test"
,
"v1"
);
Rest
::
Router
router
;
desc
.
route
(
desc
.
post
(
"/"
))
.
bind
(
&
handleEcho
)
.
response
(
Http
::
Code
::
Ok
,
"Response to the /ready call"
);
router
.
initFromDescription
(
desc
);
auto
flags
=
Tcp
::
Options
::
ReuseAddr
;
auto
opts
=
Http
::
Endpoint
::
options
()
.
threads
(
threads
)
.
flags
(
flags
)
.
maxPayload
(
maxPayload
);
auto
endpoint
=
std
::
make_shared
<
Pistache
::
Http
::
Endpoint
>
(
addr
);
endpoint
->
init
(
opts
);
endpoint
->
setHandler
(
router
.
handler
());
endpoint
->
serveThreaded
();
Http
::
Client
client
;
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
maxPayload
=
1024
;
// very small
auto
pid
=
fork
();
if
(
pid
==
0
)
{
std
::
shared_ptr
<
Http
::
Endpoint
>
endpoint
;
Rest
::
Description
desc
(
"Rest Description Test"
,
"v1"
);
Rest
::
Router
router
;
desc
.
route
(
desc
.
post
(
"/"
))
.
bind
(
&
handleEcho
)
.
response
(
Http
::
Code
::
Ok
,
"Response to the /ready call"
);
router
.
initFromDescription
(
desc
);
auto
flags
=
Tcp
::
Options
::
InstallSignalHandler
|
Tcp
::
Options
::
ReuseAddr
;
auto
opts
=
Http
::
Endpoint
::
options
()
.
threads
(
threads
)
.
flags
(
flags
)
.
maxPayload
(
maxPayload
);
;
endpoint
=
std
::
make_shared
<
Pistache
::
Http
::
Endpoint
>
(
addr
);
endpoint
->
init
(
opts
);
endpoint
->
setHandler
(
router
.
handler
());
endpoint
->
serve
();
endpoint
->
shutdown
();
return
;
}
// TODO: Remove temp hack once 'serveThreaded()' waits for socket to be
// created before returning.
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
150
));
const
auto
port
=
endpoint
->
getPort
();
PayloadTestSets
payloads
{
{
800
,
Http
::
Code
::
Ok
}
,
{
1024
,
Http
::
Code
::
Request_Entity_Too_Large
}
,{
2048
,
Http
::
Code
::
Request_Entity_Too_Large
}
};
testPayloads
(
client
,
"127.0.0.1:"
+
std
::
to_string
(
PORT
),
payloads
);
kill
(
pid
,
SIGTERM
);
int
r
;
waitpid
(
pid
,
&
r
,
0
);
testPayloads
(
client
,
"127.0.0.1:"
+
std
::
to_string
(
port
),
payloads
);
client
.
shutdown
();
endpoint
->
shutdown
();
}
TEST
(
payload
,
manual_construction
)
{
...
...
@@ -133,45 +128,44 @@ TEST(payload, manual_construction) {
tag
placeholder
;
};
// General test parameters.
const
Address
addr
(
Ipv4
::
any
(),
Port
(
0
));
const
int
threads
=
20
;
const
auto
flags
=
Tcp
::
Options
::
ReuseAddr
;
const
size_t
maxPayload
=
2048
;
// Build in-process server threads.
auto
endpoint
=
std
::
make_shared
<
Http
::
Endpoint
>
(
addr
);
auto
opts
=
Http
::
Endpoint
::
options
()
.
threads
(
threads
)
.
flags
(
flags
)
.
maxPayload
(
maxPayload
);
endpoint
->
init
(
opts
);
endpoint
->
setHandler
(
Http
::
make_handler
<
MyHandler
>
());
endpoint
->
serveThreaded
();
// TODO: Remove temp hack once 'serveThreaded()' waits for socket to be
// created before returning.
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
);
Port
port
(
PORT
);
Address
addr
(
Ipv4
::
any
(),
port
);
int
threads
=
20
;
auto
flags
=
Tcp
::
Options
::
InstallSignalHandler
|
Tcp
::
Options
::
ReuseAddr
;
size_t
maxPayload
=
2048
;
auto
pid
=
fork
();
if
(
pid
==
0
)
{
auto
endpoint
=
std
::
make_shared
<
Http
::
Endpoint
>
(
addr
);
auto
opts
=
Http
::
Endpoint
::
options
()
.
threads
(
threads
)
.
flags
(
flags
)
.
maxPayload
(
maxPayload
);
;
endpoint
->
init
(
opts
);
endpoint
->
setHandler
(
Http
::
make_handler
<
MyHandler
>
());
endpoint
->
serve
();
endpoint
->
shutdown
();
return
;
}
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
);
testPayloads
(
client
,
"127.0.0.1:"
+
std
::
to_string
(
port
),
payloads
);
// Cleanup
kill
(
pid
,
SIGTERM
);
int
r
;
waitpid
(
pid
,
&
r
,
0
);
client
.
shutdown
();
endpoint
->
shutdown
();
}
tests/streaming_test.cc
View file @
ffd44ec3
...
...
@@ -14,7 +14,6 @@ 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
=
9082
;
void
dumpData
(
const
Rest
::
Request
&
req
,
Http
::
ResponseWriter
response
)
{
UNUSED
(
req
);
...
...
@@ -49,7 +48,7 @@ void dumpData(const Rest::Request&req, Http::ResponseWriter response) {
TEST
(
stream
,
from_description
)
{
Address
addr
(
Ipv4
::
any
(),
P
ORT
);
Address
addr
(
Ipv4
::
any
(),
P
ort
(
0
)
);
const
size_t
threads
=
20
;
std
::
shared_ptr
<
Http
::
Endpoint
>
endpoint
;
...
...
@@ -63,8 +62,7 @@ TEST(stream, from_description)
router
.
initFromDescription
(
desc
);
auto
flags
=
Tcp
::
Options
::
InstallSignalHandler
|
Tcp
::
Options
::
ReuseAddr
;
auto
flags
=
Tcp
::
Options
::
ReuseAddr
;
auto
opts
=
Http
::
Endpoint
::
options
()
.
threads
(
threads
)
.
flags
(
flags
)
...
...
@@ -86,7 +84,8 @@ TEST(stream, from_description)
return
size
*
nmemb
;
};
std
::
string
url
=
"http://localhost:"
+
std
::
to_string
(
PORT
)
+
"/"
;
const
auto
port
=
endpoint
->
getPort
();
std
::
string
url
=
"http://localhost:"
+
std
::
to_string
(
port
)
+
"/"
;
CURLcode
res
=
CURLE_FAILED_INIT
;
CURL
*
curl
=
curl_easy_init
();
if
(
curl
)
...
...
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