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
acf91eb2
Unverified
Commit
acf91eb2
authored
Mar 25, 2021
by
Noir
Committed by
GitHub
Mar 25, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1244
Properly handle request.await in test DSL
parents
83144dce
19db4a86
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
99 additions
and
2 deletions
+99
-2
CHANGELOG.md
CHANGELOG.md
+3
-0
libcaf_core/caf/intrusive/drr_cached_queue.hpp
libcaf_core/caf/intrusive/drr_cached_queue.hpp
+7
-0
libcaf_core/caf/intrusive/fifo_inbox.hpp
libcaf_core/caf/intrusive/fifo_inbox.hpp
+7
-0
libcaf_core/caf/intrusive/task_queue.hpp
libcaf_core/caf/intrusive/task_queue.hpp
+9
-0
libcaf_core/caf/intrusive/wdrr_dynamic_multiplexed_queue.hpp
libcaf_core/caf/intrusive/wdrr_dynamic_multiplexed_queue.hpp
+9
-0
libcaf_core/caf/intrusive/wdrr_fixed_multiplexed_queue.hpp
libcaf_core/caf/intrusive/wdrr_fixed_multiplexed_queue.hpp
+20
-0
libcaf_core/src/scheduled_actor.cpp
libcaf_core/src/scheduled_actor.cpp
+10
-1
libcaf_core/test/mixin/requester.cpp
libcaf_core/test/mixin/requester.cpp
+34
-1
No files found.
CHANGELOG.md
View file @
acf91eb2
...
...
@@ -34,6 +34,9 @@ is based on [Keep a Changelog](https://keepachangelog.com).
-
Fix heap-use-after-free when accessing the meta objects table in applications
that leave the
`main`
function while the actor system and its worker threads
are still running (#1241).
-
The testing DSL now properly accounts for the message prioritization of actors
(suspending regular behavior until receiving the response) when using
`request.await`
(#1232).
## [0.18.1] - 2021-03-19
...
...
libcaf_core/caf/intrusive/drr_cached_queue.hpp
View file @
acf91eb2
...
...
@@ -102,6 +102,13 @@ public:
list_
.
peek_all
(
f
);
}
/// Tries to find the next element in the queue (excluding cached elements)
/// that matches the given predicate.
template
<
class
Predicate
>
pointer
find_if
(
Predicate
pred
)
{
return
list_
.
find_if
(
pred
);
}
// -- modifiers -------------------------------------------------------------
/// Removes all elements from the queue.
...
...
libcaf_core/caf/intrusive/fifo_inbox.hpp
View file @
acf91eb2
...
...
@@ -161,6 +161,13 @@ public:
return
queue_
.
peek
();
}
/// Tries to find an element in the queue that matches the given predicate.
template
<
class
Predicate
>
pointer
find_if
(
Predicate
pred
)
{
fetch_more
();
return
queue_
.
find_if
(
pred
);
}
queue_type
&
queue
()
noexcept
{
return
queue_
;
}
...
...
libcaf_core/caf/intrusive/task_queue.hpp
View file @
acf91eb2
...
...
@@ -124,6 +124,15 @@ public:
f
(
*
i
);
}
/// Tries to find an element in the queue that matches the given predicate.
template
<
class
Predicate
>
pointer
find_if
(
Predicate
pred
)
{
for
(
auto
i
=
begin
();
i
!=
end
();
++
i
)
if
(
pred
(
*
i
))
return
promote
(
i
.
ptr
);
return
nullptr
;
}
// -- modifiers -------------------------------------------------------------
/// Removes all elements from the queue.
...
...
libcaf_core/caf/intrusive/wdrr_dynamic_multiplexed_queue.hpp
View file @
acf91eb2
...
...
@@ -154,6 +154,15 @@ public:
kvp
.
second
.
peek_all
(
f
);
}
/// Tries to find an element in the queue that matches the given predicate.
template
<
class
Predicate
>
pointer
find_if
(
Predicate
pred
)
{
for
(
auto
&
kvp
:
qs_
)
if
(
auto
ptr
=
kvp
.
second
.
find_if
(
pred
))
return
ptr
;
return
nullptr
;
}
/// Returns `true` if all queues are empty, `false` otherwise.
bool
empty
()
const
noexcept
{
return
total_task_size
()
==
0
;
...
...
libcaf_core/caf/intrusive/wdrr_fixed_multiplexed_queue.hpp
View file @
acf91eb2
...
...
@@ -80,6 +80,12 @@ public:
return
peek_recursion
<
0
>
();
}
/// Tries to find an element in the queue that matches the given predicate.
template
<
class
Predicate
>
pointer
find_if
(
Predicate
pred
)
{
return
find_if_recursion
<
0
>
(
pred
);
}
/// Applies `f` to each element in the queue.
template
<
class
F
>
void
peek_all
(
F
f
)
const
{
...
...
@@ -204,6 +210,20 @@ private:
return
peek_recursion
<
I
+
1
>
();
}
template
<
size_t
I
,
class
Predicate
>
detail
::
enable_if_t
<
I
==
num_queues
,
pointer
>
find_if_recursion
(
Predicate
)
{
return
nullptr
;
}
template
<
size_t
I
,
class
Predicate
>
detail
::
enable_if_t
<
I
!=
num_queues
,
pointer
>
find_if_recursion
(
Predicate
pred
)
{
if
(
auto
ptr
=
std
::
get
<
I
>
(
qs_
).
find_if
(
pred
))
return
ptr
;
else
return
find_if_recursion
<
I
+
1
>
(
std
::
move
(
pred
));
}
template
<
size_t
I
,
class
F
>
detail
::
enable_if_t
<
I
==
num_queues
>
peek_all_recursion
(
F
&
)
const
{
// nop
...
...
libcaf_core/src/scheduled_actor.cpp
View file @
acf91eb2
...
...
@@ -175,8 +175,17 @@ void scheduled_actor::enqueue(mailbox_element_ptr ptr, execution_unit* eu) {
break
;
}
}
mailbox_element
*
scheduled_actor
::
peek_at_next_mailbox_element
()
{
return
mailbox
().
closed
()
||
mailbox
().
blocked
()
?
nullptr
:
mailbox
().
peek
();
if
(
mailbox
().
closed
()
||
mailbox
().
blocked
())
{
return
nullptr
;
}
else
if
(
awaited_responses_
.
empty
())
{
return
mailbox
().
peek
();
}
else
{
auto
mid
=
awaited_responses_
.
begin
()
->
first
;
auto
pred
=
[
mid
](
mailbox_element
&
x
)
{
return
x
.
mid
==
mid
;
};
return
mailbox
().
find_if
(
pred
);
}
}
// -- overridden functions of local_actor --------------------------------------
...
...
libcaf_core/test/mixin/requester.cpp
View file @
acf91eb2
...
...
@@ -6,7 +6,7 @@
#include "caf/mixin/requester.hpp"
#include "c
af/test/dsl
.hpp"
#include "c
ore-test
.hpp"
#include <numeric>
...
...
@@ -187,4 +187,37 @@ CAF_TEST(exceptions while processing requests trigger error messages) {
#endif // CAF_ENABLE_EXCEPTIONS
SCENARIO
(
"request.await enforces a processing order"
)
{
GIVEN
(
"an actor that is waiting for a request.await handler"
)
{
auto
server
=
sys
.
spawn
([]()
->
behavior
{
return
{
[](
int32_t
x
)
{
return
x
*
x
;
},
};
});
run
();
auto
client
=
sys
.
spawn
([
server
](
event_based_actor
*
self
)
->
behavior
{
self
->
request
(
server
,
infinite
,
int32_t
{
3
}).
await
([](
int32_t
res
)
{
CHECK_EQ
(
res
,
9
);
});
return
{
[](
const
std
::
string
&
str
)
{
// Received from self.
CHECK_EQ
(
str
,
"hello"
);
},
};
});
sched
.
run_once
();
WHEN
(
"sending it a message before the response arrives"
)
{
THEN
(
"the actor handles the asynchronous message later"
)
{
self
->
send
(
client
,
"hello"
);
disallow
((
std
::
string
),
from
(
self
).
to
(
client
));
// not processed yet
expect
((
int32_t
),
from
(
client
).
to
(
server
).
with
(
3
));
// client -> server
disallow
((
std
::
string
),
from
(
self
).
to
(
client
));
// not processed yet
expect
((
int32_t
),
from
(
server
).
to
(
client
).
with
(
9
));
// server -> client
expect
((
std
::
string
),
from
(
self
).
to
(
client
).
with
(
"hello"
));
// at last
}
}
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
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