def test_statefulset_not_fully_available_when_it_should(
        cl, client, watch, has_conf):
    has_conf.return_value = False
    statefulset = MagicMock()
    statefulset.spec.replicas = 2
    statefulset.status.ready_replicas = 1

    watcher = MagicMock()
    watcher.stream = MagicMock()
    watcher.stream.side_effect = urllib3.exceptions.ReadTimeoutError(
        None, None, None)
    watch.Watch.return_value = watcher

    with pytest.raises(ActivityFailed) as excinfo:
        statefulset_fully_available("mysvc")
    assert "microservice 'mysvc' failed to recover within" in str(
        excinfo.value)
def test_statefulset_fully_available(cl, client, watch, has_conf):
    has_conf.return_value = False
    statefulset = MagicMock()
    statefulset.spec.replicas = 2
    statefulset.status.ready_replicas = 2

    watcher = MagicMock()
    watcher.stream = MagicMock()
    watcher.stream.side_effect = [[{"object": statefulset, "type": "ADDED"}]]
    watch.Watch.return_value = watcher

    assert statefulset_fully_available("mysvc") is True