Skip to content

Commit

Permalink
tests/main/auto-refresh-backoff: fix sorting of changes from the state (
Browse files Browse the repository at this point in the history
#14691)

* tests/main/auto-refresh-backoff: fix sorting of changes from the state

When the changes reach 2 digit numbers, the default lexicographic
sorting will sort changes with ids 10, or 11 before 9, thus leading to
the last change ID being incorrect breaking the rest of the test.

Compare:

google:ubuntu-16.04-64 .../tests/main/auto-refresh-backoff# snap debug api /v2/changes?select=all | \
    jq '.result | sort_by(.id) | .[].id'
"1"
"10"
"11"
"2"
... <IDs 3-7>
"8"
"9"
google:ubuntu-16.04-64 .../tests/main/auto-refresh-backoff# snap debug api /v2/changes?select=all | \
    jq '.result | sort_by(.id|tonumber) | .[].id'
"1"
"2"
... <IDs 3-7>
"8"
"9"
"10"
"11"

Signed-off-by: Maciej Borzecki <[email protected]>

* tests/core/auto-refresh-backoff-after-reboot: fix ordering by change ID

Signed-off-by: Maciej Borzecki <[email protected]>

---------

Signed-off-by: Maciej Borzecki <[email protected]>
  • Loading branch information
bboozzoo authored Nov 7, 2024
1 parent eabd4db commit adab44d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions tests/core/auto-refresh-backoff-after-reboot/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ prepare: |
snap set system refresh.hold=forever
# Record last change id before we start to avoid flakiness due to auto-refreshes in other tests
snap debug api /v2/changes?select=all | jq '.result | sort_by(.id) | .[-1].id' > last-change-id
snap debug api /v2/changes?select=all | jq '.result | sort_by(.id|tonumber) | .[-1].id' > last-change-id
# Record current snap revision for reference
readlink "/snap/$SNAP_NAME/current" > snap.rev
Expand Down Expand Up @@ -58,7 +58,7 @@ restore: |
snap set system refresh.hold!
debug: |
snap debug api /v2/changes?select=ready | jq "[.result[] | select(.kind == \"auto-refresh\")] | sort_by(.id)"
snap debug api /v2/changes?select=ready | jq "[.result[] | select(.kind == \"auto-refresh\")] | sort_by(.id|tonumber)"
execute: |
if [ "$TRUST_TEST_KEYS" = "false" ]; then
Expand Down Expand Up @@ -169,7 +169,7 @@ execute: |
retry -n 50 --wait 1 "$(pwd)"/check_auto_refresh_count.sh "$LAST_CHANGE_ID" 2
echo "Check auto-refresh behaviour matches expectations for backoff algorithm"
snap debug api /v2/changes?select=ready | jq "[.result[] | select(.kind == \"auto-refresh\" and (.id|tonumber) > ($LAST_CHANGE_ID|tonumber))] | sort_by(.id)" > changes.json
snap debug api /v2/changes?select=ready | jq "[.result[] | select(.kind == \"auto-refresh\" and (.id|tonumber) > ($LAST_CHANGE_ID|tonumber))] | sort_by(.id|tonumber)" > changes.json
# 1st auto-refresh
jq '.[0].status' < changes.json | MATCH "Error"
Expand Down
6 changes: 3 additions & 3 deletions tests/main/auto-refresh-backoff/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ restore: |
rm -rf "$BLOB_DIR"
debug: |
snap debug api /v2/changes?select=ready | jq "[.result[] | select(.kind == \"auto-refresh\")] | sort_by(.id)"
snap debug api /v2/changes?select=ready | jq "[.result[] | select(.kind == \"auto-refresh\")] | sort_by(.id|tonumber)"
execute: |
if [ "$TRUST_TEST_KEYS" = "false" ]; then
Expand Down Expand Up @@ -94,7 +94,7 @@ execute: |
}
# Record last change id before we start to avoid flakiness due to auto-refreshes in other tests
LAST_CHANGE_ID=$(snap debug api /v2/changes?select=all | jq '.result | sort_by(.id) | .[-1].id')
LAST_CHANGE_ID=$(snap debug api /v2/changes?select=all | jq '.result | sort_by(.id|tonumber) | .[-1].id')
# -------- FIRST AUTO REFRESH --------
Expand Down Expand Up @@ -162,7 +162,7 @@ execute: |
readlink "$SNAP_MOUNT_DIR/$SNAP_TWO/current" | MATCH 33
echo "Check auto-refresh behaviour matches expectations for backoff algorithm"
snap debug api /v2/changes?select=ready | jq "[.result[] | select(.kind == \"auto-refresh\" and (.id|tonumber) > ($LAST_CHANGE_ID|tonumber))] | sort_by(.id)" > changes.json
snap debug api /v2/changes?select=ready | jq "[.result[] | select(.kind == \"auto-refresh\" and (.id|tonumber) > ($LAST_CHANGE_ID|tonumber))] | sort_by(.id|tonumber)" > changes.json
# 1st auto-refresh
jq '.[0].status' < changes.json | MATCH "Error"
Expand Down

0 comments on commit adab44d

Please sign in to comment.