Skip to content

Commit

Permalink
Remove test that seems to cause deadlock for python 3.9 during unit t…
Browse files Browse the repository at this point in the history
…ests (#319)

Check withotu test
  • Loading branch information
eyurtsev authored Dec 13, 2023
1 parent c1e0fb2 commit 34b96e5
Showing 1 changed file with 0 additions and 84 deletions.
84 changes: 0 additions & 84 deletions tests/unit_tests/test_server_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1725,90 +1725,6 @@ async def test_feedback_succeeds_when_langsmith_enabled() -> None:
assert json_response == expected_response_json


async def test_feedback_defaults_on_for_hosted() -> None:
"""Tests that the feedback endpoint can accept feedback to langsmith."""

with patch("langserve.api_handler.ls_client") as mocked_ls_client_package:
with patch("langserve.api_handler.tracing_is_enabled") as tracing_is_enabled:
tracing_is_enabled.return_value = True
mocked_client = MagicMock(return_value=None)
mocked_ls_client_package.Client.return_value = mocked_client
mocked_client.create_feedback.return_value = ls_schemas.Feedback(
id="5484c6b3-5a1a-4a87-b2c7-2e39e7a7e4ac",
created_at=datetime.datetime(1994, 9, 19, 9, 19),
modified_at=datetime.datetime(1994, 9, 19, 9, 19),
run_id="f47ac10b-58cc-4372-a567-0e02b2c3d479",
key="silliness",
score=1000,
)

local_app = FastAPI()

# This is the hackiest code ever, but here's how it goes:
#
# Python caches modules when you import them for the first time.
# This is a problem for testing the default behavior of the
# feedback endpoint because it is read in at import time.
#
# We therefore have to do things in this order:
# 1. monkeypatch our env variable for hosting to ensure that the
# feedback endpoint is enabled by default
# 2. import the whole langserve.server module so we can reference
# it directly
# 3. reload the langserve.server module so that it redefines the
# default behavior based on the env variable
# 4. import the add_routes function under a new name so we can
# monkeypatch use it instead of the original add_routes which
# was imported before the env variable was set
# 5. (Later) reload the langserve.server module again outside of the
# monkeypatch context so that the overridden defaults are not
# loaded in
with MonkeyPatch.context() as mp:
mp.setenv("HOSTED_LANGSERVE_ENABLED", "true")
import importlib

import langserve.server

importlib.reload(langserve.server)
from langserve.server import add_routes as add_routes_patched

add_routes_patched(
local_app,
RunnableLambda(lambda foo: "hello"),
)
importlib.reload(langserve.server)

async with get_async_test_client(
local_app, raise_app_exceptions=True
) as async_client:
response = await async_client.post(
"/feedback",
json={
"run_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"key": "silliness",
"score": 1000,
},
)

expected_response_json = {
"run_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"key": "silliness",
"score": 1000,
"created_at": "1994-09-19T09:19:00",
"modified_at": "1994-09-19T09:19:00",
"comment": None,
"correction": None,
"value": None,
}

json_response = response.json()

assert "id" in json_response
del json_response["id"]

assert json_response == expected_response_json


async def test_feedback_fails_when_langsmith_disabled(app: FastAPI) -> None:
"""Tests that feedback is not sent to langsmith if langsmith is disabled."""
with MonkeyPatch.context() as mp:
Expand Down

0 comments on commit 34b96e5

Please sign in to comment.