Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion gate/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ def _wait_for_connectivity(max_wait: float = 30.0) -> bool:
s.close()
except Exception:
pass
time.sleep(min(2.0, deadline - time.monotonic()))
remaining = deadline - time.monotonic()
if remaining <= 0:
break
time.sleep(min(2.0, remaining))
logger.warning(f"GitHub unreachable after {max_wait}s of probing")
return False

Expand Down
30 changes: 30 additions & 0 deletions tests/test_github.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Tests for gate.github module."""

import socket
import subprocess
from unittest.mock import patch

from gate import github
from gate.github import (
_build_comment,
_format_build_section,
Expand All @@ -16,6 +18,34 @@
)


class TestWaitForConnectivity:
def test_timeout_does_not_sleep_negative(self, monkeypatch):
class FakeSocket:
def settimeout(self, _timeout):
pass

def connect(self, _target):
raise TimeoutError("timed out")

def close(self):
pass

times = iter([0.0, 0.0, 6.0])
sleeps: list[float] = []

monkeypatch.setattr(
socket,
"getaddrinfo",
lambda *_args, **_kwargs: [(None, None, None, None, ("127.0.0.1", 443))],
)
monkeypatch.setattr(socket, "socket", lambda *_args, **_kwargs: FakeSocket())
monkeypatch.setattr(github.time, "monotonic", lambda: next(times))
monkeypatch.setattr(github.time, "sleep", sleeps.append)

assert github._wait_for_connectivity(max_wait=5.0) is False
assert sleeps == []


class TestFormatFindings:
def test_empty_findings(self):
assert _format_findings([]) == ""
Expand Down
Loading