test: Speed up test_state_absent_can_remove_down_profiles

The`test_state_absent_can_remove_down_profiles` takes 90 seconds to
finish as the `assertlib.assert_state_match()` will keep retrying till
matches or expired.

Fixed by add `no_retry` option to `assertlib.assert_state_match()`

Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
Gris Ge 2022-12-18 19:54:38 +08:00 committed by Fernando Fernández Mancera
parent 94c7341ac5
commit 249961df2a
2 changed files with 5 additions and 22 deletions
tests/integration

@ -1,21 +1,4 @@
#
# Copyright (c) 2019-2022 Red Hat, Inc.
#
# This file is part of nmstate
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 2.1 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: LGPL-2.1-or-later
from contextlib import contextmanager
@ -282,10 +265,10 @@ def test_state_absent_can_remove_down_profiles(dummy0_with_down_profile):
}
)
# Sinec absent already removed the down profile, if we bring the same
# Since absent already removed the down profile, if we bring the same
# interface up, it should contain different states than before
with pytest.raises(AssertionError):
assertlib.assert_state_match(state_before_down)
assertlib.assert_state_match(state_before_down, no_retry=True)
def test_create_memory_only_profile_new_interface():

@ -57,7 +57,7 @@ def assert_absent(*ifnames):
time.sleep(0.5)
def assert_state_match(desired_state_data):
def assert_state_match(desired_state_data, no_retry=False):
"""
Given a state, assert it against the current state by treating missing
value in desired_state as match.
@ -68,7 +68,7 @@ def assert_state_match(desired_state_data):
)
if desired_state.match(current_state):
return
elif i == RETRY_COUNT - 1:
elif i == RETRY_COUNT - 1 or no_retry:
print(
"desired miss match with current, retrying, "
f"desire {desired_state.state}"