Skip to content

Commit

Permalink
fix (vscode) - schedule vscode status check using kivy.clock.Clock
Browse files Browse the repository at this point in the history
…instead of `asyncio` - closes #101
  • Loading branch information
sassanh committed May 14, 2024
1 parent d250c88 commit a358c6e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 40 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
is set/cleared - closes #105
- fix(camera) - back button in the camera viewfinder doesn't cancel the parent application/menu
- closes #106
- fix (vscode) - schedule vscode status check using `kivy.clock.Clock` instead of
`asyncio` - closes #101

## Version 0.14.1

Expand Down
64 changes: 48 additions & 16 deletions tests/fixtures/stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import asyncio
from typing import TYPE_CHECKING, Protocol

import pytest
Expand All @@ -10,6 +11,9 @@
from tests.fixtures.snapshot import write_image

if TYPE_CHECKING:
from collections.abc import Callable, Coroutine

from numpy._typing import NDArray
from redux_pytest.fixtures import StoreSnapshot
from redux_pytest.fixtures.wait_for import AsyncWaiter, WaitFor

Expand All @@ -27,10 +31,46 @@ async def __call__(
...


async def _run(
*,
check: Callable[[], Coroutine],
store_snapshot: StoreSnapshot,
window_snapshot: WindowSnapshot,
store_snapshots: list[str],
window_snapshots: list[NDArray],
) -> None:
await asyncio.sleep(2)
for _ in range(3):
try:
await check()
except RetryError as exception:
if isinstance(exception.last_attempt.exception(), AssertionError):
continue
raise
except AssertionError:
continue

try:
await check()
except RetryError:
for i, snapshot in enumerate(store_snapshots):
(
store_snapshot.results_dir
/ f'store-unstability_snapshot_{i}.mismatch.jsonc'
).write_text(snapshot)
for i, snapshot in enumerate(window_snapshots):
write_image(
window_snapshot.results_dir
/ f'window-unstability_snapshot_{i}.mismatch.png',
snapshot,
)
raise


@pytest.fixture()
async def stability(
window_snapshot: WindowSnapshot,
store_snapshot: StoreSnapshot,
window_snapshot: WindowSnapshot,
wait_for: WaitFor,
) -> AsyncWaiter:
"""Wait for the screen and store to stabilize."""
Expand Down Expand Up @@ -72,20 +112,12 @@ def check() -> None:
assert is_window_stable, 'The content of the screen is not stable yet'
assert is_store_stable, 'The content of the store is not stable yet'

try:
await check()
except RetryError:
for i, snapshot in enumerate(store_snapshots):
(
store_snapshot.results_dir
/ f'store-unstability_snapshot_{i}.mismatch.jsonc'
).write_text(snapshot)
for i, snapshot in enumerate(window_snapshots):
write_image(
window_snapshot.results_dir
/ f'window-unstability_snapshot_{i}.mismatch.png',
snapshot,
)
raise
await _run(
check=check,
store_snapshot=store_snapshot,
window_snapshot=window_snapshot,
store_snapshots=store_snapshots,
window_snapshots=window_snapshots,
)

return wrapper
22 changes: 3 additions & 19 deletions tests/integration/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

from __future__ import annotations

import asyncio
from typing import TYPE_CHECKING

from tenacity import RetryError

if TYPE_CHECKING:
from redux_pytest.fixtures import StoreSnapshot

Expand Down Expand Up @@ -45,19 +42,6 @@ async def test_all_services_register(
app = MenuApp()
app_context.set_app(app)
load_services(ALL_SERVICES_IDS, timeout=10)
for _ in range(3):
try:
await asyncio.sleep(3)
await stability(timeout=3)
store_snapshot.take()
window_snapshot.take()
break
except RetryError as exception:
if isinstance(exception.last_attempt.exception(), AssertionError):
continue
raise
except AssertionError:
continue
else:
store_snapshot.take()
window_snapshot.take()
await stability()
store_snapshot.take()
window_snapshot.take()
7 changes: 3 additions & 4 deletions ubo_app/services/050-vscode/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from commands import check_status, install_service, uninstall_service
from constants import CODE_BINARY_PATH, CODE_BINARY_URL, DOWNLOAD_PATH
from kivy.clock import Clock
from kivy.lang.builder import Builder
from login_page import LoginPage
from ubo_gui.constants import DANGER_COLOR
Expand Down Expand Up @@ -231,16 +232,14 @@ def generate_vscode_menu() -> Callable[[], HeadedMenu]:
return vscode_menu


async def init_service() -> None:
def init_service() -> None:
dispatch(
RegisterSettingAppAction(
menu_item=ActionItem(label='VSCode', icon='󰨞', action=generate_vscode_menu),
category=SettingsCategory.REMOTE,
),
)
while True:
await asyncio.sleep(5)
await check_status()
Clock.schedule_interval(lambda _: create_task(check_status()), 5)


Builder.load_file(
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/050-vscode/ubo_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async def setup(service: Service) -> None:
from setup import init_service

service.register_reducer(reducer)
await init_service()
init_service()


register(
Expand Down

0 comments on commit a358c6e

Please sign in to comment.