22# Tests for handling Unix signals.
33set -xeuo pipefail
44
5- # Enable verbose logging.
6- export COPYQ_LOG_LEVEL=DEBUG
7- export QT_LOGGING_RULES=" *.debug=true;qt.*.debug=false;qt.*.warning=true"
85export COPYQ_SESSION_NAME=__COPYQ_SIGTEST
96
7+ source " $( dirname " $0 " ) /test-start-server.sh"
8+
109exit_code=0
1110
12- ./copyq &
13- copyq_pid=$!
11+ # Test interrupting a long sleep command
12+ if [[ ${COPYQ_TESTS_SKIP_SIGNAL:- 0} == " 1" ]]; then
13+ echo " ⚠️ Skipping signal test"
14+ else
15+ ./copyq ' sleep(100000)' &
16+ copyq_sleep_pid=$!
1417
15- # Wait for server to start
16- for i in {1..3}; do
17- echo " Trying to start CopyQ server ($i )"
18- if ./copyq ' serverLog("Server started")' ; then
19- break
20- elif [[ $i == 5 ]]; then
21- echo " ❌ FAILED: Could not start CopyQ server"
22- exit 1
23- fi
24- sleep $(( i * 2 ))
25- done
18+ sigterm=15
19+ expected_exit_code=$(( 128 + sigterm))
2620
27- sigterm=15
28- expected_exit_code=$(( 128 + sigterm))
29- script_pid=$$
30- {
3121 sleep 2
3222 if ! pkill -$sigterm -f ' ^\./copyq sleep\(100000\)$' ; then
3323 echo " ❌ FAILED: Could not send SIGTERM to the command"
34- kill $script_pid $copyq_pid
24+ kill $copyq_sleep_pid
25+ exit_code=1
3526 fi
36- } &
37- if ./copyq ' sleep(100000)' ; then
38- echo " ❌ FAILED: Interrupt sleep: should exit with an error"
39- else
40- actual_exit_code=$?
41- if [[ $actual_exit_code == $expected_exit_code ]]; then
42- echo " ✅ PASSED: Interrupt sleep: exited with an error as expected"
27+
28+ if wait $copyq_sleep_pid ; then
29+ echo " ❌ FAILED: Interrupt sleep: should exit with an error"
30+ exit_code=1
4331 else
44- echo " ❌ FAILED: Interrupt sleep: expected exit code $expected_exit_code , got $actual_exit_code "
32+ actual_exit_code=$?
33+ if [[ $actual_exit_code == $expected_exit_code ]]; then
34+ echo " ✅ PASSED: Interrupt sleep: exited with an error as expected"
35+ else
36+ echo " ❌ FAILED: Interrupt sleep: expected exit code $expected_exit_code , got $actual_exit_code "
37+ exit_code=1
38+ fi
4539 fi
4640fi
4741
@@ -51,7 +45,7 @@ copyq_sleep_pid=$!
5145./copyq ' while(true){read(9999999);}' &
5246copyq_loop_pid=$!
5347
54- trap " kill -9 $copyq_sleep_pid $copyq_loop_pid " TERM INT
48+ trap " kill -9 $copyq_sleep_pid $copyq_loop_pid || true " TERM INT
5549
5650sleep 2
5751echo " ⏱️ Sending SIGTERM to server"
0 commit comments