FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
expresscpp/test/long_session.cpp at master · expresscpp/expresscpp · GitHub
expresscpp
/
expresscpp
Public
Notifications
You must be signed in to change notification settings
Fork
15
Star
96
Code
Issues
5
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
expresscpp
/
test
/
long_session.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
70 lines (57 loc) · 1.81 KB
Breadcrumbs
expresscpp
/
test
/
long_session.cpp
Copy path
File metadata and controls
70 lines (57 loc) · 1.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#
include
"
expresscpp/expresscpp.hpp
"
#
include
"
expresscpp/fetch.hpp
"
#
include
"
fmt/format.h
"
#
include
"
gtest/gtest.h
"
#
include
"
nlohmann/json.hpp
"
#
include
"
test_utils.hpp
"
using
namespace
expresscpp
;
constexpr
uint16_t
port =
8081
;
TEST
(LongSession, SleepSession) {
ExpressCpp app;
std::string error_message =
"
Internal Error
"
;
bool
visited =
false
;
app.
Get
(
"
/users
"
, [&](
auto
/*
req
*/
,
auto
res,
auto
/*
next
*/
) {
visited =
true
;
std::this_thread::sleep_for
(
std::chrono::seconds
(
5
));
res->
Send
(
"
asdf
"
);
});
app.
Listen
(port, [&](
auto
ec) {
EXPECT_FALSE
(ec);
const
auto
should_work_response =
fetch
(
fmt::format
(
"
localhost:{}/users
"
, port));
EXPECT_TRUE
(visited);
});
}
TEST
(LongSession, LongResponsePayload) {
ExpressCpp app;
std::string error_message =
"
Internal Error
"
;
bool
visited =
false
;
app.
Get
(
"
/users
"
, [&](
auto
/*
req
*/
,
auto
res,
auto
/*
next
*/
) {
visited =
true
;
std::string
s
(
500000
,
'
a
'
);
std::cout <<
"
size of string
"
<< s.
size
() << std::endl;
res->
Send
(s);
});
app.
Listen
(port, [&](
auto
ec) {
EXPECT_FALSE
(ec);
const
auto
should_work_response =
fetch
(
fmt::format
(
"
localhost:{}/users
"
, port));
EXPECT_TRUE
(visited);
});
}
TEST
(LongSession, LongRequestPayload) {
TestCallSleeper
sleeper
(
1
);
ExpressCpp app;
std::string error_message =
"
Internal Error
"
;
constexpr
uint32_t
size_of_payload =
1024
*
1024
;
app.
Get
(
"
/users
"
, [&](
auto
req,
auto
res,
auto
/*
next
*/
) {
sleeper.
Call
();
EXPECT_EQ
(req->
getBody
().
size
(), size_of_payload);
res->
Send
(
"
ok
"
);
});
app.
Listen
(port, [&](
auto
ec) {
EXPECT_FALSE
(ec);
std::string
s
(size_of_payload,
'
a
'
);
const
FetchOptions op{ HttpMethod::Get, {}, s};
const
auto
should_work_response =
fetch
(
fmt::format
(
"
localhost:{}/users
"
, port), op);
});
EXPECT_TRUE
(sleeper.
Wait
());
}
Back
|
FazBrowse Home
|
New Git URL