forked from reanahub/reana-workflow-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
consumer: daemon to not die on errors
* Currently if an exception would be raised during workflow status update, the changes would not be saved in DB, causing for example inconsistencies if calls to Kubernetes fail for some reason, leaving workflows in running state forever (addresses reanahub/reana#478).
- Loading branch information
Diego Rodriguez
committed
Feb 12, 2021
1 parent
345558b
commit 956691d
Showing
2 changed files
with
98 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of REANA. | ||
# Copyright (C) 2021 CERN. | ||
# | ||
# REANA is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""REANAN Workflow Controller consumer tests.""" | ||
|
||
import pytest | ||
from kubernetes.client.rest import ApiException | ||
from mock import Mock, patch | ||
from reana_commons.config import MQ_DEFAULT_QUEUES | ||
from reana_commons.consumer import BaseConsumer | ||
from reana_commons.publisher import WorkflowStatusPublisher | ||
from reana_db.models import RunStatus | ||
|
||
from reana_workflow_controller.consumer import JobStatusConsumer | ||
|
||
|
||
def test_workflow_finish_and_kubernetes_not_available( | ||
in_memory_queue_connection, sample_serial_workflow_in_db, consume_queue, | ||
): | ||
"""Test workflow finish with a Kubernetes connection troubles.""" | ||
sample_serial_workflow_in_db.status = RunStatus.running | ||
next_status = RunStatus.failed | ||
job_status_consumer = JobStatusConsumer(connection=in_memory_queue_connection) | ||
job_status_consumer.queue | ||
workflow_status_publisher = WorkflowStatusPublisher( | ||
connection=in_memory_queue_connection, queue=job_status_consumer.queue | ||
) | ||
workflow_status_publisher.publish_workflow_status( | ||
str(sample_serial_workflow_in_db.id_), next_status.value, | ||
) | ||
k8s_corev1_api_client_mock = Mock() | ||
k8s_corev1_api_client_mock.delete_namespaced_job = Mock( | ||
side_effect=ApiException(reason="Could not delete job.", status=404) | ||
) | ||
with patch( | ||
"reana_workflow_controller.consumer.current_k8s_corev1_api_client", | ||
k8s_corev1_api_client_mock, | ||
): | ||
consume_queue(job_status_consumer, limit=1) | ||
assert sample_serial_workflow_in_db.status == next_status |