Skip to content

Commit

Permalink
fix: When EventStream.stop is called, the next event always is the …
Browse files Browse the repository at this point in the history
…last one
  • Loading branch information
Stranger6667 committed Jun 19, 2021
1 parent bbcbd92 commit 703430c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
`Unreleased`_ - TBD
-------------------

**Fixed**

- When ``EventStream.stop`` is called, the next event always is the last one.

`3.9.2`_ - 2021-06-16
---------------------

Expand Down
4 changes: 4 additions & 0 deletions src/schemathesis/runner/impl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def _generate_events(self, stop_event: threading.Event) -> Generator[events.Exec
def _finish() -> events.Finished:
return events.Finished.from_results(results=results, running_time=time.monotonic() - initialized.start_time)

if stop_event.is_set():
yield _finish()
return

yield initialized

if stop_event.is_set():
Expand Down
5 changes: 5 additions & 0 deletions test/runner/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,11 @@ def test_stop_event_stream(event_stream):
assert isinstance(next(event_stream), events.Finished)


def test_stop_event_stream_immediately(event_stream):
event_stream.stop()
assert isinstance(next(event_stream), events.Finished)


def test_stop_event_stream_after_second_event(event_stream):
next(event_stream)
assert isinstance(next(event_stream), events.BeforeExecution)
Expand Down

0 comments on commit 703430c

Please sign in to comment.