summaryrefslogtreecommitdiffstats
path: root/test/units/TEST-07-PID1.poll-limit.sh
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2024-05-11 19:17:13 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2024-05-14 12:43:28 +0200
commit7a321b5a21f7ad4ed526ac5a40ea0fabeb2e2ba5 (patch)
tree9464b421b4486e0af21b49706467a1f8053eda8f /test/units/TEST-07-PID1.poll-limit.sh
parenttest: Rework integration test definitions (diff)
downloadsystemd-7a321b5a21f7ad4ed526ac5a40ea0fabeb2e2ba5.tar.xz
systemd-7a321b5a21f7ad4ed526ac5a40ea0fabeb2e2ba5.zip
test: Rename testsuite-XX units to match test name
Having these named differently than the test itself mostly creates unecessary confusion and makes writing logic against the tests harder so let's rename the testsuite-xx units and scripts to just use the test name itself.
Diffstat (limited to 'test/units/TEST-07-PID1.poll-limit.sh')
-rwxr-xr-xtest/units/TEST-07-PID1.poll-limit.sh48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/units/TEST-07-PID1.poll-limit.sh b/test/units/TEST-07-PID1.poll-limit.sh
new file mode 100755
index 0000000000..ca988b2321
--- /dev/null
+++ b/test/units/TEST-07-PID1.poll-limit.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eux
+set -o pipefail
+
+systemd-analyze log-level debug
+
+cat >/run/systemd/system/floodme@.service <<EOF
+[Service]
+ExecStart=true
+EOF
+
+cat >/run/systemd/system/floodme.socket <<EOF
+[Socket]
+ListenStream=/tmp/floodme
+PollLimitIntervalSec=10s
+Accept=yes
+PollLimitBurst=3
+EOF
+
+systemctl daemon-reload
+systemctl start floodme.socket
+
+START=$(date +%s%N)
+
+# Trigger this 100 times in a flood
+for _ in {1..100}; do
+ logger -u /tmp/floodme foo &
+done
+
+# Let some time pass
+sleep 5
+
+END=$(date +%s%N)
+
+PASSED=$((END-START))
+
+# Calculate (round up) how many trigger events could have happened in the passed time
+MAXCOUNT=$(((PASSED+10000000000)*3/10000000000))
+
+# We started 100 connection attempts, but only 3 should have gone through, as per limit
+test "$(systemctl show -P NAccepted floodme.socket)" -le "$MAXCOUNT"
+
+systemctl stop floodme.socket floodme@*.service
+
+rm /run/systemd/system/floodme@.service /run/systemd/system/floodme.socket /tmp/floodme
+
+systemctl daemon-reload