|
| 1 | +from unittest.mock import Mock |
| 2 | + |
1 | 3 | import pytest
|
2 | 4 | from typing import Text
|
3 | 5 |
|
|
7 | 9 | from asyncio import AbstractEventLoop
|
8 | 10 | from pathlib import Path
|
9 | 11 | from rasa.core import run, interpreter, policies
|
| 12 | +from rasa.core.brokers.sql import SQLEventBroker |
10 | 13 | from rasa.core.utils import AvailableEndpoints
|
11 | 14 |
|
12 | 15 | CREDENTIALS_FILE = "examples/moodbot/credentials.yml"
|
@@ -82,3 +85,27 @@ async def test_load_agent_on_start_with_bad_model_file(
|
82 | 85 | assert isinstance(agent.interpreter, rasa.shared.nlu.interpreter.RegexInterpreter)
|
83 | 86 | assert agent.policy_ensemble is None
|
84 | 87 | assert isinstance(agent.domain, rasa.shared.core.domain.Domain)
|
| 88 | + |
| 89 | + |
| 90 | +async def test_close_resources(loop: AbstractEventLoop): |
| 91 | + broker = SQLEventBroker() |
| 92 | + app = Mock() |
| 93 | + app.agent.tracker_store.event_broker = broker |
| 94 | + |
| 95 | + with pytest.warns(None) as warnings: |
| 96 | + await run.close_resources(app, loop) |
| 97 | + |
| 98 | + assert len(warnings) == 0 |
| 99 | + |
| 100 | + |
| 101 | +async def test_close_resources_with_sync(loop: AbstractEventLoop): |
| 102 | + class TestBroker(SQLEventBroker): |
| 103 | + def close(self) -> None: |
| 104 | + pass |
| 105 | + |
| 106 | + broker = TestBroker() |
| 107 | + app = Mock() |
| 108 | + app.agent.tracker_store.event_broker = broker |
| 109 | + |
| 110 | + with pytest.warns(FutureWarning): |
| 111 | + await run.close_resources(app, loop) |
0 commit comments