Fix flaky test

This commit is contained in:
Nuno Campos
2024-09-22 12:37:24 -07:00
parent 33d18593bf
commit e76f49c7f0
3 changed files with 29 additions and 12 deletions
+17
View File
@@ -2,6 +2,23 @@ import re
from typing import Any, Sequence, Union
class FloatBetween(float):
def __init__(self, min_value: float, max_value: float) -> None:
super().__init__()
self.min_value = min_value
self.max_value = max_value
def __eq__(self, other: object) -> bool:
return (
isinstance(other, float)
and other >= self.min_value
and other <= self.max_value
)
def __hash__(self) -> int:
return hash((float(self), self.min_value, self.max_value))
class AnyStr(str):
def __init__(self, prefix: Union[str, re.Pattern] = "") -> None:
super().__init__()
+6 -6
View File
@@ -72,7 +72,7 @@ from langgraph.pregel import (
from langgraph.pregel.retry import RetryPolicy
from langgraph.store.memory import MemoryStore
from langgraph.types import Interrupt, PregelTask, Send, StreamWriter
from tests.any_str import AnyDict, AnyStr, AnyVersion, UnsortedSequence
from tests.any_str import AnyDict, AnyStr, AnyVersion, FloatBetween, UnsortedSequence
from tests.conftest import ALL_CHECKPOINTERS_SYNC, SHOULD_CHECK_SNAPSHOTS
from tests.fake_chat import FakeChatModel
from tests.fake_tracer import FakeTracer
@@ -8596,22 +8596,22 @@ def test_stream_subgraphs_during_execution(
assert chunks == [
# arrives before "inner" finishes
(
0.0,
FloatBetween(0.0, 0.1),
(
(AnyStr("inner:"),),
{"inner_1": {"my_key": "got here", "my_other_key": ""}},
),
),
(0.2, ((), {"outer_1": {"my_key": " and parallel"}})),
(FloatBetween(0.2, 0.3), ((), {"outer_1": {"my_key": " and parallel"}})),
(
0.5,
FloatBetween(0.5, 0.6),
(
(AnyStr("inner:"),),
{"inner_2": {"my_key": " and there", "my_other_key": "got here"}},
),
),
(0.5, ((), {"inner": {"my_key": "got here and there"}})),
(0.5, ((), {"outer_2": {"my_key": " and back again"}})),
(FloatBetween(0.5, 0.6), ((), {"inner": {"my_key": "got here and there"}})),
(FloatBetween(0.5, 0.6), ((), {"outer_2": {"my_key": " and back again"}})),
]
+6 -6
View File
@@ -70,7 +70,7 @@ from langgraph.pregel import (
from langgraph.pregel.retry import RetryPolicy
from langgraph.store.memory import MemoryStore
from langgraph.types import Interrupt, PregelTask, Send, StreamWriter
from tests.any_str import AnyDict, AnyStr, AnyVersion, UnsortedSequence
from tests.any_str import AnyDict, AnyStr, AnyVersion, FloatBetween, UnsortedSequence
from tests.conftest import (
ALL_CHECKPOINTERS_ASYNC,
ALL_CHECKPOINTERS_ASYNC_PLUS_NONE,
@@ -7202,22 +7202,22 @@ async def test_stream_subgraphs_during_execution(checkpointer_name: str) -> None
assert chunks == [
# arrives before "inner" finishes
(
0.0,
FloatBetween(0.0, 0.1),
(
(AnyStr("inner:"),),
{"inner_1": {"my_key": "got here", "my_other_key": ""}},
),
),
(0.2, ((), {"outer_1": {"my_key": " and parallel"}})),
(FloatBetween(0.2, 0.3), ((), {"outer_1": {"my_key": " and parallel"}})),
(
0.5,
FloatBetween(0.5, 0.6),
(
(AnyStr("inner:"),),
{"inner_2": {"my_key": " and there", "my_other_key": "got here"}},
),
),
(0.5, ((), {"inner": {"my_key": "got here and there"}})),
(0.5, ((), {"outer_2": {"my_key": " and back again"}})),
(FloatBetween(0.5, 0.6), ((), {"inner": {"my_key": "got here and there"}})),
(FloatBetween(0.5, 0.6), ((), {"outer_2": {"my_key": " and back again"}})),
]