Skip to content
Snippets Groups Projects
Commit ef9b3b70 authored by Nathan Hertz's avatar Nathan Hertz
Browse files

Modified a few tests to make them work

parent e85c771b
No related branches found
No related tags found
1 merge request!27SSA-6824: Fix failing tests
Pipeline #336 passed
......@@ -5,20 +5,20 @@ Testing suite for wf_monitor. Currently not covered by tests:
"""
import logging
import time
import os
import threading
import time
import pytest
import threading
from pytest_mock import MockerFixture
from wf_monitor.monitor import WorkflowMonitor
from workspaces.schema import WorkflowEventType
from wf_monitor.monitor import WorkflowMonitor
os.environ["CAPO_PROFILE"] = "local"
log_path = 'logs/condor.log'
os.environ["CAPO_PROFILE"] = "docker"
log_path = "logs/condor.log"
test_monitor = WorkflowMonitor(log_path, -1)
WORKFLOW_STATUS_EXCH = 'workspaces.workflow-service.workflow-status'
WORKFLOW_STATUS_EXCH = "workspaces.workflow-service.workflow-status"
def test_read_log():
......@@ -27,11 +27,11 @@ def test_read_log():
exist in the example log file
"""
test_strs = [
'Image size of job updated: 72',
'72 - ResidentSetSize of job (KB)',
'(1) Normal termination (return value 0)',
'000 (3983.000.000) 08/26 11:06:06 Job submitted from host: '
'<10.64.1.178:9618?addrs=10.64.1.178-9618&noUDP&sock=4050180_7e37_3>'
"Image size of job updated: 72",
"72 - ResidentSetSize of job (KB)",
"(1) Normal termination (return value 0)",
"000 (3983.000.000) 08/26 11:06:06 Job submitted from host: "
"<10.64.1.178:9618?addrs=10.64.1.178-9618&noUDP&sock=4050180_7e37_3>",
]
for s in test_strs:
assert s in test_monitor.log
......@@ -59,7 +59,7 @@ def test_read_log_slow(caplog):
with open("logs/slow.log", "a") as slow:
slow.write(event)
event = ""
time.sleep(3)
time.sleep(0.5)
thread.join()
assert "Finished monitoring logs/slow.log." in caplog.text
......@@ -70,7 +70,7 @@ def test_read_log_timeout():
Tests the timeout functionality of WorkflowMonitor.read_htcondor_log()
"""
with pytest.raises(SystemExit) as sys_ex:
WorkflowMonitor('logs/file-that-does-not-exist.txt', -1, 1)
WorkflowMonitor("logs/file-that-does-not-exist.txt", -1, 1)
assert sys_ex.type == SystemExit
assert sys_ex.value.code == -1
......@@ -97,7 +97,7 @@ def test_parse_log_error(caplog):
"""
caplog.set_level(logging.INFO)
with pytest.raises(TimeoutError):
WorkflowMonitor('logs/test.log', -1, 5)
WorkflowMonitor("logs/test.log", -1, 5)
msg = (
"HTCondor event not well-formatted. Event contents:\n"
"this will trigger an exception!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
......
from channels.amqp_helpers import workflow_events, CONN, WorkflowEventChannel
from channels.amqp_helpers import CONN, WorkflowEventChannel, workflow_events
from workspaces.schema import WorkflowEvent, WorkflowEventType
def test_workflow_event_sending():
workflow_events.connect(profile='local')
workflow_events.connect(profile="docker")
channel = workflow_events.chan.connection.channel()
queue = channel.queue_declare(queue='', exclusive=True).method.queue
channel.queue_bind(queue=queue, exchange=WorkflowEventChannel.EXCHANGE, routing_key='#')
workflow_events.send(WorkflowEvent('name', 'id', WorkflowEventType.OTHER, '2020-01-01', 'Nothing to log'))
queue = channel.queue_declare(queue="", exclusive=True).method.queue
channel.queue_bind(
queue=queue, exchange=WorkflowEventChannel.EXCHANGE, routing_key="#"
)
workflow_events.send(
WorkflowEvent(
"-1", "name", "-1", WorkflowEventType.OTHER, "2020-01-01", "Nothing to log"
)
)
method, header, body = channel.basic_get(queue)
if method:
print(body)
from typing import List
from workspaces.capability_interfaces import (
CapabilityInfoIF,
CapabilityExecutionIF,
CapabilityIF,
CapabilityRequestIF,
CapabilityInfoIF,
CapabilityName,
CapabilityRequestIF,
)
from workspaces.helpers import ExecutionState, CapabilityStep
from workspaces.helpers import CapabilityStep, ExecutionState
from workspaces.product_interfaces import FutureProductIF
from workspaces.schema import Capability, CapabilityExecution
from workspaces.services import CapabilityService, CapabilityEngine, WorkflowService
from workspaces.services import CapabilityEngine, CapabilityService, WorkflowService
from .test_workflow_services import FakeWorkflowInfo
......@@ -73,6 +73,9 @@ class FakeCapabilityInfo(CapabilityInfoIF):
if execution_id == execution.id:
return execution
def save_execution(self):
pass
capability_info = FakeCapabilityInfo()
workflow_info = FakeWorkflowInfo()
......
from typing import Dict, List, Union
import json
from typing import Dict, List, Union
import requests
from pycapo import CapoConfig
from workspaces.schema import (
Workflow,
WorkflowTemplate,
WorkflowRequest,
WorkflowRequestFile,
WorkflowTemplate,
)
from workspaces.services import WorkflowService
from workspaces.workflow_interfaces import (
WorkflowInfoIF,
WorkflowIF,
WorkflowRequestIF,
WorkflowInfoIF,
WorkflowRequestFileIF,
WorkflowRequestIF,
)
......@@ -63,7 +63,6 @@ class FakeWorkflowInfo(WorkflowInfoIF):
)
)
return w
raise NotImplementedError
info = FakeWorkflowInfo()
......@@ -73,7 +72,6 @@ def test_workflow_creation():
# This seems like a bit of a blunt instrument for testing the service. We should probably break the service down
# into smaller pieces.
global info
service = WorkflowService(info)
# create request
request = info.create_workflow_request(
......@@ -93,7 +91,7 @@ def test_workflow_request_execution():
"""
settings = CapoConfig().settings("edu.nrao.archive.workspaces.WorkflowSettings")
r1 = requests.post(f"{settings.serviceUrl}/workflows/null/requests/create?args=-g")
request_id = r1.json()['workflow_request_id']
request_id = r1.json()["workflow_request_id"]
r2 = requests.post(f"{settings.serviceUrl}/workflows/requests/{request_id}/submit")
# Assert workflow request execution was received with no error
assert r2.status_code == 200
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment