Skip to content

Commit 4726cc5

Browse files
chore(tests): simplify get_platform test
`nest_asyncio` is archived and broken on some platforms so it's not worth keeping in our test suite.
1 parent d1fea1c commit 4726cc5

File tree

3 files changed

+6
-49
lines changed

3 files changed

+6
-49
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ dev-dependencies = [
5656
"dirty-equals>=0.6.0",
5757
"importlib-metadata>=6.7.0",
5858
"rich>=13.7.1",
59-
"nest_asyncio==1.6.0",
6059
"pytest-xdist>=3.6.1",
6160
"paramiko>=3.5.1",
6261
"anthropic>=0.45.2",

requirements-dev.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ multidict==6.4.4
8989
mypy==1.14.1
9090
mypy-extensions==1.0.0
9191
# via mypy
92-
nest-asyncio==1.6.0
9392
nodeenv==1.8.0
9493
# via pyright
9594
nox==2023.4.22

tests/test_client.py

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
import os
77
import sys
88
import json
9-
import time
109
import asyncio
1110
import inspect
12-
import subprocess
1311
import tracemalloc
1412
from typing import Any, Union, cast
15-
from textwrap import dedent
1613
from unittest import mock
1714
from typing_extensions import Literal
1815

@@ -23,14 +20,17 @@
2320

2421
from gitpod import Gitpod, AsyncGitpod, APIResponseValidationError
2522
from gitpod._types import Omit
23+
from gitpod._utils import asyncify
2624
from gitpod._models import BaseModel, FinalRequestOptions
2725
from gitpod._exceptions import GitpodError, APIStatusError, APITimeoutError, APIResponseValidationError
2826
from gitpod._base_client import (
2927
DEFAULT_TIMEOUT,
3028
HTTPX_DEFAULT_TIMEOUT,
3129
BaseClient,
30+
OtherPlatform,
3231
DefaultHttpxClient,
3332
DefaultAsyncHttpxClient,
33+
get_platform,
3434
make_request_options,
3535
)
3636

@@ -1683,50 +1683,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
16831683

16841684
assert response.http_request.headers.get("x-stainless-retry-count") == "42"
16851685

1686-
def test_get_platform(self) -> None:
1687-
# A previous implementation of asyncify could leave threads unterminated when
1688-
# used with nest_asyncio.
1689-
#
1690-
# Since nest_asyncio.apply() is global and cannot be un-applied, this
1691-
# test is run in a separate process to avoid affecting other tests.
1692-
test_code = dedent("""
1693-
import asyncio
1694-
import nest_asyncio
1695-
import threading
1696-
1697-
from gitpod._utils import asyncify
1698-
from gitpod._base_client import get_platform
1699-
1700-
async def test_main() -> None:
1701-
result = await asyncify(get_platform)()
1702-
print(result)
1703-
for thread in threading.enumerate():
1704-
print(thread.name)
1705-
1706-
nest_asyncio.apply()
1707-
asyncio.run(test_main())
1708-
""")
1709-
with subprocess.Popen(
1710-
[sys.executable, "-c", test_code],
1711-
text=True,
1712-
) as process:
1713-
timeout = 10 # seconds
1714-
1715-
start_time = time.monotonic()
1716-
while True:
1717-
return_code = process.poll()
1718-
if return_code is not None:
1719-
if return_code != 0:
1720-
raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code")
1721-
1722-
# success
1723-
break
1724-
1725-
if time.monotonic() - start_time > timeout:
1726-
process.kill()
1727-
raise AssertionError("calling get_platform using asyncify resulted in a hung process")
1728-
1729-
time.sleep(0.1)
1686+
async def test_get_platform(self) -> None:
1687+
platform = await asyncify(get_platform)()
1688+
assert isinstance(platform, (str, OtherPlatform))
17301689

17311690
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
17321691
# Test that the proxy environment variables are set correctly

0 commit comments

Comments
 (0)