@@ -49,19 +49,44 @@ def test_pihole_ftl_architecture(docker):
4949 assert platform in func .stdout
5050
5151
52- # Wait 5 seconds for startup, then kill the start.sh script
53- # Finally, check the FTL log to see if it has been shut down cleanly
54- def test_pihole_ftl_clean_shutdown (docker ):
55- func = docker .run (
56- """
57- sleep 5
58- killall --signal 15 start.sh
59- sleep 5
60- grep 'terminated' /var/log/pihole/FTL.log
61- """
52+ # Wait for FTL to start up, then stop the container gracefully
53+ # Finally, check the container logs to see if FTL was shut down cleanly
54+ def test_pihole_ftl_starts_and_shuts_down_cleanly (docker ):
55+ import subprocess
56+ import time
57+
58+ # Get the container ID from the docker fixture
59+ container_id = docker .backend .name
60+
61+ # Wait for FTL to fully start up by checking logs
62+ max_wait_time = 60 # Maximum wait time in seconds
63+ start_time = time .time ()
64+ ftl_started = False
65+
66+ while time .time () - start_time < max_wait_time :
67+ result = subprocess .run (
68+ ["docker" , "logs" , container_id ], capture_output = True , text = True
69+ )
70+
71+ if "########## FTL started" in result .stdout :
72+ ftl_started = True
73+ break
74+
75+ time .sleep (1 ) # Check every second
76+
77+ assert ftl_started , f"FTL did not start within { max_wait_time } seconds"
78+
79+ # Stop the container gracefully (sends SIGTERM)
80+ subprocess .run (["docker" , "stop" , container_id ], check = True )
81+
82+ # Get the container logs
83+ result = subprocess .run (
84+ ["docker" , "logs" , container_id ], capture_output = True , text = True
6285 )
63- assert "INFO: ########## FTL terminated after" in func .stdout
64- assert "(code 0)" in func .stdout
86+
87+ # Check for clean shutdown messages in the logs
88+ assert "INFO: ########## FTL terminated after" in result .stdout
89+ assert "(code 0)" in result .stdout
6590
6691
6792def test_cronfile_valid (docker ):
0 commit comments