xref: /aosp_15_r20/external/federated-compute/fcp/secagg/testing/server/test_async_runner.h (revision 14675a029014e728ec732f129a32e299b2da0601)
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef FCP_SECAGG_TESTING_SERVER_TEST_ASYNC_RUNNER_H_
18 #define FCP_SECAGG_TESTING_SERVER_TEST_ASYNC_RUNNER_H_
19 
20 #include <memory>
21 #include <utility>
22 
23 #include "fcp/base/scheduler.h"
24 #include "fcp/secagg/server/secagg_scheduler.h"
25 
26 namespace fcp {
27 namespace secagg {
28 
29 // Defines a scheduler used for testing, owning pointers to underlying
30 // schedulers in SecAggScheduler
31 class TestAsyncRunner : public SecAggScheduler {
32  public:
TestAsyncRunner(std::unique_ptr<Scheduler> worker_scheduler,std::unique_ptr<Scheduler> callback_scheduler)33   TestAsyncRunner(std::unique_ptr<Scheduler> worker_scheduler,
34                   std::unique_ptr<Scheduler> callback_scheduler)
35       : SecAggScheduler(worker_scheduler.get(), callback_scheduler.get()),
36         worker_scheduler_(std::move(worker_scheduler)),
37         callback_scheduler_(std::move(callback_scheduler)) {}
38 
~TestAsyncRunner()39   ~TestAsyncRunner() override { WaitUntilIdle(); }
40 
41  private:
42   std::unique_ptr<Scheduler> worker_scheduler_;
43   std::unique_ptr<Scheduler> callback_scheduler_;
44 };
45 
46 }  // namespace secagg
47 }  // namespace fcp
48 
49 #endif  // FCP_SECAGG_TESTING_SERVER_TEST_ASYNC_RUNNER_H_
50