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
2a3e00c3
Commit
2a3e00c3
authored
Jan 04, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Streamline actor_lifetime test implementation
parent
65332322
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
35 deletions
+24
-35
unit_testing/test_actor_lifetime.cpp
unit_testing/test_actor_lifetime.cpp
+24
-35
No files found.
unit_testing/test_actor_lifetime.cpp
View file @
2a3e00c3
...
@@ -10,16 +10,16 @@ using std::endl;
...
@@ -10,16 +10,16 @@ using std::endl;
using
namespace
caf
;
using
namespace
caf
;
namespace
{
namespace
{
std
::
atomic
<
long
>
s_
dud
es
;
std
::
atomic
<
long
>
s_
teste
es
;
}
// namespace <anonymous>
}
// namespace <anonymous>
class
dud
e
:
public
event_based_actor
{
class
teste
e
:
public
event_based_actor
{
public:
public:
dud
e
()
{
teste
e
()
{
++
s_
dud
es
;
++
s_
teste
es
;
}
}
~
dud
e
();
~
teste
e
();
behavior
make_behavior
()
{
behavior
make_behavior
()
{
return
{
return
{
...
@@ -30,45 +30,32 @@ class dude : public event_based_actor {
...
@@ -30,45 +30,32 @@ class dude : public event_based_actor {
}
}
};
};
dude
::~
dud
e
()
{
testee
::~
teste
e
()
{
// avoid weak-vtables warning
// avoid weak-vtables warning
--
s_
dud
es
;
--
s_
teste
es
;
}
}
behavior
linking_dude
(
event_based_actor
*
self
,
const
actor
&
other_dude
)
{
template
<
class
ExitMsgType
>
behavior
tester
(
event_based_actor
*
self
,
const
actor
&
aut
)
{
CAF_CHECKPOINT
();
CAF_CHECKPOINT
();
self
->
trap_exit
(
true
);
if
(
std
::
is_same
<
ExitMsgType
,
exit_msg
>::
value
)
{
self
->
link_to
(
other_dude
);
self
->
trap_exit
(
true
);
anon_send_exit
(
other_dude
,
exit_reason
::
user_shutdown
);
self
->
link_to
(
aut
);
CAF_CHECKPOINT
();
}
else
{
return
{
self
->
monitor
(
aut
);
[
self
](
const
exit_msg
&
)
{
}
// must not been destroyed here
CAF_CHECK_EQUAL
(
s_dudes
.
load
(),
1
);
self
->
send
(
self
,
atom
(
"check"
));
},
on
(
atom
(
"check"
))
>>
[
self
]
{
// make sure dude's dtor has been called
CAF_CHECK_EQUAL
(
s_dudes
.
load
(),
0
);
self
->
quit
();
}
};
}
behavior
monitoring_dude
(
event_based_actor
*
self
,
actor
other_dude
)
{
CAF_CHECKPOINT
();
CAF_CHECKPOINT
();
self
->
monitor
(
other_dude
);
anon_send_exit
(
aut
,
exit_reason
::
user_shutdown
);
anon_send_exit
(
other_dude
,
exit_reason
::
user_shutdown
);
CAF_CHECKPOINT
();
CAF_CHECKPOINT
();
return
{
return
{
[
self
](
const
down_msg
&
)
{
[
self
](
const
ExitMsgType
&
)
{
// must not been destroyed here
// must not been destroyed here
CAF_CHECK_EQUAL
(
s_
dud
es
.
load
(),
1
);
CAF_CHECK_EQUAL
(
s_
teste
es
.
load
(),
1
);
self
->
send
(
self
,
atom
(
"check"
));
self
->
send
(
self
,
atom
(
"check"
));
},
},
on
(
atom
(
"check"
))
>>
[
self
]
{
on
(
atom
(
"check"
))
>>
[
self
]
{
// make sure dude's dtor has been called
// make sure dude's dtor has been called
CAF_CHECK_EQUAL
(
s_
dud
es
.
load
(),
0
);
CAF_CHECK_EQUAL
(
s_
teste
es
.
load
(),
0
);
self
->
quit
();
self
->
quit
();
}
}
};
};
...
@@ -76,9 +63,11 @@ behavior monitoring_dude(event_based_actor* self, actor other_dude) {
...
@@ -76,9 +63,11 @@ behavior monitoring_dude(event_based_actor* self, actor other_dude) {
template
<
spawn_options
O1
,
spawn_options
O2
>
template
<
spawn_options
O1
,
spawn_options
O2
>
void
run
()
{
void
run
()
{
spawn
<
O1
>
(
linking_dude
,
spawn
<
dude
,
O2
>
());
CAF_PRINT
(
"run test using links"
);
spawn
<
O1
>
(
tester
<
exit_msg
>
,
spawn
<
testee
,
O2
>
());
await_all_actors_done
();
await_all_actors_done
();
spawn
<
O1
>
(
monitoring_dude
,
spawn
<
dude
,
O2
>
());
CAF_PRINT
(
"run test using monitors"
);
spawn
<
O1
>
(
tester
<
down_msg
>
,
spawn
<
testee
,
O2
>
());
await_all_actors_done
();
await_all_actors_done
();
}
}
...
@@ -96,6 +85,6 @@ void test_actor_lifetime() {
...
@@ -96,6 +85,6 @@ 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_
dud
es
.
load
(),
0
);
CAF_CHECK_EQUAL
(
s_
teste
es
.
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