Skip to content

Commit c32eb05

Browse files
committed
fix(test): collect coverage without using bash
Recent versions of `nginx:x-alpine` docker images does not have `bash` installed anymore making the collection of code coverage failing. This remove the dependency on bash.
1 parent bcb891f commit c32eb05

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

test/cases/orchestration.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from . import formats
44
from .lazy_singleton import LazySingleton
55

6+
import tarfile
7+
import tempfile
68
import contextlib
79
import faulthandler
810
import json
@@ -480,7 +482,6 @@ def down(self):
480482
Run `docker compose down` to bring down the orchestrated services.
481483
Join the log-parsing thread.
482484
"""
483-
484485
if self.has_coverage_data():
485486
self.create_coverage_tarball()
486487

@@ -506,37 +507,45 @@ def down(self):
506507

507508
@staticmethod
508509
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)
520517

521518
@staticmethod
522519
def create_coverage_tarball():
523-
tar_command = docker_compose_command(
520+
cmd = docker_compose_command(
524521
"exec",
525522
"-T",
526523
"--",
527524
"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",
531529
)
532530

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)
537532
if result.returncode != 0:
538533
raise Exception("Failed to create tarball")
539534

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+
540549
@staticmethod
541550
def nginx_version():
542551
result = subprocess.run(

0 commit comments

Comments
 (0)