mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 00:55:07 +08:00
🐛 fix bug and improve test coverage
This commit is contained in:
parent
b3d0e7c548
commit
f6308916ad
@ -21,7 +21,7 @@ async def matcher_mutex(event: Event) -> Generator[bool, None, None]:
|
||||
else:
|
||||
_running_matcher[session_id] = current_event_id
|
||||
yield result
|
||||
if result:
|
||||
if not result:
|
||||
del _running_matcher[session_id]
|
||||
|
||||
|
||||
|
@ -7,22 +7,30 @@ from utils import make_fake_event
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_matcher_mutex():
|
||||
from nonebot.plugins.single_session import matcher_mutex
|
||||
from nonebot.plugins.single_session import matcher_mutex, _running_matcher
|
||||
|
||||
am = asynccontextmanager(matcher_mutex)
|
||||
event = make_fake_event()()
|
||||
event_1 = make_fake_event()()
|
||||
event_2 = make_fake_event(_session_id="test1")()
|
||||
event_3 = make_fake_event(_session_id=None)()
|
||||
|
||||
async with am(event) as ctx:
|
||||
assert ctx == False
|
||||
assert not _running_matcher
|
||||
|
||||
async with am(event) as ctx:
|
||||
async with am(event_1) as ctx_1:
|
||||
assert ctx == False
|
||||
assert ctx_1 == True
|
||||
assert not _running_matcher
|
||||
|
||||
async with am(event) as ctx:
|
||||
async with am(event_2) as ctx_2:
|
||||
assert ctx == False
|
||||
assert ctx_2 == False
|
||||
assert not _running_matcher
|
||||
|
||||
async with am(event_3) as ctx_3:
|
||||
assert ctx_3 == False
|
||||
assert not _running_matcher
|
||||
|
@ -50,7 +50,7 @@ def make_fake_event(
|
||||
_name: str = "test",
|
||||
_description: str = "test",
|
||||
_user_id: str = "test",
|
||||
_session_id: str = "test",
|
||||
_session_id: Optional[str] = "test",
|
||||
_message: Optional["Message"] = None,
|
||||
_to_me: bool = True,
|
||||
**fields,
|
||||
@ -73,7 +73,9 @@ def make_fake_event(
|
||||
return _user_id
|
||||
|
||||
def get_session_id(self) -> str:
|
||||
return _session_id
|
||||
if _session_id is not None:
|
||||
return _session_id
|
||||
raise NotImplementedError
|
||||
|
||||
def get_message(self) -> "Message":
|
||||
if _message is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user