| 24 | #include "test.h" |
| 25 | |
| 26 | FL_TEST_FILE(FL_FILEPATH) { |
| 27 | |
| 28 | namespace draining_state_test { |
| 29 | |
| 30 | using namespace fl; |
| 31 | using DriverState = IChannelDriver::DriverState; |
| 32 | |
| 33 | /// Mock driver that lets tests control what poll() returns. |
| 34 | class StatefulMockDriver : public IChannelDriver { |
| 35 | public: |
| 36 | explicit StatefulMockDriver(const char* name) : mName(name) {} |
| 37 | |
| 38 | // Controllable state |
| 39 | DriverState::Value mState = DriverState::READY; |
| 40 | int showCount = 0; |
| 41 | int enqueueCount = 0; |
| 42 | int pollCount = 0; |
| 43 | |
| 44 | bool canHandle(const ChannelDataPtr&) const override { return true; } |
| 45 | void enqueue(ChannelDataPtr) override { enqueueCount++; } |
| 46 | void show() override { showCount++; } |
| 47 | DriverState poll() override { pollCount++; return DriverState(mState); } |
| 48 | fl::string getName() const override { return mName; } |
| 49 | |
| 50 | Capabilities getCapabilities() const override { |
| 51 | return Capabilities(true, false); |
| 52 | } |
| 53 | |
| 54 | private: |
| 55 | fl::string mName; |
| 56 | }; |
| 57 | |
| 58 | FL_TEST_CASE("ChannelManager::poll propagates each state correctly") { |
| 59 | auto driver = fl::make_shared<StatefulMockDriver>("DRAIN_POLL"); |
| 60 | ChannelManager& mgr = ChannelManager::instance(); |
| 61 | mgr.addDriver(5000, driver); |
| 62 | |
| 63 | // Step through the full lifecycle: READY → BUSY → DRAINING → READY |
| 64 | // Each mgr.poll() call is a single poll - no looping, no timeouts. |
| 65 | |
| 66 | driver->mState = DriverState::READY; |
| 67 | FL_CHECK_EQ(static_cast<int>(mgr.poll().state), |
| 68 | static_cast<int>(DriverState::READY)); |
| 69 | |
| 70 | driver->mState = DriverState::BUSY; |
| 71 | FL_CHECK_EQ(static_cast<int>(mgr.poll().state), |
| 72 | static_cast<int>(DriverState::BUSY)); |
| 73 | |
| 74 | driver->mState = DriverState::DRAINING; |
| 75 | FL_CHECK_EQ(static_cast<int>(mgr.poll().state), |
| 76 | static_cast<int>(DriverState::DRAINING)); |
| 77 | |
| 78 | driver->mState = DriverState::READY; |
| 79 | FL_CHECK_EQ(static_cast<int>(mgr.poll().state), |
| 80 | static_cast<int>(DriverState::READY)); |
| 81 | |
| 82 | // Verify poll was called exactly 4 times (once per mgr.poll()) |
| 83 | FL_CHECK_EQ(driver->pollCount, 4); |
nothing calls this directly
no test coverage detected