3
3
from . import formats
4
4
from .lazy_singleton import LazySingleton
5
5
6
+ import tarfile
7
+ import tempfile
6
8
import contextlib
7
9
import faulthandler
8
10
import json
@@ -480,7 +482,6 @@ def down(self):
480
482
Run `docker compose down` to bring down the orchestrated services.
481
483
Join the log-parsing thread.
482
484
"""
483
-
484
485
if self .has_coverage_data ():
485
486
self .create_coverage_tarball ()
486
487
@@ -506,37 +507,45 @@ def down(self):
506
507
507
508
@staticmethod
508
509
def has_coverage_data ():
509
- command = docker_compose_command (
510
- "exec" ,
511
- "-T" ,
512
- "--" ,
513
- "nginx" ,
514
- "bash" ,
515
- "-c" ,
516
- "find /tmp -name '*.profraw' -print -quit | grep -q ." ,
517
- )
518
- result = subprocess .run (command )
519
- return result .returncode == 0
510
+ command = docker_compose_command ("exec" , "-T" , "--" , "nginx" , "find" ,
511
+ "/tmp" , "-name" , "*.profraw" )
512
+ result = subprocess .run (command , capture_output = True )
513
+ if result .returncode != 0 :
514
+ return False
515
+
516
+ return len (result .stdout )
520
517
521
518
@staticmethod
522
519
def create_coverage_tarball ():
523
- tar_command = docker_compose_command (
520
+ cmd = docker_compose_command (
524
521
"exec" ,
525
522
"-T" ,
526
523
"--" ,
527
524
"nginx" ,
528
- "bash" ,
529
- "-c" ,
530
- "tar --transform='s@tmp/@@' -czf - -T <(find /tmp -maxdepth 1 -name '*.profraw')" ,
525
+ "find" ,
526
+ "/tmp" ,
527
+ "-name" ,
528
+ "*.profraw" ,
531
529
)
532
530
533
- with open ("./coverage_data.tar.gz" , "wb" ) as file :
534
- result = subprocess .run (tar_command , stdout = file )
535
-
536
- # Check if the tarball was created successfully
531
+ result = subprocess .run (cmd , capture_output = True )
537
532
if result .returncode != 0 :
538
533
raise Exception ("Failed to create tarball" )
539
534
535
+ with tempfile .TemporaryDirectory () as work_dir :
536
+ files = []
537
+ for src_profraw in result .stdout .decode ().split ():
538
+ out_profraw = os .path .join (work_dir ,
539
+ os .path .basename (src_profraw ))
540
+ cp_cmd = docker_compose_command ("cp" , f"nginx:{ src_profraw } " ,
541
+ out_profraw )
542
+ subprocess .run (cp_cmd , stdout = subprocess .DEVNULL )
543
+ files .append (out_profraw )
544
+
545
+ with tarfile .open ("./coverage_data.tar.gz" , "w:gz" ) as tar :
546
+ for f in files :
547
+ tar .add (f , arcname = os .path .basename (f ))
548
+
540
549
@staticmethod
541
550
def nginx_version ():
542
551
result = subprocess .run (
0 commit comments