Debian Codegraph @

tests/test_coverup_117.py

raw symbols SCIP
1 # file scalene/launchbrowser.py:55-64
2 # lines [58, 59, 60, 61, 62, 64]
3 # branches ['58->59', '58->64']
4
5 import pytest
6 import threading
7 import http.server
8 import socket
9 from scalene.launchbrowser import CustomHandler, last_heartbeat
10 import time
11
12
13 @pytest.fixture(scope="module")
14 def server():
15 # Setup: start a simple HTTP server in a separate thread
16 httpd = http.server.HTTPServer(("localhost", 0), CustomHandler)
17 server_thread = threading.Thread(target=httpd.serve_forever)
18 server_thread.daemon = True
19 server_thread.start()
20 yield httpd
21 # Teardown: stop the server
22 httpd.shutdown()
23 server_thread.join()
24
25
26 def test_heartbeat(server):
27 # Get the server address and port
28 host, port = server.server_address
29 # Send a GET request to the /heartbeat path
30 conn = http.client.HTTPConnection(host, port)
31 conn.request("GET", "/heartbeat")
32 response = conn.getresponse()
33 # Check that the response is OK
34 assert response.status == 200
35 # Check that the last_heartbeat global variable was updated
36 now = time.time()
37 assert last_heartbeat <= now
38 # Clean up
39 conn.close()