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
f4f8269a
Commit
f4f8269a
authored
Feb 16, 2019
by
knowledge4igor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add first reactor test
parent
89ff57be
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
0 deletions
+101
-0
tests/CMakeLists.txt
tests/CMakeLists.txt
+1
-0
tests/reactor_test.cc
tests/reactor_test.cc
+100
-0
No files found.
tests/CMakeLists.txt
View file @
f4f8269a
...
...
@@ -29,6 +29,7 @@ pistache_test(rest_server_test)
pistache_test
(
string_view_test
)
pistache_test
(
mailbox_test
)
pistache_test
(
stream_test
)
pistache_test
(
reactor_test
)
if
(
PISTACHE_SSL
)
...
...
tests/reactor_test.cc
0 → 100644
View file @
f4f8269a
#include <pistache/reactor.h>
#include <pistache/mailbox.h>
#include "gtest/gtest.h"
#include <memory>
#include <iostream>
#include <thread>
#include <chrono>
#include <unordered_set>
using
namespace
Pistache
;
class
TransportMock
:
public
Aio
::
Handler
{
PROTOTYPE_OF
(
Aio
::
Handler
,
TransportMock
)
public:
TransportMock
()
:
queue_
()
{
}
TransportMock
(
const
TransportMock
&
)
:
queue_
()
{
}
void
onReady
(
const
Aio
::
FdSet
&
fds
)
override
{
for
(
const
auto
&
entry
:
fds
)
{
if
(
entry
.
getTag
()
==
queue_
.
tag
())
{
while
(
true
)
{
auto
value
=
queue_
.
popSafe
();
if
(
!
value
)
break
;
values_
.
insert
(
*
value
);
}
}
}
}
void
registerPoller
(
Polling
::
Epoll
&
poller
)
override
{
queue_
.
bind
(
poller
);
}
void
push
(
int
value
)
{
queue_
.
push
(
value
);
}
const
std
::
unordered_set
<
int
>&
values
()
{
return
values_
;
}
private:
PollableQueue
<
int
>
queue_
;
std
::
unordered_set
<
int
>
values_
;
};
TEST
(
reactor_test
,
reactor_creation
)
{
const
size_t
NUM_THREADS
=
2
;
std
::
shared_ptr
<
Aio
::
Reactor
>
reactor
=
Aio
::
Reactor
::
create
();
reactor
->
init
(
Aio
::
AsyncContext
(
NUM_THREADS
));
auto
key
=
reactor
->
addHandler
(
std
::
make_shared
<
TransportMock
>
());
reactor
->
run
();
auto
handlers
=
reactor
->
handlers
(
key
);
ASSERT_EQ
(
handlers
.
size
(),
NUM_THREADS
);
const
size_t
NUM_VALUES
=
4
;
int
values
[
NUM_THREADS
][
NUM_VALUES
]
=
{
{
1
,
2
,
3
,
4
},
{
5
,
6
,
7
,
8
}
};
for
(
size_t
i
=
0
;
i
<
handlers
.
size
();
++
i
)
{
auto
transport
=
std
::
static_pointer_cast
<
TransportMock
>
(
handlers
[
i
]);
for
(
size_t
j
=
0
;
j
<
NUM_VALUES
;
++
j
)
{
transport
->
push
(
values
[
i
][
j
]);
}
}
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
1
));
reactor
->
shutdown
();
for
(
size_t
i
=
0
;
i
<
handlers
.
size
();
++
i
)
{
auto
transport
=
std
::
static_pointer_cast
<
TransportMock
>
(
handlers
[
i
]);
const
auto
&
resulted_values
=
transport
->
values
();
for
(
size_t
j
=
0
;
j
<
NUM_VALUES
;
++
j
)
{
ASSERT_NE
(
resulted_values
.
find
(
values
[
i
][
j
]),
resulted_values
.
end
());
}
}
}
\ No newline at end of file
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