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
343f3930
Commit
343f3930
authored
Oct 07, 2022
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Plain Diff
Merge issue/1299
Close #1299.
parents
697dba79
dea2b3f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
123 additions
and
2 deletions
+123
-2
libcaf_core/src/scheduled_actor.cpp
libcaf_core/src/scheduled_actor.cpp
+10
-2
libcaf_core/test/mixin/requester.cpp
libcaf_core/test/mixin/requester.cpp
+113
-0
No files found.
libcaf_core/src/scheduled_actor.cpp
View file @
343f3930
...
@@ -306,8 +306,16 @@ resumable::resume_result scheduled_actor::resume(execution_unit* ctx,
...
@@ -306,8 +306,16 @@ resumable::resume_result scheduled_actor::resume(execution_unit* ctx,
// TODO: maybe replace '3' with configurable / adaptive value?
// TODO: maybe replace '3' with configurable / adaptive value?
static
constexpr
size_t
quantum
=
3
;
static
constexpr
size_t
quantum
=
3
;
// Dispatch urgent and normal (asynchronous) messages.
// Dispatch urgent and normal (asynchronous) messages.
get_urgent_queue
().
new_round
(
quantum
*
3
,
handle_async
);
auto
&
hq
=
get_urgent_queue
();
get_normal_queue
().
new_round
(
quantum
,
handle_async
);
auto
&
nq
=
get_normal_queue
();
if
(
hq
.
new_round
(
quantum
*
3
,
handle_async
).
consumed_items
>
0
)
{
// After matching any message, all caches must be re-evaluated.
nq
.
flush_cache
();
}
if
(
nq
.
new_round
(
quantum
,
handle_async
).
consumed_items
>
0
)
{
// After matching any message, all caches must be re-evaluated.
hq
.
flush_cache
();
}
// Update metrics or try returning if the actor consumed nothing.
// Update metrics or try returning if the actor consumed nothing.
auto
delta
=
consumed
-
prev
;
auto
delta
=
consumed
-
prev
;
CAF_LOG_DEBUG
(
"consumed"
<<
delta
<<
"messages this round"
);
CAF_LOG_DEBUG
(
"consumed"
<<
delta
<<
"messages this round"
);
...
...
libcaf_core/test/mixin/requester.cpp
View file @
343f3930
...
@@ -221,4 +221,117 @@ SCENARIO("request.await enforces a processing order") {
...
@@ -221,4 +221,117 @@ SCENARIO("request.await enforces a processing order") {
}
}
}
}
// The GH-1299 worker processes int32 and string messages but alternates between
// processing either type.
using
log_ptr
=
std
::
shared_ptr
<
std
::
string
>
;
behavior
gh1299_worker_bhvr1
(
caf
::
event_based_actor
*
self
,
log_ptr
log
);
behavior
gh1299_worker_bhvr2
(
caf
::
event_based_actor
*
self
,
log_ptr
log
);
behavior
gh1299_worker
(
caf
::
event_based_actor
*
self
,
log_ptr
log
)
{
self
->
set_default_handler
(
skip
);
return
gh1299_worker_bhvr1
(
self
,
log
);
}
behavior
gh1299_worker_bhvr1
(
caf
::
event_based_actor
*
self
,
log_ptr
log
)
{
return
{
[
self
,
log
](
int32_t
x
)
{
*
log
+=
"int: "
;
*
log
+=
std
::
to_string
(
x
);
*
log
+=
'\n'
;
self
->
become
(
gh1299_worker_bhvr2
(
self
,
log
));
},
};
}
behavior
gh1299_worker_bhvr2
(
caf
::
event_based_actor
*
self
,
log_ptr
log
)
{
return
{
[
self
,
log
](
const
std
::
string
&
x
)
{
*
log
+=
"string: "
;
*
log
+=
x
;
*
log
+=
'\n'
;
self
->
become
(
gh1299_worker_bhvr1
(
self
,
log
));
},
};
}
TEST_CASE
(
"GH-1299 regression non-blocking"
)
{
SUBTEST
(
"HIGH (skip) -> NORMAL"
)
{
auto
log
=
std
::
make_shared
<
std
::
string
>
();
auto
worker
=
sys
.
spawn
(
gh1299_worker
,
log
);
scoped_actor
self
{
sys
};
self
->
send
<
message_priority
::
high
>
(
worker
,
"hi there"
);
run
();
self
->
send
(
worker
,
int32_t
{
123
});
run
();
CHECK_EQ
(
*
log
,
"int: 123
\n
string: hi there
\n
"
);
}
SUBTEST
(
"NORMAL (skip) -> HIGH"
)
{
auto
log
=
std
::
make_shared
<
std
::
string
>
();
auto
worker
=
sys
.
spawn
(
gh1299_worker
,
log
);
scoped_actor
self
{
sys
};
self
->
send
(
worker
,
"hi there"
);
run
();
self
->
send
<
message_priority
::
high
>
(
worker
,
int32_t
{
123
});
run
();
CHECK_EQ
(
*
log
,
"int: 123
\n
string: hi there
\n
"
);
}
}
void
gh1299_recv
(
scoped_actor
&
self
,
log_ptr
log
,
int
&
tag
)
{
bool
fin
=
false
;
for
(;;)
{
if
(
tag
==
0
)
{
self
->
receive
(
[
log
,
&
tag
](
int32_t
x
)
{
*
log
+=
"int: "
;
*
log
+=
std
::
to_string
(
x
);
*
log
+=
'\n'
;
tag
=
1
;
},
after
(
timespan
{
0
})
>>
[
&
fin
]
{
fin
=
true
;
});
if
(
fin
)
return
;
}
else
{
self
->
receive
(
[
log
,
&
tag
](
const
std
::
string
&
x
)
{
*
log
+=
"string: "
;
*
log
+=
x
;
*
log
+=
'\n'
;
tag
=
0
;
},
after
(
timespan
{
0
})
>>
[
&
fin
]
{
fin
=
true
;
});
if
(
fin
)
return
;
}
}
}
TEST_CASE
(
"GH-1299 regression blocking"
)
{
SUBTEST
(
"HIGH (skip) -> NORMAL"
)
{
auto
log
=
std
::
make_shared
<
std
::
string
>
();
auto
tag
=
0
;
scoped_actor
sender
{
sys
};
scoped_actor
self
{
sys
};
sender
->
send
<
message_priority
::
high
>
(
self
,
"hi there"
);
gh1299_recv
(
self
,
log
,
tag
);
sender
->
send
(
self
,
int32_t
{
123
});
gh1299_recv
(
self
,
log
,
tag
);
CHECK_EQ
(
*
log
,
"int: 123
\n
string: hi there
\n
"
);
}
SUBTEST
(
"NORMAL (skip) -> HIGH"
)
{
auto
log
=
std
::
make_shared
<
std
::
string
>
();
auto
tag
=
0
;
scoped_actor
sender
{
sys
};
scoped_actor
self
{
sys
};
sender
->
send
(
self
,
"hi there"
);
gh1299_recv
(
self
,
log
,
tag
);
sender
->
send
<
message_priority
::
high
>
(
self
,
int32_t
{
123
});
gh1299_recv
(
self
,
log
,
tag
);
CHECK_EQ
(
*
log
,
"int: 123
\n
string: hi there
\n
"
);
}
}
END_FIXTURE_SCOPE
()
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