Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions tests/main/confdb-cross-config/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ prepare: |

restore: |
snap unset system experimental.confdb
rm first_read last_read || true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rm first_read last_read || true
rm first-read last-read password=last-password || true

But tbh I don't even know if this is needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

password=last-password isn't a file, it's the key-value set for one of the writes


execute: |
changeAfterID() {
Expand Down Expand Up @@ -151,3 +152,39 @@ execute: |
MATCH 'written-secret-changed' < /var/snap/loading-custodian/common/load-view-manage-wifi-ran
# but query-view gets the value load-view sets
MATCH "loaded-secret" < /var/snap/loading-custodian/common/query-view-manage-wifi-ran

# waiting-custodian will block on write or read ops until a flag is written
resetTestState
snap disconnect loading-custodian:manage-wifi
"$TESTSTOOLS"/snaps-state install-local waiting-custodian
snap connect waiting-custodian:wifi-setup

OLD_CHANGE=$(snap changes | tail -n 2 | head -n 1 | awk '{print $1}')
snap set developer1/network-ephemeral/wifi-setup password=initial-password &

# first change blocks on the save-view-* hook
changeAfterID "$OLD_CHANGE"
retry -n 5 --wait 1 sh -c 'snap changes | tail -n 2 | grep "Doing.*Set confdb through \"developer1/network-ephemeral/wifi-setup\""'
BLOCKED_CHANGE=$(( OLD_CHANGE + 1 ))
snap change "$BLOCKED_CHANGE" | MATCH "Doing.*Run hook save-view-wifi-setup"

# the access timeout should make this call error without being unblocked
timeout -s KILL 2s snap get developer1/network-ephemeral/wifi-setup --wait-for 0s password 2>&1 | tr -d "\n" | tr -s ' ' ' ' | MATCH "error: cannot read developer1/network-ephemeral/wifi-setup: timed out waiting for access"

# queue a series of operations that will block on the previous one sequentially
sleep 1
snap get developer1/network-ephemeral/wifi-setup password > first-read &
sleep 1
snap set developer1/network-ephemeral/wifi-setup password=last-password &
sleep 1
snap get developer1/network-ephemeral/wifi-setup password > last-read &

# unblock the first write and wait for the next operations to complete
touch /var/snap/waiting-custodian/common/flag
wait

retry -n 5 --wait 1 sh -c 'snap changes | tail -n 2 | grep "Done.*Get confdb through \"developer1/network-ephemeral/wifi-setup\""'

# check the operations executed in the expected order
MATCH "initial-password" < first-read
MATCH "last-password" < last-read
3 changes: 3 additions & 0 deletions tests/main/confdb-cross-config/waiting-custodian/bin/sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

exec /bin/sh "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

until [ -e "$SNAP_COMMON"/flag ]; do
sleep 2
done
12 changes: 12 additions & 0 deletions tests/main/confdb-cross-config/waiting-custodian/meta/snap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: waiting-custodian
version: 1.0
apps:
sh:
command: bin/sh
base: core24
plugs:
wifi-setup:
interface: confdb
account: developer1
view: network-ephemeral/wifi-setup
role: custodian
Loading