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 committed Jun 3, 2024
1 parent b609abc commit f524f06
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/unit/sharded_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,23 @@ 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<>();
}
};

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 { return s.fn(a); }).get();

srv.stop().get();
}

0 comments on commit f524f06

Please sign in to comment.