コード例 #1
0
def test_baseservice():
    """
    Base service tests for:
        - [x] name on init
        - [x] idle state on init
        - [x] starting state on start()
        - [x] ready() alias for idle state
        - [x] stopped state on stop()
        - [x] idle state exception when service not in stopped state
        - [x] idle state on idle()
    :return:
    """

    name = "base-service-1"
    base = BaseService(name)
    assert base.alias == name
    assert base.unique_name == '%s/%s' % (name, base.uuid)
    assert base.get_state() == BaseStates.Idle
    assert base.ready() is True  # ready == Idle

    greenlet = base.start()
    assert greenlet is not None
    assert base.get_state() == BaseStates.Starting
    assert base.ready() is False

    # exception should be thrown if state is started
    # and asking service to make itself idle.
    try:
        base.idle()
    except IdleActionException as ex:
        assert ex is not None

    base.stop()
    assert base.get_state() == BaseStates.Stopped

    # Try restarting the service, it will fail because it is not idle
    # In order to restart a service must be set to idle again.
    try:
        base.start()
        assert not True  # <-- should never get here
    except ServiceNotIdleException as ex:
        assert ex is not None

    # now set to idle
    base.idle()  # should not throw this time
    assert base.get_state() == BaseStates.Idle

    # not start, should work and not throw an exception
    base.start()
コード例 #2
0
def test_baseservice_service_directory():
    """
    Base service tests for:
        - [x] name on init
        - [x] idle state on init
        - [x] started state on start()
        - [x] ready() alias for idle state
        - [x] stopped state on stop()
        - [x] idle state exception when service not in stopped state
        - [x] idle state on idle()
    :return:
    """

    name = "base-service-1"
    base = BaseService(name)
    assert base.alias == name
    assert base.unique_name == '%s/%s' % (name, base.uuid)
    assert base.get_state() == BaseStates.Idle
    assert base.ready() is True  # ready == Idle

    greenlet = base.start()
    assert greenlet is not None
    assert base.get_state() == BaseStates.Starting
    assert base.ready() is False

    # exception should be thrown if state is started
    # and asking service to make itself idle.
    try:
        base.idle()
    except IdleActionException as ex:
        assert ex is not None

    base.stop()
    assert base.get_state() == BaseStates.Stopped
    base.idle()  # should not throw this time
    assert base.get_state() == BaseStates.Idle