ha_state_machine_control_unittest.cc 2.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <ha_state_machine_control.h>
#include <ha_test.h>
#include <gtest/gtest.h>

using namespace isc::ha;
using namespace isc::ha::test;

namespace {

class HAStateMachineControlTest : public HATest {
public:

    /// @brief Constructor.
    HAStateMachineControlTest()
        : HATest() {
    }

};

// This test verifies that pausing HA state machine works as expected.
TEST_F(HAStateMachineControlTest, pause) {
    HAConfigPtr config = createValidConfiguration();

    // Always pause in the waiting state and pause on first transition to
    // the ready state. Do not pause for other states.
32 33
    config->getStateMachineConfig()->getStateConfig(HA_WAITING_ST)->setPausing("always");
    config->getStateMachineConfig()->getStateConfig(HA_READY_ST)->setPausing("once");
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

    // Initially we shouldn't be paused.
    HAStateMachineControl control(config);
    EXPECT_FALSE(control.amPaused());

    // Should not pause in load-balancing state.
    EXPECT_NO_THROW(control.notify(HA_LOAD_BALANCING_ST));
    EXPECT_FALSE(control.amPaused());

    // Should always pause in waiting state.
    EXPECT_NO_THROW(control.notify(HA_WAITING_ST));
    EXPECT_TRUE(control.amPaused());

    control.unpause();
    EXPECT_FALSE(control.amPaused());

    // Should pause once in the ready state.
    EXPECT_NO_THROW(control.notify(HA_READY_ST));
    EXPECT_TRUE(control.amPaused());

    control.unpause();
    EXPECT_FALSE(control.amPaused());

    // Do not pause the second time in the ready state.
    EXPECT_NO_THROW(control.notify(HA_READY_ST));
    EXPECT_FALSE(control.amPaused());

    // Never pause in the load-balancing state.
    EXPECT_NO_THROW(control.notify(HA_LOAD_BALANCING_ST));
    EXPECT_FALSE(control.amPaused());

    // Always pause in the waiting state.
    EXPECT_NO_THROW(control.notify(HA_WAITING_ST));
    EXPECT_TRUE(control.amPaused());
}

}