|
17 | 17 | environment = cast(Any, environment_module) |
18 | 18 |
|
19 | 19 |
|
20 | | -class PromptRaceCli: |
| 20 | +class TimeoutOnEofCli: |
21 | 21 | def __init__(self) -> None: |
22 | | - self.interrupt_prompt_seen = False |
23 | | - self.closed = False |
| 22 | + self.sent_controls: list[str] = [] |
| 23 | + self.terminated_force: bool | None = None |
| 24 | + |
| 25 | + def sendcontrol(self, key: str) -> None: |
| 26 | + self.sent_controls.append(key) |
24 | 27 |
|
25 | 28 | def expect_exact(self, expected: object, timeout: int) -> None: |
26 | 29 | if expected == pexpect.EOF: |
27 | | - if not self.closed: |
28 | | - raise pexpect.TIMEOUT('process still running') |
29 | | - return |
30 | | - |
31 | | - if expected == 'root@127.0.0.1:mycli_behave_tests>': |
32 | | - self.interrupt_prompt_seen = True |
33 | | - return |
| 30 | + raise pexpect.TIMEOUT('process still running') |
34 | 31 |
|
35 | 32 | raise AssertionError(f'unexpected expectation: {expected!r}') |
36 | 33 |
|
37 | | - def sendcontrol(self, key: str) -> None: |
38 | | - if key == 'c': |
39 | | - return |
40 | | - if key == 'd': |
41 | | - self.closed = self.interrupt_prompt_seen |
| 34 | + def terminate(self, force: bool = False) -> None: |
| 35 | + self.terminated_force = force |
42 | 36 |
|
43 | 37 |
|
44 | | -def test_after_scenario_waits_for_prompt_after_interrupt(monkeypatch, tmp_path) -> None: |
| 38 | +def test_after_scenario_terminates_when_teardown_eof_times_out(monkeypatch, tmp_path) -> None: |
45 | 39 | log_file = tmp_path / 'mycli.test.log' |
46 | 40 | log_file.write_text('') |
47 | 41 | monkeypatch.setattr(environment, 'test_log_file', str(log_file)) |
48 | 42 | monkeypatch.setattr(environment, 'MY_CNF_BACKUP_PATH', str(tmp_path / '.my.cnf.backup')) |
49 | 43 | monkeypatch.setattr(environment, 'MYLOGIN_CNF_BACKUP_PATH', str(tmp_path / '.mylogin.cnf.backup')) |
50 | 44 | monkeypatch.setattr(environment, 'MYLOGIN_CNF_PATH', str(tmp_path / '.mylogin.cnf')) |
51 | 45 |
|
| 46 | + cli = TimeoutOnEofCli() |
52 | 47 | context = SimpleNamespace( |
53 | 48 | atprompt=True, |
54 | | - cli=PromptRaceCli(), |
55 | | - conf={ |
56 | | - 'user': 'root', |
57 | | - 'host': '127.0.0.1', |
58 | | - 'dbname': 'mycli_behave_tests', |
59 | | - }, |
60 | | - currentdb='mycli_behave_tests', |
| 49 | + cli=cli, |
61 | 50 | exit_sent=False, |
62 | 51 | ) |
63 | 52 |
|
64 | 53 | environment.after_scenario(context, SimpleNamespace()) |
| 54 | + |
| 55 | + assert cli.sent_controls == ['c', 'd'] |
| 56 | + assert cli.terminated_force is True |
0 commit comments