From 907300c3c3db0940964dd511f9744529226a69a2 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 22 Jun 2021 12:12:34 +0200 Subject: [PATCH 1/2] test: ignore the "freezing" & "thawing" intermediate states When checking the unit state after `systemctl freeze|thaw` we can be "too fast" and get the intermediate state (freezing/thawing) which we're not interested in. Let's wait a bit and try to get the state again in such cases to avoid unnecessary flakiness. ``` [ 29.390203] testsuite-38.sh[218]: + state=thawing [ 29.390203] testsuite-38.sh[218]: + '[' thawing = running ']' [ 29.390203] testsuite-38.sh[218]: + echo 'error: unexpected freezer state, expected: running, actual: thawing' [ 29.390203] testsuite-38.sh[218]: error: unexpected freezer state, expected: running, actual: thawing [ 29.390203] testsuite-38.sh[218]: + exit 1 ``` --- test/units/testsuite-38.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/units/testsuite-38.sh b/test/units/testsuite-38.sh index 818f69bc63..e58bae81fe 100755 --- a/test/units/testsuite-38.sh +++ b/test/units/testsuite-38.sh @@ -82,11 +82,18 @@ check_freezer_state() { name="${1%.$suffix}" object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}" - state=$(busctl get-property \ - org.freedesktop.systemd1 \ - "${object_path}" \ - org.freedesktop.systemd1.Unit \ - FreezerState | cut -d " " -f2 | tr -d '"') + for _ in {0..10}; do + state=$(busctl get-property \ + org.freedesktop.systemd1 \ + "${object_path}" \ + org.freedesktop.systemd1.Unit \ + FreezerState | cut -d " " -f2 | tr -d '"') + + # Ignore the intermediate freezing & thawing states in case we check + # the unit state too quickly + [[ "$state" =~ ^(freezing|thawing)$ ]] || break + sleep .5 + done [ "$state" = "$2" ] || { echo "error: unexpected freezer state, expected: $2, actual: $state" >&2 From 179ca4d2b1b5579014773a128462475f99b7a91b Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 22 Jun 2021 12:30:24 +0200 Subject: [PATCH 2/2] test: correctly mask supporting services in tests It turns out the "supporting services" were run in _all_ tests if TEST-01-BASIC was run as the first test (which is usually the case), since with the original condition in test_create_image() we would skip the masking and then propagate the change to the default image used by other tests. This has been causing multiple bogus test timeouts (especially when the hwdb was being rebuilt in tests with short timeouts, like TEST-52-HONORFIRSTSHUTDOWN). Let's "fix" this by making the call to mask_supporting_services() uncoditional and override the test_create_image() function in TEST-01-BASIC to avoid the masking in this single case. --- test/TEST-01-BASIC/test.sh | 12 ++++++++++++ test/test-functions | 8 +------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index d42c0df9a0..5a6156d770 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -9,6 +9,18 @@ TEST_REQUIRE_INSTALL_TESTS=0 # shellcheck source=test/test-functions . "${TEST_BASE_DIR:?}/test-functions" +# Explicitly override the default test_create_image() function to avoid the +# call to mask_supporting_services(), since we want to run them in TEST-01-BASIC +test_create_image() { + create_empty_image_rootdir + + # Create what will eventually be our root filesystem onto an overlay + ( + LOG_LEVEL=5 + setup_basic_environment + ) +} + test_append_files() { # install tests manually so the test is functional even when -Dinstall-tests=false local dst="${1:?}/usr/lib/systemd/tests/testdata/units/" diff --git a/test/test-functions b/test/test-functions index b154ace393..eb1d99e0d1 100644 --- a/test/test-functions +++ b/test/test-functions @@ -2355,13 +2355,7 @@ test_create_image() { ( LOG_LEVEL=5 setup_basic_environment - - # We want to test all services in TEST-01-BASIC, but mask them in - # all other tests - if [[ "$TESTID" != "01" ]]; then - dinfo "Masking supporting services" - mask_supporting_services - fi + mask_supporting_services ) }