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
a2660f28
Commit
a2660f28
authored
Jan 09, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix formatting
parent
00ddd026
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
166 deletions
+92
-166
libcaf_core/test/actor_lifetime.cpp
libcaf_core/test/actor_lifetime.cpp
+4
-8
libcaf_core/test/actor_pool.cpp
libcaf_core/test/actor_pool.cpp
+2
-2
libcaf_core/test/dynamic_spawn.cpp
libcaf_core/test/dynamic_spawn.cpp
+86
-156
No files found.
libcaf_core/test/actor_lifetime.cpp
View file @
a2660f28
...
...
@@ -21,9 +21,9 @@
#define CAF_SUITE actor_lifetime
#include "caf/test/unit_test.hpp"
#include <mutex>
#include <atomic>
#include <condition_variable>
#include <mutex>
#include "caf/all.hpp"
...
...
@@ -62,9 +62,7 @@ public:
behavior
make_behavior
()
override
{
return
{
[
=
](
int
x
)
{
return
x
;
}
[
=
](
int
x
)
{
return
x
;
},
};
}
};
...
...
@@ -108,12 +106,10 @@ behavior tester(event_based_actor* self, const actor& aut) {
CAF_CHECK_EQUAL
(
s_testees
.
load
(),
0
);
CAF_CHECK_EQUAL
(
s_pending_on_exits
.
load
(),
0
);
self
->
quit
();
}
}
,
};
}
struct
config
:
actor_system_config
{
config
()
{
set
(
"scheduler.policy"
,
"testing"
);
...
...
@@ -163,7 +159,7 @@ struct fixture {
}
// Run the exit_msg.
sched
.
run_once
();
//expect((exit_msg), from(tst_driver).to(tst_subject));
//
expect((exit_msg), from(tst_driver).to(tst_subject));
{
// Resume driver.
std
::
unique_lock
<
std
::
mutex
>
guard
{
s_mtx
};
s_testee_cleanup_done
=
true
;
...
...
libcaf_core/test/actor_pool.cpp
View file @
a2660f28
...
...
@@ -86,8 +86,8 @@ CAF_TEST_FIXTURE_SCOPE(actor_pool_tests, fixture)
CAF_TEST
(
round_robin_actor_pool
)
{
scoped_actor
self
{
system
};
auto
pool
=
actor_pool
::
make
(
&
context
,
5
,
spawn_worker
,
actor_pool
::
round_robin
());
auto
pool
=
actor_pool
::
make
(
&
context
,
5
,
spawn_worker
,
actor_pool
::
round_robin
());
self
->
send
(
pool
,
sys_atom_v
,
put_atom_v
,
spawn_worker
());
std
::
vector
<
actor
>
workers
;
for
(
int
i
=
0
;
i
<
6
;
++
i
)
{
...
...
libcaf_core/test/dynamic_spawn.cpp
View file @
a2660f28
...
...
@@ -57,30 +57,12 @@ class event_testee : public event_based_actor {
public:
event_testee
(
actor_config
&
cfg
)
:
event_based_actor
(
cfg
)
{
inc_actor_instances
();
wait4string
.
assign
(
[
=
](
const
std
::
string
&
)
{
become
(
wait4int
);
},
[
=
](
get_atom
)
{
return
"wait4string"
;
}
);
wait4float
.
assign
(
[
=
](
float
)
{
become
(
wait4string
);
},
[
=
](
get_atom
)
{
return
"wait4float"
;
}
);
wait4int
.
assign
(
[
=
](
int
)
{
become
(
wait4float
);
},
[
=
](
get_atom
)
{
return
"wait4int"
;
}
);
wait4string
.
assign
([
=
](
const
std
::
string
&
)
{
become
(
wait4int
);
},
[
=
](
get_atom
)
{
return
"wait4string"
;
});
wait4float
.
assign
([
=
](
float
)
{
become
(
wait4string
);
},
[
=
](
get_atom
)
{
return
"wait4float"
;
});
wait4int
.
assign
([
=
](
int
)
{
become
(
wait4float
);
},
[
=
](
get_atom
)
{
return
"wait4int"
;
});
}
~
event_testee
()
override
{
...
...
@@ -101,8 +83,7 @@ actor spawn_event_testee2(scoped_actor& parent) {
struct
wrapper
:
event_based_actor
{
actor
parent
;
wrapper
(
actor_config
&
cfg
,
actor
parent_actor
)
:
event_based_actor
(
cfg
),
parent
(
std
::
move
(
parent_actor
))
{
:
event_based_actor
(
cfg
),
parent
(
std
::
move
(
parent_actor
))
{
inc_actor_instances
();
}
~
wrapper
()
override
{
...
...
@@ -110,14 +91,15 @@ actor spawn_event_testee2(scoped_actor& parent) {
}
behavior
wait4timeout
(
int
remaining
)
{
return
{
after
(
chrono
::
milliseconds
(
1
))
>>
[
=
]
{
after
(
chrono
::
milliseconds
(
1
))
>>
[
=
]
{
CAF_MESSAGE
(
"remaining: "
<<
to_string
(
remaining
));
if
(
remaining
==
1
)
{
send
(
parent
,
ok_atom_v
);
quit
();
}
else
become
(
wait4timeout
(
remaining
-
1
));
}
}
else
become
(
wait4timeout
(
remaining
-
1
));
},
};
}
behavior
make_behavior
()
override
{
...
...
@@ -139,46 +121,28 @@ public:
void
act
()
override
{
bool
running
=
true
;
receive_while
(
running
)
(
[
&
](
int
)
{
wait4float
();
},
[
&
](
get_atom
)
{
return
"wait4int"
;
},
receive_while
(
running
)([
&
](
int
)
{
wait4float
();
},
[
&
](
get_atom
)
{
return
"wait4int"
;
},
[
&
](
exit_msg
&
em
)
{
if
(
em
.
reason
)
{
fail_state
(
std
::
move
(
em
.
reason
));
running
=
false
;
}
}
);
});
}
private:
void
wait4string
()
{
bool
string_received
=
false
;
do_receive
(
[
&
](
const
string
&
)
{
string_received
=
true
;
},
[
&
](
get_atom
)
{
return
"wait4string"
;
}
)
do_receive
([
&
](
const
string
&
)
{
string_received
=
true
;
},
[
&
](
get_atom
)
{
return
"wait4string"
;
})
.
until
([
&
]
{
return
string_received
;
});
}
void
wait4float
()
{
bool
float_received
=
false
;
do_receive
(
[
&
](
float
)
{
float_received
=
true
;
},
[
&
](
get_atom
)
{
return
"wait4float"
;
}
)
do_receive
([
&
](
float
)
{
float_received
=
true
;
},
[
&
](
get_atom
)
{
return
"wait4float"
;
})
.
until
([
&
]
{
return
float_received
;
});
wait4string
();
}
...
...
@@ -197,9 +161,7 @@ public:
behavior
make_behavior
()
override
{
return
{
after
(
chrono
::
milliseconds
(
10
))
>>
[
=
]
{
unbecome
();
}
after
(
chrono
::
milliseconds
(
10
))
>>
[
=
]
{
unbecome
();
},
};
}
};
...
...
@@ -219,7 +181,7 @@ public:
return
{
[]
{
// nop
}
}
,
};
}
};
...
...
@@ -239,18 +201,18 @@ public:
return
{
[]
{
// nop
}
}
,
};
}
};
behavior
master
(
event_based_actor
*
self
)
{
return
(
return
{
[
=
](
ok_atom
)
{
CAF_MESSAGE
(
"master: received done"
);
self
->
quit
(
exit_reason
::
user_shutdown
);
}
)
;
}
,
}
;
}
behavior
slave
(
event_based_actor
*
self
,
const
actor
&
master
)
{
...
...
@@ -262,7 +224,7 @@ behavior slave(event_based_actor* self, const actor& master) {
return
{
[]
{
// nop
}
}
,
};
}
...
...
@@ -292,7 +254,9 @@ public:
struct
fixture
{
actor_system_config
cfg
;
// put inside a union to control ctor/dtor timing
union
{
actor_system
system
;
};
union
{
actor_system
system
;
};
fixture
()
{
new
(
&
system
)
actor_system
(
cfg
);
...
...
@@ -349,38 +313,30 @@ CAF_TEST(detached_actors_and_schedulued_actors) {
CAF_TEST
(
self_receive_with_zero_timeout
)
{
scoped_actor
self
{
system
};
self
->
receive
(
[
&
]
{
CAF_ERROR
(
"Unexpected message"
);
},
after
(
chrono
::
seconds
(
0
))
>>
[]
{
self
->
receive
([
&
]
{
CAF_ERROR
(
"Unexpected message"
);
},
after
(
chrono
::
seconds
(
0
))
>>
[]
{
// mailbox empty
}
);
});
}
CAF_TEST
(
detached_mirror
)
{
scoped_actor
self
{
system
};
auto
mirror
=
self
->
spawn
<
simple_mirror
,
detached
>
();
self
->
send
(
mirror
,
"hello mirror"
);
self
->
receive
(
[](
const
std
::
string
&
msg
)
{
CAF_CHECK_EQUAL
(
msg
,
"hello mirror"
);
}
);
self
->
receive
(
[](
const
std
::
string
&
msg
)
{
CAF_CHECK_EQUAL
(
msg
,
"hello mirror"
);
});
}
CAF_TEST
(
send_to_self
)
{
scoped_actor
self
{
system
};
self
->
send
(
self
,
1
,
2
,
3
,
true
);
self
->
receive
(
[](
int
a
,
int
b
,
int
c
,
bool
d
)
{
self
->
receive
([](
int
a
,
int
b
,
int
c
,
bool
d
)
{
CAF_CHECK_EQUAL
(
a
,
1
);
CAF_CHECK_EQUAL
(
b
,
2
);
CAF_CHECK_EQUAL
(
c
,
3
);
CAF_CHECK_EQUAL
(
d
,
true
);
}
);
});
self
->
send
(
self
,
message
{});
self
->
receive
([]
{});
}
...
...
@@ -390,63 +346,44 @@ CAF_TEST(echo_actor_messaging) {
auto
mecho
=
system
.
spawn
<
echo_actor
>
();
self
->
send
(
mecho
,
"hello echo"
);
self
->
receive
(
[](
const
std
::
string
&
arg
)
{
CAF_CHECK_EQUAL
(
arg
,
"hello echo"
);
}
);
[](
const
std
::
string
&
arg
)
{
CAF_CHECK_EQUAL
(
arg
,
"hello echo"
);
});
}
CAF_TEST
(
delayed_send
)
{
scoped_actor
self
{
system
};
self
->
delayed_send
(
self
,
chrono
::
milliseconds
(
1
),
1
,
2
,
3
);
self
->
receive
(
[](
int
a
,
int
b
,
int
c
)
{
self
->
receive
([](
int
a
,
int
b
,
int
c
)
{
CAF_CHECK_EQUAL
(
a
,
1
);
CAF_CHECK_EQUAL
(
b
,
2
);
CAF_CHECK_EQUAL
(
c
,
3
);
}
);
});
}
CAF_TEST
(
delayed_spawn
)
{
scoped_actor
self
{
system
};
self
->
receive
(
after
(
chrono
::
milliseconds
(
1
))
>>
[]
{
});
self
->
receive
(
after
(
chrono
::
milliseconds
(
1
))
>>
[]
{});
system
.
spawn
<
testee1
>
();
}
CAF_TEST
(
spawn_event_testee2_test
)
{
scoped_actor
self
{
system
};
spawn_event_testee2
(
self
);
self
->
receive
(
[](
ok_atom
)
{
CAF_MESSAGE
(
"Received 'ok'"
);
}
);
self
->
receive
([](
ok_atom
)
{
CAF_MESSAGE
(
"Received 'ok'"
);
});
}
CAF_TEST
(
function_spawn
)
{
scoped_actor
self
{
system
};
auto
f
=
[](
const
string
&
name
)
->
behavior
{
return
(
[
name
](
get_atom
)
{
return
std
::
make_tuple
(
name_atom_v
,
name
);
}
);
return
([
name
](
get_atom
)
{
return
std
::
make_tuple
(
name_atom_v
,
name
);
});
};
auto
a1
=
system
.
spawn
(
f
,
"alice"
);
auto
a2
=
system
.
spawn
(
f
,
"bob"
);
self
->
send
(
a1
,
get_atom_v
);
self
->
receive
(
[
&
](
name_atom
,
const
string
&
name
)
{
CAF_CHECK_EQUAL
(
name
,
"alice"
);
}
);
self
->
receive
(
[
&
](
name_atom
,
const
string
&
name
)
{
CAF_CHECK_EQUAL
(
name
,
"alice"
);
});
self
->
send
(
a2
,
get_atom_v
);
self
->
receive
(
[
&
](
name_atom
,
const
string
&
name
)
{
CAF_CHECK_EQUAL
(
name
,
"bob"
);
}
);
self
->
receive
(
[
&
](
name_atom
,
const
string
&
name
)
{
CAF_CHECK_EQUAL
(
name
,
"bob"
);
});
self
->
send_exit
(
a1
,
exit_reason
::
user_shutdown
);
self
->
send_exit
(
a2
,
exit_reason
::
user_shutdown
);
}
...
...
@@ -454,12 +391,10 @@ CAF_TEST(function_spawn) {
using
typed_testee
=
typed_actor
<
replies_to
<
abc_atom
>::
with
<
std
::
string
>>
;
typed_testee
::
behavior_type
testee
()
{
return
{
[](
abc_atom
)
{
return
{[](
abc_atom
)
{
CAF_MESSAGE
(
"received 'abc'"
);
return
"abc"
;
}
};
}};
}
CAF_TEST
(
typed_await
)
{
...
...
@@ -473,18 +408,16 @@ CAF_TEST(constructor_attach) {
class
testee
:
public
event_based_actor
{
public:
testee
(
actor_config
&
cfg
,
actor
buddy
)
:
event_based_actor
(
cfg
),
buddy_
(
buddy
)
{
attach_functor
([
=
](
const
error
&
reason
)
{
send
(
buddy
,
ok_atom_v
,
reason
);
});
:
event_based_actor
(
cfg
),
buddy_
(
buddy
)
{
attach_functor
(
[
=
](
const
error
&
reason
)
{
send
(
buddy
,
ok_atom_v
,
reason
);
});
}
behavior
make_behavior
()
override
{
return
{
[]
{
// nop
}
}
,
};
}
...
...
@@ -506,9 +439,8 @@ CAF_TEST(constructor_attach) {
if
(
++
downs_
==
2
)
quit
(
msg
.
reason
);
});
set_exit_handler
([
=
](
exit_msg
&
msg
)
{
send_exit
(
testee_
,
std
::
move
(
msg
.
reason
));
});
set_exit_handler
(
[
=
](
exit_msg
&
msg
)
{
send_exit
(
testee_
,
std
::
move
(
msg
.
reason
));
});
}
behavior
make_behavior
()
override
{
...
...
@@ -541,7 +473,7 @@ CAF_TEST(kill_the_immortal) {
return
{
[]
{
// nop
}
}
,
};
});
scoped_actor
self
{
system
};
...
...
@@ -554,18 +486,16 @@ CAF_TEST(move_only_argument) {
unique_int
uptr
{
new
int
(
42
)};
auto
wrapper
=
[](
event_based_actor
*
self
,
unique_int
ptr
)
->
behavior
{
auto
i
=
*
ptr
;
return
{
[
=
](
float
)
{
return
{[
=
](
float
)
{
self
->
quit
();
return
i
;
}
};
}};
};
auto
f
=
make_function_view
(
system
.
spawn
(
wrapper
,
std
::
move
(
uptr
)));
CAF_CHECK_EQUAL
(
to_string
(
f
(
1.
f
)),
"(42)"
);
}
CAF_TEST
(
move
-
only
function
object
)
{
CAF_TEST
(
move
-
only
function
object
)
{
struct
move_only_fun
{
move_only_fun
()
=
default
;
move_only_fun
(
const
move_only_fun
&
)
=
delete
;
...
...
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