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
1f3e8d3c
Commit
1f3e8d3c
authored
Feb 03, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test whether `on_exit()` is called correctly
parent
dba99a67
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
15 deletions
+33
-15
unit_testing/test_actor_lifetime.cpp
unit_testing/test_actor_lifetime.cpp
+33
-15
No files found.
unit_testing/test_actor_lifetime.cpp
View file @
1f3e8d3c
...
@@ -11,30 +11,39 @@ using namespace caf;
...
@@ -11,30 +11,39 @@ using namespace caf;
namespace
{
namespace
{
std
::
atomic
<
long
>
s_testees
;
std
::
atomic
<
long
>
s_testees
;
std
::
atomic
<
long
>
s_pending_on_exits
;
}
// namespace <anonymous>
}
// namespace <anonymous>
class
testee
:
public
event_based_actor
{
class
testee
:
public
event_based_actor
{
public:
public:
testee
()
{
testee
();
++
s_testees
;
}
~
testee
();
~
testee
();
void
on_exit
();
behavior
make_behavior
()
{
behavior
make_behavior
()
override
;
return
{
others
()
>>
[
=
]
{
return
last_dequeued
();
}
};
}
};
};
testee
::
testee
()
{
++
s_testees
;
++
s_pending_on_exits
;
}
testee
::~
testee
()
{
testee
::~
testee
()
{
// avoid weak-vtables warning
// avoid weak-vtables warning
--
s_testees
;
--
s_testees
;
}
}
void
testee
::
on_exit
()
{
--
s_pending_on_exits
;
}
behavior
testee
::
make_behavior
()
{
return
{
others
()
>>
[
=
]
{
return
last_dequeued
();
}
};
}
template
<
class
ExitMsgType
>
template
<
class
ExitMsgType
>
behavior
tester
(
event_based_actor
*
self
,
const
actor
&
aut
)
{
behavior
tester
(
event_based_actor
*
self
,
const
actor
&
aut
)
{
CAF_CHECKPOINT
();
CAF_CHECKPOINT
();
...
@@ -48,9 +57,12 @@ behavior tester(event_based_actor* self, const actor& aut) {
...
@@ -48,9 +57,12 @@ behavior tester(event_based_actor* self, const actor& aut) {
anon_send_exit
(
aut
,
exit_reason
::
user_shutdown
);
anon_send_exit
(
aut
,
exit_reason
::
user_shutdown
);
CAF_CHECKPOINT
();
CAF_CHECKPOINT
();
return
{
return
{
[
self
](
const
ExitMsgType
&
)
{
[
self
](
const
ExitMsgType
&
msg
)
{
// must be still alive at this point
// must be still alive at this point
CAF_CHECK_EQUAL
(
s_testees
.
load
(),
1
);
CAF_CHECK_EQUAL
(
s_testees
.
load
(),
1
);
CAF_CHECK_EQUAL
(
msg
.
reason
,
exit_reason
::
user_shutdown
);
CAF_CHECK_EQUAL
(
self
->
last_dequeued
().
vals
()
->
get_reference_count
(),
1
);
CAF_CHECK
(
&
msg
==
self
->
last_dequeued
().
at
(
0
));
// testee might be still running its cleanup code in
// testee might be still running its cleanup code in
// another worker thread; by waiting some milliseconds, we make sure
// another worker thread; by waiting some milliseconds, we make sure
// testee had enough time to return control to the scheduler
// testee had enough time to return control to the scheduler
...
@@ -59,18 +71,22 @@ behavior tester(event_based_actor* self, const actor& aut) {
...
@@ -59,18 +71,22 @@ behavior tester(event_based_actor* self, const actor& aut) {
check_atom
::
value
);
check_atom
::
value
);
},
},
[
self
](
check_atom
)
{
[
self
](
check_atom
)
{
// make sure
dude's dtor has
been called
// make sure
aut's dtor and on_exit() have
been called
CAF_CHECK_EQUAL
(
s_testees
.
load
(),
0
);
CAF_CHECK_EQUAL
(
s_testees
.
load
(),
0
);
CAF_CHECK_EQUAL
(
s_pending_on_exits
.
load
(),
0
);
self
->
quit
();
self
->
quit
();
}
}
};
};
}
}
#define BREAK_ON_ERROR() if (CAF_TEST_RESULT() > 0) return
template
<
spawn_options
O1
,
spawn_options
O2
>
template
<
spawn_options
O1
,
spawn_options
O2
>
void
run
()
{
void
run
()
{
CAF_PRINT
(
"run test using links"
);
CAF_PRINT
(
"run test using links"
);
spawn
<
O1
>
(
tester
<
exit_msg
>
,
spawn
<
testee
,
O2
>
());
spawn
<
O1
>
(
tester
<
exit_msg
>
,
spawn
<
testee
,
O2
>
());
await_all_actors_done
();
await_all_actors_done
();
BREAK_ON_ERROR
();
CAF_PRINT
(
"run test using monitors"
);
CAF_PRINT
(
"run test using monitors"
);
spawn
<
O1
>
(
tester
<
down_msg
>
,
spawn
<
testee
,
O2
>
());
spawn
<
O1
>
(
tester
<
down_msg
>
,
spawn
<
testee
,
O2
>
());
await_all_actors_done
();
await_all_actors_done
();
...
@@ -79,10 +95,13 @@ void run() {
...
@@ -79,10 +95,13 @@ void run() {
void
test_actor_lifetime
()
{
void
test_actor_lifetime
()
{
CAF_PRINT
(
"run<no_spawn_options, no_spawn_options>"
);
CAF_PRINT
(
"run<no_spawn_options, no_spawn_options>"
);
run
<
no_spawn_options
,
no_spawn_options
>
();
run
<
no_spawn_options
,
no_spawn_options
>
();
BREAK_ON_ERROR
();
CAF_PRINT
(
"run<detached, no_spawn_options>"
);
CAF_PRINT
(
"run<detached, no_spawn_options>"
);
run
<
detached
,
no_spawn_options
>
();
run
<
detached
,
no_spawn_options
>
();
BREAK_ON_ERROR
();
CAF_PRINT
(
"run<no_spawn_options, detached>"
);
CAF_PRINT
(
"run<no_spawn_options, detached>"
);
run
<
no_spawn_options
,
detached
>
();
run
<
no_spawn_options
,
detached
>
();
BREAK_ON_ERROR
();
CAF_PRINT
(
"run<detached, detached>"
);
CAF_PRINT
(
"run<detached, detached>"
);
run
<
detached
,
detached
>
();
run
<
detached
,
detached
>
();
}
}
...
@@ -90,6 +109,5 @@ void test_actor_lifetime() {
...
@@ -90,6 +109,5 @@ void test_actor_lifetime() {
int
main
()
{
int
main
()
{
CAF_TEST
(
test_actor_lifetime
);
CAF_TEST
(
test_actor_lifetime
);
test_actor_lifetime
();
test_actor_lifetime
();
CAF_CHECK_EQUAL
(
s_testees
.
load
(),
0
);
return
CAF_TEST_RESULT
();
return
CAF_TEST_RESULT
();
}
}
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