Skip to content

Commit

Permalink
Skip advisories with no creation time when calculating processing time
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah256 committed Aug 12, 2019
1 parent 28ec4d8 commit 411840b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
9 changes: 9 additions & 0 deletions estuary/utils/story.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@ def get_total_processing_time(self, results):
completion_time = datetime.utcnow()
if build:
creation_time = artifact.attached_build_time(artifact, build)
if not creation_time:
creation_time = getattr(build, timed_processes[build.__label__][1])
if not build or not creation_time:
log.warning(
'While calculating the processing time, a %s with ID %s was '
'encountered without a build or creation time.',
artifact.__label__, getattr(artifact,
artifact.unique_id_property + '_'))
continue

# We do not want the processing time of the entire FreshmakerEvent, just the
# processing time until the displayed ContainerKojiBuild is created
Expand Down
32 changes: 29 additions & 3 deletions tests/api/test_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_full_module_timeline():
'state': 'SHIPPED_LIVE',
'created_at': datetime(2019, 1, 1, 0, 0, 40),
'status_time': datetime(2019, 1, 1, 0, 0, 50)
}, [10.0, 10.0, [0], 0]),
}, [0, 10.0, [0], 0]),
('FreshmakerEvent', {
'id_': '5555',
'time_created': datetime(2019, 1, 1, 0, 1, 0),
Expand All @@ -145,7 +145,7 @@ def test_full_module_timeline():
'state': 'SHIPPED_LIVE',
'created_at': datetime(2019, 1, 1, 0, 1, 40),
'status_time': datetime(2019, 1, 1, 0, 1, 50)
}, [10.0, 10.0, [0], 0]),
}, [0, 10.0, [0], 0]),
])
def test_individual_nodes(label, data, expected):
"""Test the data relating to the timeline with only one node."""
Expand Down Expand Up @@ -381,7 +381,7 @@ def test_event_no_time(caplog):
assert flag is True


def test_no_attached_build(caplog):
def test_unattached_build(caplog):
"""Test when there is an advisory without an attached build."""
build = helpers.make_artifact('KojiBuild', **{
'id_': '3333',
Expand Down Expand Up @@ -410,3 +410,29 @@ def test_no_attached_build(caplog):
('estuary', logging.WARNING, 'While calculating the wait time, a Advisory with ID 4444 was'
' encountered without an attached build time.')
]


def test_no_attached_build(caplog):
"""Test when there is an advisory without an attached build."""
advisory = helpers.make_artifact('Advisory', **{
'id_': '4444',
'state': 'QE',
'created_at': datetime(2019, 1, 1, 0, 0, 40),
'status_time': datetime(2019, 1, 1, 0, 0, 50),
'attached_builds': None
})
event = helpers.make_artifact('FreshmakerEvent', **{
'id_': '5555',
'time_created': datetime(2019, 1, 1, 0, 1, 0),
'time_done': datetime(2019, 1, 1, 0, 1, 10),
'state_name': 'COMPLETE'
})

results = [advisory, event]
base_instance = estuary.utils.story.BaseStoryManager()
base_instance.get_total_processing_time(results)

assert caplog.record_tuples == [
('estuary', logging.WARNING, 'While calculating the processing time, a Advisory with'
' ID 4444 was encountered without a build or creation time.')
]

0 comments on commit 411840b

Please sign in to comment.