Skip to content

Commit 1aeff01

Browse files
committed
nbd/004: avoid left connection
The test case nbd/004 disconnects /dev/nbd0 in most cases, but sometimes leaves it in connected status. The test case stops the nbd server then /dev/nbd0 does not work even when it is in connected status. This makes "udevadm settle" command to wait for nbd udev events infinitely and causes failures of following test cases. There are two causes of the left connection. The first cause is left nbd-client process. The test case waits for completion of its child process connect_and_disconnect. However, it does not wait for completion of nbd-client process that connect_and_disconnect spawns. After the test case end, the left nbd-client process establishes the connection of /dev/nbd0. The second cause is missing disconnect operation. The connect_and_disconnect process repeats _netlink_connect and _netlink_disconnect. When this process is killed after _netlink_connect and before _netlink_disconnect, the connected status is left. To avoid the left connection, wait for nbd-client process completion and call _netlink_disconnect at the test case end. Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent 11ab7cc commit 1aeff01

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

tests/nbd/004

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ connect_and_disconnect() {
3131
test() {
3232
echo "Running ${TEST_NAME}"
3333

34+
local pid1 pid2 i=0
35+
3436
_start_nbd_server_netlink
3537

3638
module_load_and_unload &
@@ -53,6 +55,18 @@ test() {
5355
echo "Fail"
5456
fi
5557

58+
# Ensure nbd-client completion and clean up left connection
59+
# shellcheck disable=SC2009
60+
while ps | grep -qe nbd-client; do
61+
sleep .5
62+
if ((i == 10)); then
63+
echo "nbd-client process is left"
64+
break
65+
fi
66+
i=$((i + 1))
67+
done
68+
_netlink_disconnect
69+
5670
echo "Test complete"
5771
}
5872

0 commit comments

Comments
 (0)