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

Improve the map_syncer script and fix tests #213

Merged
merged 2 commits into from
Nov 26, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci_tools_map_syncer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ jobs:
- name: Check Types
run: mypy
- name: Lint
run: ruff . --format=github
run: ruff check --output-format=github .
- name: Test
run: pytest
7 changes: 6 additions & 1 deletion tools/map_syncer/map_syncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import queue
import shutil
import signal
import socket
import sys
import threading
import time
Expand Down Expand Up @@ -48,6 +49,10 @@
DEFAULT_DELETE_AFTER = 4 * 60 * 60 # 4 hours
DEFAULT_POLL_INTERVAL = 10 * 60 # 10 minutes

# In some rare instances, sockets can get stuck. Let's make sure that
# we timeout them after some time for all socket oprations.
socket.setdefaulttimeout(60)


@dataclass
class LiveMapEntry:
Expand Down Expand Up @@ -177,7 +182,7 @@ class SyncOp(Enum):
STOP = 2


if TYPE_CHECKING: # noqa: SIM108
if TYPE_CHECKING:
SyncQueue = queue.Queue[Tuple[SyncOp, str]]
else:
SyncQueue = queue.Queue
Expand Down
9 changes: 5 additions & 4 deletions tools/map_syncer/map_syncer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def test_poller_starts_sync_correctly(mocker: MockerFixture) -> None:
sync_trigger: map_syncer.SyncQueue = queue.Queue()
t = threading.Thread(
target=lambda: map_syncer.polling_sync(
pathlib.Path(""), "", 0, sync_trigger, "http://x.com/health"
pathlib.Path(), "", 0, sync_trigger, "http://x.com/health"
)
)
t.start()
Expand All @@ -245,7 +245,7 @@ def test_poller_catches_exceptions(mocker: MockerFixture) -> None:
sync_files.side_effect = RuntimeError("test")
sync_trigger: map_syncer.SyncQueue = queue.Queue()
t = threading.Thread(
target=lambda: map_syncer.polling_sync(pathlib.Path(""), "", 0, sync_trigger)
target=lambda: map_syncer.polling_sync(pathlib.Path(), "", 0, sync_trigger)
)
t.start()
sync_trigger.put((map_syncer.SyncOp.SYNC, "A"))
Expand All @@ -260,7 +260,7 @@ def test_poller_ignores_duplicate_requests(mocker: MockerFixture) -> None:
sync_files = mocker.patch("map_syncer.sync_files")
sync_trigger: map_syncer.SyncQueue = queue.Queue()
t = threading.Thread(
target=lambda: map_syncer.polling_sync(pathlib.Path(""), "", 0, sync_trigger)
target=lambda: map_syncer.polling_sync(pathlib.Path(), "", 0, sync_trigger)
)
t.start()
for _ in range(10):
Expand Down Expand Up @@ -322,7 +322,8 @@ def test_sync_files_deletes_only_old(live_maps_url: str, fs: FakeFilesystem) ->
assert fs.exists(d / "map_old_1.sd7")
assert not fs.exists(d / "map_old_2.sd7")
assert cast(
Dict[str, int], json.loads(fs.get_object(d / "tombstones.json").contents)
Dict[str, int],
json.loads(fs.get_object(d / "tombstones.json").contents or "{}"),
) == {
"map_old_1.sd7": initial_tombstones["map_old_1.sd7"],
}
18 changes: 9 additions & 9 deletions tools/map_syncer/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
black>=23.3.0
isort>=5.12.0
mypy>=1.4.1
black==23.11.0
isort==5.12.0
mypy==1.7.1
paho-mqtt>=1.6.1
pyfakefs>=5.2.2
pyfakefs>=5.3.1
pytest-httpserver>=1.0.8
pytest-mock>=3.11.1
pytest-mqtt>=0.2.0
pytest>=7.4.0
ruff>=0.0.277
types-paho-mqtt>=1.6.0.6
pytest-mock>=3.12.0
pytest-mqtt>=0.3.1
pytest>=7.4.3
ruff==0.1.6
types-paho-mqtt>=1.6.0.7