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
42f463c9
Commit
42f463c9
authored
Jan 25, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port test coordinator to new clock API
parent
2f308ccb
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
53 deletions
+33
-53
libcaf_core/caf/detail/test_actor_clock.hpp
libcaf_core/caf/detail/test_actor_clock.hpp
+9
-0
libcaf_core/caf/scheduler/test_coordinator.hpp
libcaf_core/caf/scheduler/test_coordinator.hpp
+0
-11
libcaf_core/src/test_actor_clock.cpp
libcaf_core/src/test_actor_clock.cpp
+21
-0
libcaf_core/src/test_coordinator.cpp
libcaf_core/src/test_coordinator.cpp
+2
-38
libcaf_core/test/request_timeout.cpp
libcaf_core/test/request_timeout.cpp
+1
-3
libcaf_core/test/simple_timeout.cpp
libcaf_core/test/simple_timeout.cpp
+0
-1
No files found.
libcaf_core/caf/detail/test_actor_clock.hpp
View file @
42f463c9
...
@@ -30,6 +30,15 @@ public:
...
@@ -30,6 +30,15 @@ public:
time_point
now
()
const
noexcept
override
;
time_point
now
()
const
noexcept
override
;
/// Tries to dispatch the next timeout or delayed message regardless of its
/// timestamp. Returns `false` if `schedule().empty()`, otherwise `true`.
bool
dispatch_once
();
/// Dispatches all timeouts and delayed messages regardless of their
/// timestamp. Returns the number of dispatched events.
size_t
dispatch
();
/// Advances the time by `x` and dispatches timeouts and delayed messages.
void
advance_time
(
duration_type
x
);
void
advance_time
(
duration_type
x
);
};
};
...
...
libcaf_core/caf/scheduler/test_coordinator.hpp
View file @
42f463c9
...
@@ -45,20 +45,9 @@ public:
...
@@ -45,20 +45,9 @@ public:
/// A double-ended queue representing our current job queue.
/// A double-ended queue representing our current job queue.
std
::
deque
<
resumable
*>
jobs
;
std
::
deque
<
resumable
*>
jobs
;
/// A scheduled message or timeout.
struct
delayed_msg
{
strong_actor_ptr
from
;
strong_actor_ptr
to
;
message_id
mid
;
message
msg
;
};
/// A clock type using the highest available precision.
/// A clock type using the highest available precision.
using
hrc
=
std
::
chrono
::
high_resolution_clock
;
using
hrc
=
std
::
chrono
::
high_resolution_clock
;
/// A map type for storing scheduled messages and timeouts.
std
::
multimap
<
hrc
::
time_point
,
delayed_msg
>
delayed_messages
;
/// Returns whether at least one job is in the queue.
/// Returns whether at least one job is in the queue.
inline
bool
has_job
()
const
{
inline
bool
has_job
()
const
{
return
!
jobs
.
empty
();
return
!
jobs
.
empty
();
...
...
libcaf_core/src/test_actor_clock.cpp
View file @
42f463c9
...
@@ -25,6 +25,27 @@ test_actor_clock::time_point test_actor_clock::now() const noexcept {
...
@@ -25,6 +25,27 @@ test_actor_clock::time_point test_actor_clock::now() const noexcept {
return
current_time
;
return
current_time
;
}
}
bool
test_actor_clock
::
dispatch_once
()
{
if
(
schedule_
.
empty
())
return
false
;
visitor
f
{
this
};
auto
i
=
schedule_
.
begin
();
visit
(
f
,
i
->
second
);
schedule_
.
erase
(
i
);
return
true
;
}
size_t
test_actor_clock
::
dispatch
()
{
if
(
schedule_
.
empty
())
return
0u
;
visitor
f
{
this
};
auto
result
=
schedule_
.
size
();
for
(
auto
&
kvp
:
schedule_
)
visit
(
f
,
kvp
.
second
);
schedule_
.
clear
();
return
result
;
}
void
test_actor_clock
::
advance_time
(
duration_type
x
)
{
void
test_actor_clock
::
advance_time
(
duration_type
x
)
{
visitor
f
{
this
};
visitor
f
{
this
};
current_time
+=
x
;
current_time
+=
x
;
...
...
libcaf_core/src/test_coordinator.cpp
View file @
42f463c9
...
@@ -62,33 +62,6 @@ private:
...
@@ -62,33 +62,6 @@ private:
message_handler
mh_
;
message_handler
mh_
;
};
};
class
dummy_timer
:
public
monitorable_actor
{
public:
dummy_timer
(
actor_config
&
cfg
,
test_coordinator
*
parent
)
:
monitorable_actor
(
cfg
),
parent_
(
parent
)
{
mh_
.
assign
(
[
&
](
const
duration
&
d
,
strong_actor_ptr
&
from
,
strong_actor_ptr
&
to
,
message_id
mid
,
message
&
msg
)
{
auto
tout
=
test_coordinator
::
hrc
::
now
();
tout
+=
d
;
using
delayed_msg
=
test_coordinator
::
delayed_msg
;
parent_
->
delayed_messages
.
emplace
(
tout
,
delayed_msg
{
std
::
move
(
from
),
std
::
move
(
to
),
mid
,
std
::
move
(
msg
)});
}
);
}
void
enqueue
(
mailbox_element_ptr
what
,
execution_unit
*
)
override
{
mh_
(
what
->
content
());
}
private:
test_coordinator
*
parent_
;
message_handler
mh_
;
};
}
// namespace <anonymous>
}
// namespace <anonymous>
test_coordinator
::
test_coordinator
(
actor_system
&
sys
)
:
super
(
sys
)
{
test_coordinator
::
test_coordinator
(
actor_system
&
sys
)
:
super
(
sys
)
{
...
@@ -173,20 +146,11 @@ size_t test_coordinator::run(size_t max_count) {
...
@@ -173,20 +146,11 @@ size_t test_coordinator::run(size_t max_count) {
}
}
bool
test_coordinator
::
dispatch_once
()
{
bool
test_coordinator
::
dispatch_once
()
{
auto
i
=
delayed_messages
.
begin
();
return
clock
().
dispatch_once
();
if
(
i
==
delayed_messages
.
end
())
return
false
;
auto
&
dm
=
i
->
second
;
dm
.
to
->
enqueue
(
dm
.
from
,
dm
.
mid
,
std
::
move
(
dm
.
msg
),
nullptr
);
delayed_messages
.
erase
(
i
);
return
true
;
}
}
size_t
test_coordinator
::
dispatch
()
{
size_t
test_coordinator
::
dispatch
()
{
size_t
res
=
0
;
return
clock
().
dispatch
();
while
(
dispatch_once
())
++
res
;
return
res
;
}
}
std
::
pair
<
size_t
,
size_t
>
test_coordinator
::
run_dispatch_loop
()
{
std
::
pair
<
size_t
,
size_t
>
test_coordinator
::
run_dispatch_loop
()
{
...
...
libcaf_core/test/request_timeout.cpp
View file @
42f463c9
...
@@ -280,7 +280,6 @@ struct fixture {
...
@@ -280,7 +280,6 @@ struct fixture {
self
(
system
),
self
(
system
),
sched
(
dynamic_cast
<
scheduler
::
test_coordinator
&>
(
system
.
scheduler
()))
{
sched
(
dynamic_cast
<
scheduler
::
test_coordinator
&>
(
system
.
scheduler
()))
{
CAF_REQUIRE
(
sched
.
jobs
.
empty
());
CAF_REQUIRE
(
sched
.
jobs
.
empty
());
CAF_REQUIRE
(
sched
.
delayed_messages
.
empty
());
}
}
~
fixture
()
{
~
fixture
()
{
...
@@ -335,8 +334,7 @@ CAF_TEST(nested_timeout) {
...
@@ -335,8 +334,7 @@ CAF_TEST(nested_timeout) {
// not respond to the message yet, i.e., timeout arrives before response
// not respond to the message yet, i.e., timeout arrives before response
sched
.
run
();
sched
.
run
();
// dispatch second timeout
// dispatch second timeout
CAF_REQUIRE
(
!
sched
.
delayed_messages
.
empty
());
CAF_REQUIRE_EQUAL
(
sched
.
dispatch
(),
true
);
sched
.
dispatch
();
CAF_REQUIRE_EQUAL
(
sched
.
next_job
<
local_actor
>
().
name
(),
string
{
"ping"
});
CAF_REQUIRE_EQUAL
(
sched
.
next_job
<
local_actor
>
().
name
(),
string
{
"ping"
});
CAF_CHECK
(
!
had_timeout
);
CAF_CHECK
(
!
had_timeout
);
CAF_CHECK
(
sched
.
next_job
<
ping_actor
>
().
state
.
had_first_timeout
);
CAF_CHECK
(
sched
.
next_job
<
ping_actor
>
().
state
.
had_first_timeout
);
...
...
libcaf_core/test/simple_timeout.cpp
View file @
42f463c9
...
@@ -87,7 +87,6 @@ struct fixture {
...
@@ -87,7 +87,6 @@ struct fixture {
self
(
system
),
self
(
system
),
sched
(
dynamic_cast
<
scheduler
::
test_coordinator
&>
(
system
.
scheduler
()))
{
sched
(
dynamic_cast
<
scheduler
::
test_coordinator
&>
(
system
.
scheduler
()))
{
CAF_REQUIRE
(
sched
.
jobs
.
empty
());
CAF_REQUIRE
(
sched
.
jobs
.
empty
());
CAF_REQUIRE
(
sched
.
delayed_messages
.
empty
());
}
}
~
fixture
()
{
~
fixture
()
{
...
...
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