Skip to content

Commit

Permalink
fix: clear stop_download on_enter
Browse files Browse the repository at this point in the history
this fixes a bug where the stop event would remain set and jobs
that got cancelled or deleted while on download would make
upparat being stuck without being able to download a next job.

Workaround was restarting upparat.
  • Loading branch information
livioso committed Mar 5, 2020
1 parent 62d7e35 commit acaadd1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/upparat/statemachine/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def clean_previous_downloads(self):
os.remove(download_file_path)

def start_download_thread(self):
# event could still be set from the previous job
# that has been cancelled or deleted, so clear it.
self.stop_download.clear()
self.clean_previous_downloads()

logger.debug(f"Start download for job {self.job.id_}.")
Expand Down
14 changes: 14 additions & 0 deletions tests/statemachine/download_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ def download_state(mocker, tmpdir):
return state, inbox, mqtt_client, statemachine, run_hook


def test_on_enter_clear_stop_event(mocker, download_state, urllib_urlopen_mock):
mocker.patch("urllib.request.urlopen", urllib_urlopen_mock())
state, inbox, _, _, _ = download_state

# previous job got cancelled
state.on_job_cancelled(None, None)

# next job should clear event
# before starting the download
state.on_enter(None, None)

assert not state.stop_download.is_set()


def test_download_completed_on_http_416(mocker, download_state, urllib_urlopen_mock):
side_effect = create_http_error(416)
urlopen_mock = urllib_urlopen_mock(side_effect)
Expand Down

0 comments on commit acaadd1

Please sign in to comment.