Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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
cpp-libs
Actor Framework
Commits
d38672e7
Commit
d38672e7
authored
Mar 14, 2017
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make local group test more readable
parent
087bf895
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
48 deletions
+32
-48
libcaf_core/test/local_group.cpp
libcaf_core/test/local_group.cpp
+32
-48
No files found.
libcaf_core/test/local_group.cpp
View file @
d38672e7
...
...
@@ -22,7 +22,9 @@
#define CAF_SUITE local_group
#include "caf/test/unit_test.hpp"
#include <array>
#include <chrono>
#include <algorithm>
#include "caf/all.hpp"
...
...
@@ -33,45 +35,24 @@ namespace {
using
msg_atom
=
atom_constant
<
atom
(
"msg"
)
>
;
using
timeout_atom
=
atom_constant
<
atom
(
"timeout"
)
>
;
class
testee1
:
public
event_based_actor
{
public:
testee1
(
actor_config
&
cfg
)
:
event_based_actor
(
cfg
),
x_
(
0
)
{
// nop
}
behavior
make_behavior
()
override
{
return
{
[
=
](
put_atom
,
int
x
)
{
x_
=
x
;
},
[
=
](
get_atom
)
{
return
x_
;
}
};
}
private:
int
x_
;
};
using
testee_if
=
typed_actor
<
replies_to
<
get_atom
>::
with
<
int
>
,
reacts_to
<
put_atom
,
int
>>
;
struct
testee_state
{
int
x
=
0
;
};
behavior
testee2
(
event_based_actor
*
self
)
{
auto
counter
=
std
::
make_shared
<
int
>
(
0
);
auto
grp
=
self
->
system
().
groups
().
get_local
(
"test"
);
self
->
join
(
grp
);
CAF_MESSAGE
(
"self joined group"
);
self
->
send
(
grp
,
msg_atom
::
value
);
behavior
testee_impl
(
stateful_actor
<
testee_state
>*
self
)
{
auto
subscriptions
=
self
->
joined_groups
();
return
{
[
=
](
msg_atom
)
{
CAF_MESSAGE
(
"received `msg_atom`"
);
++*
counter
;
self
->
leave
(
grp
);
self
->
send
(
grp
,
msg_atom
::
value
);
self
->
send
(
self
,
timeout_atom
::
value
);
[
=
](
put_atom
,
int
x
)
{
self
->
state
.
x
=
x
;
},
[
=
](
timeout_atom
)
{
// this actor should receive only 1 message
CAF_CHECK_EQUAL
(
*
counter
,
1
);
self
->
quit
();
[
=
](
get_atom
)
{
return
self
->
state
.
x
;
}
};
}
}
;
struct
fixture
{
actor_system_config
config
;
...
...
@@ -83,24 +64,27 @@ struct fixture {
CAF_TEST_FIXTURE_SCOPE
(
group_tests
,
fixture
)
CAF_TEST
(
function_based_self_joining
)
{
system
.
spawn
(
testee2
);
}
CAF_TEST
(
class_based_joined_at_spawn
)
{
auto
grp
=
system
.
groups
().
get_local
(
"test"
);
auto
tst
=
system
.
spawn_in_group
<
testee1
>
(
grp
);
// initialize all testee actors, spawning them in the group
std
::
array
<
actor
,
10
>
xs
;
for
(
auto
&
x
:
xs
)
x
=
system
.
spawn_in_group
(
grp
,
testee_impl
);
// get a function view for all testees
std
::
array
<
function_view
<
testee_if
>
,
10
>
fs
;
std
::
transform
(
xs
.
begin
(),
xs
.
end
(),
fs
.
begin
(),
[](
const
actor
&
x
)
{
return
make_function_view
(
actor_cast
<
testee_if
>
(
x
));
});
// make sure all actors start at 0
for
(
auto
&
f
:
fs
)
CAF_CHECK_EQUAL
(
f
(
get_atom
::
value
),
0
);
// send a put to all actors via the group and make sure they change state
self
->
send
(
grp
,
put_atom
::
value
,
42
);
self
->
request
(
tst
,
infinite
,
get_atom
::
value
).
receive
(
[
&
](
int
x
)
{
CAF_REQUIRE_EQUAL
(
x
,
42
);
},
[
&
](
const
error
&
e
)
{
CAF_FAIL
(
"error: "
<<
system
.
render
(
e
));
}
);
// groups holds a reference to testee, stop manually
self
->
send_exit
(
tst
,
exit_reason
::
user_shutdown
);
for
(
auto
&
f
:
fs
)
CAF_CHECK_EQUAL
(
f
(
get_atom
::
value
),
42
);
// shutdown all actors
for
(
auto
&
x
:
xs
)
self
->
send_exit
(
x
,
exit_reason
::
user_shutdown
);
}
CAF_TEST_FIXTURE_SCOPE_END
()
...
...
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