Skip to content

Commit

Permalink
test: Add test for sharded<>::invoke_on_...() compilation
Browse files Browse the repository at this point in the history
There are several options what invoke_on_...() can try to invoke. So far
only non-const and non-mutable callables are in use and it works.

If calling it with mutable lambdas, it used to fail compilation, but
previous patch fixed it, so here's the test.

It also makes sense to support calling it on const sharded<> object
(with the lambda accepting const service reference), but it's not that
simple (see scylladb#2278)

Signed-off-by: Pavel Emelyanov <[email protected]>
  • Loading branch information
xemul authored and tchaikov committed Jun 6, 2024
1 parent 0bfe012 commit c161caa
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/unit/sharded_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,32 @@ SEASTAR_THREAD_TEST_CASE(invoke_on_all_sharded_arg) {
srv.stop().get();
arg.stop().get();
}

SEASTAR_THREAD_TEST_CASE(invoke_on_modifiers) {
class checker {
public:
future<> fn(int a) {
return make_ready_future<>();
}
future<> fn(int a) const {
return make_ready_future<>();
}
};

seastar::sharded<checker> srv;
srv.start().get();
int a = 42;

srv.invoke_on_all([a] (checker& s) { return s.fn(a); }).get();
srv.invoke_on_all([a] (checker& s) mutable { return s.fn(a); }).get();
srv.invoke_on_others([a] (checker& s) { return s.fn(a); }).get();
srv.invoke_on_others([a] (checker& s) mutable ->future<> { return s.fn(a); }).get();
/* const versions of invoke_on_...() are yet to come, see scylladb/seastar#2278
const_cast<const sharded<checker>&>(srv).invoke_on_all([a] (const checker& s) { return s.fn(a); }).get();
const_cast<const sharded<checker>&>(srv).invoke_on_all([a] (const checker& s) mutable { return s.fn(a); }).get();
const_cast<const sharded<checker>&>(srv).invoke_on_others([a] (const checker& s) { return s.fn(a); }).get();
const_cast<const sharded<checker>&>(srv).invoke_on_others([a] (const checker& s) mutable ->future<> { return s.fn(a); }).get();
*/

srv.stop().get();
}

0 comments on commit c161caa

Please sign in to comment.