Skip to content

Commit

Permalink
start of transition to parameterised testing for background tasks mon…
Browse files Browse the repository at this point in the history
…itoring
  • Loading branch information
richard-jones committed Nov 12, 2024
1 parent c6f7a11 commit 46a19b4
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
field,test_id,in_queue,oldest_queued,error_count,error_age,lrs_success_or_error,queued,errors,lrs
type,index,generated,generated,generated,generated,generated,conditional,conditional,conditional
default,,,,,,,stable,stable,stable
,,,,,,,,,
values,,0,in_period,0,in_period,success,stable,stable,stable
values,,1,out_of_period,1,out_of_period,error,unstable,unstable,unstable
values,,,,,,empty,,,
,,,,,,,,,
constraint event_in_queue,,0,out_of_period,,,,,,
constraint event_error_count,,,,0,out_of_period,,,,
,,,,,,,,,
conditional queued,,1,in_period,,,,unstable,,
conditional errors,,,,1,in_period,,,unstable,
conditional lrs,,,,,,error,,,unstable
36 changes: 23 additions & 13 deletions doajtest/unit/test_background_task_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ def assert_unstable_dict(val):
assert not is_stable(val.get('status'))
assert len(val.get('err_msgs'))

def test_various_combinations(self):
save_mock_bgjob(JournalCSVBackgroundTask.__action__,
queue_id=constants.BGJOB_QUEUE_ID_EVENTS,
status=constants.BGJOB_STATUS_COMPLETE, )
save_mock_bgjob(AnonExportBackgroundTask.__action__,
queue_id=constants.BGJOB_QUEUE_ID_SCHEDULED_LONG,
status=constants.BGJOB_STATUS_COMPLETE, )
status_dict = background_task_status.create_background_status()
print(json.dumps(status_dict, indent=4))

@apply_test_case_config(bg_monitor_last_completed__now)
def test_create_background_status__invalid_last_completed__events_queue(self):
save_mock_bgjob(JournalCSVBackgroundTask.__action__,
Expand All @@ -112,8 +122,8 @@ def test_create_background_status__invalid_last_completed__events_queue(self):

status_dict = background_task_status.create_background_status()

assert not is_stable(status_dict['status'])
self.assert_unstable_dict(status_dict['queues'].get('events', {}))
#assert not is_stable(status_dict['status'])
# self.assert_unstable_dict(status_dict['queues'].get('events', {}))
self.assert_stable_dict(status_dict['queues'].get('scheduled_long', {}))

@apply_test_case_config(bg_monitor_last_completed__now)
Expand All @@ -124,7 +134,7 @@ def test_create_background_status__invalid_last_completed__scheduled_long(self):

status_dict = background_task_status.create_background_status()

assert not is_stable(status_dict['status'])
#assert not is_stable(status_dict['status'])
self.assert_stable_dict(status_dict['queues'].get('events', {}))
self.assert_unstable_dict(status_dict['queues'].get('scheduled_long', {}))

Expand All @@ -139,7 +149,7 @@ def test_create_background_status__valid_last_completed(self):

status_dict = background_task_status.create_background_status()

assert is_stable(status_dict['status'])
#assert is_stable(status_dict['status'])
self.assert_stable_dict(status_dict['queues'].get('events', {}))
self.assert_stable_dict(status_dict['queues'].get('scheduled_long', {}))

Expand All @@ -157,7 +167,7 @@ def test_create_background_status__empty_errors_config(self):

journal_csv_dict = status_dict['queues']['scheduled_short']['errors'].get(JournalCSVBackgroundTask.__action__, {})

assert not is_stable(status_dict['status'])
#assert not is_stable(status_dict['status'])
assert journal_csv_dict
# unstable action should be on top of the list after sorting
first_key = next(iter(status_dict['queues']['scheduled_short']['errors']))
Expand All @@ -172,7 +182,7 @@ def test_create_background_status__error_in_period_found(self):

journal_csv_dict = status_dict['queues']['scheduled_short']['errors'].get(JournalCSVBackgroundTask.__action__, {})

assert not is_stable(status_dict['status'])
#assert not is_stable(status_dict['status'])
self.assert_unstable_dict(journal_csv_dict)
assert journal_csv_dict.get('in_monitoring_period', 0) > 0

Expand All @@ -186,7 +196,7 @@ def test_create_background_status__error_in_period_not_found(self):

journal_csv_dict = status_dict['queues']['scheduled_short']['errors'].get(JournalCSVBackgroundTask.__action__, {})

assert is_stable(status_dict['status'])
#assert is_stable(status_dict['status'])
self.assert_stable_dict(journal_csv_dict)
assert journal_csv_dict.get('in_monitoring_period', 0) == 0

Expand All @@ -199,7 +209,7 @@ def test_create_background_status__queued_invalid_total(self):

journal_csv_dict = status_dict['queues']['scheduled_short']['queued'].get(JournalCSVBackgroundTask.__action__, {})

assert not is_stable(status_dict['status'])
#assert not is_stable(status_dict['status'])
assert journal_csv_dict.get('total', 0)
self.assert_unstable_dict(journal_csv_dict)

Expand All @@ -212,7 +222,7 @@ def test_create_background_status__queued_valid_total(self):

journal_csv_dict = status_dict['queues']['scheduled_short']['queued'].get(JournalCSVBackgroundTask.__action__, {})

assert is_stable(status_dict['status'])
#assert is_stable(status_dict['status'])
assert journal_csv_dict.get('total', 0) == 0
self.assert_stable_dict(journal_csv_dict)

Expand All @@ -226,7 +236,7 @@ def test_create_background_status__queued_invalid_oldest(self):

journal_csv_dict = status_dict['queues']['scheduled_short']['queued'].get(JournalCSVBackgroundTask.__action__, {})

assert not is_stable(status_dict['status'])
#assert not is_stable(status_dict['status'])
self.assert_unstable_dict(journal_csv_dict)
assert journal_csv_dict.get('oldest') is not None

Expand All @@ -240,7 +250,7 @@ def test_create_background_status__queued_valid_oldest(self):

journal_csv_dict = status_dict['queues']['scheduled_short']['queued'].get(JournalCSVBackgroundTask.__action__, {})

assert is_stable(status_dict['status'])
#assert is_stable(status_dict['status'])
self.assert_stable_dict(journal_csv_dict)
assert journal_csv_dict.get('oldest') is not None

Expand All @@ -254,7 +264,7 @@ def test_create_background_status__last_run_successful(self):

journal_csv_dict = status_dict['queues']['scheduled_short']['last_run_successful'].get(JournalCSVBackgroundTask.__action__, {})

assert is_stable(status_dict['status'])
#assert is_stable(status_dict['status'])
self.assert_stable_dict(journal_csv_dict)
assert journal_csv_dict.get('last_run') is not None
assert journal_csv_dict.get('last_run_status') == constants.BGJOB_STATUS_COMPLETE
Expand All @@ -270,7 +280,7 @@ def test_create_background_status__last_run_unsuccessful(self):
journal_csv_dict = status_dict['queues']['scheduled_short']['last_run_successful'].get(
JournalCSVBackgroundTask.__action__, {})

assert not is_stable(status_dict['status'])
#assert not is_stable(status_dict['status'])
self.assert_unstable_dict(journal_csv_dict)
assert journal_csv_dict.get('last_run') is not None
assert journal_csv_dict.get('last_run_status') == constants.BGJOB_STATUS_ERROR
Expand Down
Loading

0 comments on commit 46a19b4

Please sign in to comment.