55import json
66import multiprocessing
77import os
8+ import re
89import time
910import traceback
1011from os .path import exists
2021from .normalize import normalize_appmap
2122
2223TEST_HOST = "127.0.0.1"
23- TEST_PORT = 8000
2424
2525_SR = SystemRandom ()
2626
@@ -323,28 +323,25 @@ def test_can_record(self, data_dir, client):
323323 res = client .delete ("/_appmap/record" )
324324 assert res .status_code == 404
325325
326+ @pytest .mark .xdist_group ("group1" )
326327class _TestRecordRequests :
327328 """Common tests for per-requests recording (record requests.)"""
328329
329330 @classmethod
330- def server_url (cls ):
331- return f"http://{ TEST_HOST } :{ TEST_PORT } "
332-
333- @classmethod
334- def record_request_thread (cls ):
331+ def record_request_thread (cls , server_url ):
335332 # I've seen occasional test failures, seemingly because the test servers can't handle the
336333 # barrage of requests. A tiny bit of delay still causes many, many concurrent requests, but
337334 # eliminates the failures.
338335 time .sleep (_SR .uniform (0 , 0.1 ))
339- return requests .get (cls . server_url () + "/test" , timeout = 30 )
336+ return requests .get (server_url + "/test" , timeout = 30 )
340337
341- def record_requests (self , record_remote ):
338+ def record_requests (self , record_remote , server_url ):
342339 # pylint: disable=too-many-locals
343340 if record_remote :
344341 # when remote recording is enabled, this test also
345342 # verifies the global recorder doesn't save duplicate
346343 # events when per-request recording is enabled
347- response = requests .post (self . server_url () + "/_appmap/record" , timeout = 30 )
344+ response = requests .post (server_url + "/_appmap/record" , timeout = 30 )
348345 assert response .status_code == 200
349346
350347 with concurrent .futures .ThreadPoolExecutor (
@@ -354,7 +351,7 @@ def record_requests(self, record_remote):
354351 max_number_of_threads = 400
355352 future_to_request_number = {}
356353 for n in range (max_number_of_threads ):
357- future = executor .submit (self .record_request_thread )
354+ future = executor .submit (self .record_request_thread , server_url )
358355 future_to_request_number [future ] = n
359356
360357 # wait for all threads to complete
@@ -384,9 +381,8 @@ def record_requests(self, record_remote):
384381 appmap_file_name_basename_part = "_" .join (
385382 appmap_file_name_basename .split ("_" )[2 :]
386383 )
387- assert (
388- appmap_file_name_basename_part
389- == "http_127_0_0_1_8000_test.appmap.json"
384+ assert re .match (
385+ r"http_127_0_0_1_8[0-9]*_test.appmap.json" , appmap_file_name_basename_part
390386 )
391387
392388 with open (appmap_file_name , encoding = "utf-8" ) as f :
@@ -414,12 +410,12 @@ def record_requests(self, record_remote):
414410 @pytest .mark .appmap_enabled
415411 @pytest .mark .server (debug = True )
416412 def test_record_requests_with_remote (self , server ):
417- self .record_requests (server .debug )
413+ self .record_requests (server .debug , server . url )
418414
419415 @pytest .mark .appmap_enabled
420416 @pytest .mark .server (debug = False )
421417 def test_record_requests_without_remote (self , server ):
422- self .record_requests (server .debug )
418+ self .record_requests (server .debug , server . url )
423419
424420 @pytest .mark .server (debug = False )
425421 def test_remote_disabled_in_prod (self , server ):
0 commit comments