summaryrefslogtreecommitdiffstats
path: root/test/units/testsuite-60.sh
blob: 8158754667626c3f7d3f417a21deb00227de8a20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
set -eux
set -o pipefail

systemd-analyze log-level debug
systemd-analyze log-target journal

NUM_DIRS=20

# mount/unmount enough times to trigger the /proc/self/mountinfo parsing rate limiting

for ((i = 0; i < NUM_DIRS; i++)); do
    mkdir "/tmp/meow${i}"
done

for ((i = 0; i < NUM_DIRS; i++)); do
    mount -t tmpfs tmpfs "/tmp/meow${i}"
done

systemctl daemon-reload
systemctl list-units -t mount tmp-meow* | grep -q tmp-meow

for ((i = 0; i < NUM_DIRS; i++)); do
    umount "/tmp/meow${i}"
done

# figure out if we have entered the rate limit state

exited_rl=0
timeout="$(date -ud "2 minutes" +%s)"
while [[ $(date -u +%s) -le ${timeout} ]]; do
    if journalctl -u init.scope | grep -q "(mount-monitor-dispatch) entered rate limit"; then
        entered_rl=1
        break
    fi
    sleep 5
done

# if the infra is slow we might not enter the rate limit state; in that case skip the exit check

if [ "${entered_rl}" = "1" ]; then
    exited_rl=0
    timeout="$(date -ud "2 minutes" +%s)"
    while [[ $(date -u +%s) -le ${timeout} ]]; do
        if journalctl -u init.scope | grep -q "(mount-monitor-dispatch) left rate limit"; then
            exited_rl=1
            break
        fi
        sleep 5
    done

    if [ "${exited_rl}" = "0" ]; then
        exit 24
    fi
fi

# give some time for units to settle so we don't race between exiting the rate limit state and cleaning up the units

sleep 60
systemctl daemon-reload
sleep 60

# verify that the mount units are always cleaned up at the end

if systemctl list-units -t mount tmp-meow* | grep -q tmp-meow; then
    exit 42
fi

systemd-analyze log-level info

echo OK >/testok

exit 0