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
21cddd4c
Commit
21cddd4c
authored
Jan 31, 2023
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for run_delayed and run_scheduled
parent
dab96058
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
220 additions
and
0 deletions
+220
-0
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+2
-0
libcaf_core/test/run_delayed.cpp
libcaf_core/test/run_delayed.cpp
+106
-0
libcaf_core/test/run_scheduled.cpp
libcaf_core/test/run_scheduled.cpp
+112
-0
No files found.
libcaf_core/CMakeLists.txt
View file @
21cddd4c
...
@@ -343,6 +343,8 @@ caf_add_component(
...
@@ -343,6 +343,8 @@ caf_add_component(
response_handle
response_handle
response_promise
response_promise
result
result
run_delayed
run_scheduled
save_inspector
save_inspector
scheduled_actor
scheduled_actor
serial_reply
serial_reply
...
...
libcaf_core/test/run_delayed.cpp
0 → 100644
View file @
21cddd4c
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#define CAF_SUITE run_delayed
#include "caf/event_based_actor.hpp"
#include "core-test.hpp"
using
namespace
caf
;
using
namespace
std
::
literals
;
namespace
{
using
fixture
=
test_coordinator_fixture
<>
;
behavior
dummy_behavior
()
{
return
{
[](
int
)
{},
};
}
}
// namespace
BEGIN_FIXTURE_SCOPE
(
fixture
)
SCENARIO
(
"run_delayed triggers an action after a relative timeout"
)
{
GIVEN
(
"a scheduled actor"
)
{
WHEN
(
"the actor schedules an action with run_delayed"
)
{
THEN
(
"the action triggers after the relative timeout"
)
{
auto
called
=
std
::
make_shared
<
bool
>
(
false
);
auto
aut
=
sys
.
spawn
([
called
](
event_based_actor
*
self
)
{
self
->
run_delayed
(
1s
,
[
called
]
{
*
called
=
true
;
});
return
dummy_behavior
();
});
sched
.
run
();
CHECK
(
!*
called
);
advance_time
(
1s
);
sched
.
run
();
CHECK
(
*
called
);
}
AND_THEN
(
"disposing the pending timeout cancels the action"
)
{
auto
called
=
std
::
make_shared
<
bool
>
(
false
);
auto
pending
=
disposable
{};
auto
aut
=
sys
.
spawn
([
called
,
&
pending
](
event_based_actor
*
self
)
{
pending
=
self
->
run_delayed
(
1s
,
[
called
]
{
*
called
=
true
;
});
return
dummy_behavior
();
});
sched
.
run
();
CHECK
(
!*
called
);
pending
.
dispose
();
advance_time
(
1s
);
sched
.
run
();
CHECK
(
!*
called
);
}
}
}
}
SCENARIO
(
"run_delayed_weak triggers an action after a relative timeout"
)
{
GIVEN
(
"a scheduled actor"
)
{
WHEN
(
"the actor schedules an action with run_delayed"
)
{
THEN
(
"the action triggers after the relative timeout for live actors"
)
{
auto
called
=
std
::
make_shared
<
bool
>
(
false
);
auto
aut
=
sys
.
spawn
([
called
](
event_based_actor
*
self
)
{
self
->
run_delayed_weak
(
1s
,
[
called
]
{
*
called
=
true
;
});
return
dummy_behavior
();
});
sched
.
run
();
CHECK
(
!*
called
);
advance_time
(
1s
);
sched
.
run
();
CHECK
(
*
called
);
}
AND_THEN
(
"no action triggers for terminated actors"
)
{
auto
called
=
std
::
make_shared
<
bool
>
(
false
);
sys
.
spawn
([
called
](
event_based_actor
*
self
)
{
self
->
run_delayed_weak
(
1s
,
[
called
]
{
*
called
=
true
;
});
return
dummy_behavior
();
});
sched
.
run
();
// Note: actor cleaned up after this line.
CHECK
(
!*
called
);
advance_time
(
1s
);
sched
.
run
();
CHECK
(
!*
called
);
}
AND_THEN
(
"disposing the pending timeout cancels the action"
)
{
auto
called
=
std
::
make_shared
<
bool
>
(
false
);
auto
pending
=
disposable
{};
auto
aut
=
sys
.
spawn
([
called
,
&
pending
](
event_based_actor
*
self
)
{
pending
=
self
->
run_delayed_weak
(
1s
,
[
called
]
{
*
called
=
true
;
});
return
dummy_behavior
();
});
sched
.
run
();
CHECK
(
!*
called
);
pending
.
dispose
();
advance_time
(
1s
);
sched
.
run
();
CHECK
(
!*
called
);
}
}
}
}
END_FIXTURE_SCOPE
()
libcaf_core/test/run_scheduled.cpp
0 → 100644
View file @
21cddd4c
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#define CAF_SUITE run_scheduled
#include "caf/event_based_actor.hpp"
#include "core-test.hpp"
using
namespace
caf
;
using
namespace
std
::
literals
;
namespace
{
using
fixture
=
test_coordinator_fixture
<>
;
behavior
dummy_behavior
()
{
return
{
[](
int
)
{},
};
}
}
// namespace
BEGIN_FIXTURE_SCOPE
(
fixture
)
SCENARIO
(
"run_scheduled triggers an action after a relative timeout"
)
{
GIVEN
(
"a scheduled actor"
)
{
WHEN
(
"the actor schedules an action with run_scheduled"
)
{
THEN
(
"the action triggers after the relative timeout"
)
{
auto
called
=
std
::
make_shared
<
bool
>
(
false
);
auto
aut
=
sys
.
spawn
([
called
](
event_based_actor
*
self
)
{
auto
now
=
self
->
clock
().
now
();
self
->
run_scheduled
(
now
+
1s
,
[
called
]
{
*
called
=
true
;
});
return
dummy_behavior
();
});
sched
.
run
();
CHECK
(
!*
called
);
advance_time
(
1s
);
sched
.
run
();
CHECK
(
*
called
);
}
AND_THEN
(
"disposing the pending timeout cancels the action"
)
{
auto
called
=
std
::
make_shared
<
bool
>
(
false
);
auto
pending
=
disposable
{};
auto
aut
=
sys
.
spawn
([
called
,
&
pending
](
event_based_actor
*
self
)
{
auto
now
=
self
->
clock
().
now
();
pending
=
self
->
run_scheduled
(
now
+
1s
,
[
called
]
{
*
called
=
true
;
});
return
dummy_behavior
();
});
sched
.
run
();
CHECK
(
!*
called
);
pending
.
dispose
();
advance_time
(
1s
);
sched
.
run
();
CHECK
(
!*
called
);
}
}
}
}
SCENARIO
(
"run_scheduled_weak triggers an action after a relative timeout"
)
{
GIVEN
(
"a scheduled actor"
)
{
WHEN
(
"the actor schedules an action with run_scheduled"
)
{
THEN
(
"the action triggers after the relative timeout for live actors"
)
{
auto
called
=
std
::
make_shared
<
bool
>
(
false
);
auto
aut
=
sys
.
spawn
([
called
](
event_based_actor
*
self
)
{
auto
now
=
self
->
clock
().
now
();
self
->
run_scheduled_weak
(
now
+
1s
,
[
called
]
{
*
called
=
true
;
});
return
dummy_behavior
();
});
sched
.
run
();
CHECK
(
!*
called
);
advance_time
(
1s
);
sched
.
run
();
CHECK
(
*
called
);
}
AND_THEN
(
"no action triggers for terminated actors"
)
{
auto
called
=
std
::
make_shared
<
bool
>
(
false
);
sys
.
spawn
([
called
](
event_based_actor
*
self
)
{
auto
now
=
self
->
clock
().
now
();
self
->
run_scheduled_weak
(
now
+
1s
,
[
called
]
{
*
called
=
true
;
});
return
dummy_behavior
();
});
sched
.
run
();
// Note: actor cleaned up after this line.
CHECK
(
!*
called
);
advance_time
(
1s
);
sched
.
run
();
CHECK
(
!*
called
);
}
AND_THEN
(
"disposing the pending timeout cancels the action"
)
{
auto
called
=
std
::
make_shared
<
bool
>
(
false
);
auto
pending
=
disposable
{};
auto
aut
=
sys
.
spawn
([
called
,
&
pending
](
event_based_actor
*
self
)
{
auto
now
=
self
->
clock
().
now
();
pending
=
self
->
run_scheduled_weak
(
now
+
1s
,
[
called
]
{
*
called
=
true
;
});
return
dummy_behavior
();
});
sched
.
run
();
CHECK
(
!*
called
);
pending
.
dispose
();
advance_time
(
1s
);
sched
.
run
();
CHECK
(
!*
called
);
}
}
}
}
END_FIXTURE_SCOPE
()
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