Skip to content

Commit 777b3b3

Browse files
committed
tests: check blocking concurrent confdb accesses
Tests that concurrent confdb accesses to the same databag block when appropriate (no concurrent writes, accesses that can't be parallelized are serviced in order to prevent starvation) and that it's possible to supply a timeout. Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
1 parent 89b23a7 commit 777b3b3

5 files changed

Lines changed: 58 additions & 0 deletions

File tree

tests/main/confdb-cross-config/task.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ prepare: |
1414
1515
restore: |
1616
snap unset system experimental.confdb
17+
rm first_read last_read || true
1718
1819
execute: |
1920
changeAfterID() {
@@ -151,3 +152,39 @@ execute: |
151152
MATCH 'written-secret-changed' < /var/snap/loading-custodian/common/load-view-manage-wifi-ran
152153
# but query-view gets the value load-view sets
153154
MATCH "loaded-secret" < /var/snap/loading-custodian/common/query-view-manage-wifi-ran
155+
156+
# waiting-custodian will block on write or read ops until a flag is written
157+
resetTestState
158+
snap disconnect loading-custodian:manage-wifi
159+
"$TESTSTOOLS"/snaps-state install-local waiting-custodian
160+
snap connect waiting-custodian:wifi-setup
161+
162+
OLD_CHANGE=$(snap changes | tail -n 2 | head -n 1 | awk '{print $1}')
163+
snap set developer1/network-ephemeral/wifi-setup password=initial-password &
164+
165+
# first change blocks on the save-view-* hook
166+
changeAfterID "$OLD_CHANGE"
167+
retry -n 5 --wait 1 sh -c 'snap changes | tail -n 2 | grep "Doing.*Set confdb through \"developer1/network-ephemeral/wifi-setup\""'
168+
BLOCKED_CHANGE=$(( $OLD_CHANGE + 1 ))
169+
snap change "$BLOCKED_CHANGE" | MATCH "Doing.*Run hook save-view-wifi-setup"
170+
171+
# the access timeout should make this call error without being unblocked
172+
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"
173+
174+
# queue a series of operations that will block on the previous one sequentially
175+
sleep 1
176+
snap get developer1/network-ephemeral/wifi-setup password > first-read &
177+
sleep 1
178+
snap set developer1/network-ephemeral/wifi-setup password=last-password &
179+
sleep 1
180+
snap get developer1/network-ephemeral/wifi-setup password > last-read &
181+
182+
# unblock the first write and wait for the next operations to complete
183+
touch /var/snap/waiting-custodian/common/flag
184+
wait
185+
186+
retry -n 5 --wait 1 sh -c 'snap changes | tail -n 2 | grep "Done.*Get confdb through \"developer1/network-ephemeral/wifi-setup\""'
187+
188+
# check the operations executed in the expected order
189+
MATCH "initial-password" < first-read
190+
MATCH "last-password" < last-read
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
exec /bin/sh "$@"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
until [ -e "$SNAP_COMMON"/flag ]; do
4+
sleep 2
5+
done
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
load-view-wifi-setup
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: waiting-custodian
2+
version: 1.0
3+
apps:
4+
sh:
5+
command: bin/sh
6+
base: core24
7+
plugs:
8+
wifi-setup:
9+
interface: confdb
10+
account: developer1
11+
view: network-ephemeral/wifi-setup
12+
role: custodian

0 commit comments

Comments
 (0)