Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle server-timing header merging #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cfspeedtest/cloudflare.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from __future__ import annotations

import logging
import re
import statistics
import time
from enum import Enum
Expand All @@ -16,6 +17,8 @@

log = logging.getLogger("cfspeedtest")

TIMING_DURATION_RE = re.compile(r"dur=([0-9.]+)")


class TestType(Enum):
"""The type of an individual test."""
Expand Down Expand Up @@ -191,9 +194,8 @@ def run_test(self, test: TestSpec) -> TestTimers:
test.type.value, url, data=data, timeout=self.timeout
)
coll.full.append(time.time() - start)
coll.server.append(
float(r.headers["Server-Timing"].split("=")[1].split(",")[0]) / 1e3
)
timing_match = TIMING_DURATION_RE.search(r.headers["Server-Timing"])
coll.server.append(float(timing_match.group(1)) / 1e3)
Comment on lines +197 to +198
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In its current state, this change is fallible - much like before, but in a way that will crash instead of returning an erroneous value. We could handle this condition, but short of reporting None to invalidate the entire test, it would involve some compromise.

coll.request.append(
r.elapsed.seconds + r.elapsed.microseconds / 1e6
)
Expand Down