2 * Copyright 2017 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <folly/executors/FiberIOExecutor.h>
20 #include <folly/executors/IOThreadPoolExecutor.h>
22 #include <folly/portability/GTest.h>
26 class FiberIOExecutorTest : public testing::Test {};
29 TEST_F(FiberIOExecutorTest, event_base) {
30 auto tpe = std::make_shared<folly::IOThreadPoolExecutor>(1);
31 folly::FiberIOExecutor e(tpe);
33 ASSERT_NE(e.getEventBase(), nullptr);
34 ASSERT_EQ(e.getEventBase(), tpe->getEventBase());
37 TEST_F(FiberIOExecutorTest, basic_execution) {
38 auto tpe = std::make_shared<folly::IOThreadPoolExecutor>(1);
39 folly::FiberIOExecutor e(tpe);
41 // FiberIOExecutor should add tasks using the FiberManager mapped to the
42 // IOThreadPoolExecutor's event base.
44 bool inContext = false;
47 inContext = folly::fibers::onFiber();
48 auto& lc = dynamic_cast<folly::fibers::EventBaseLoopController&>(
49 folly::fibers::getFiberManager(*e.getEventBase()).loopController());
50 auto& eb = lc.getEventBase()->getEventBase();
52 inContext && &eb == folly::EventBaseManager::get()->getEventBase();
57 ASSERT_TRUE(inContext);