@@ -114,6 +114,28 @@ def tearDown(self):
114114 self .session .query (ErrorType ).delete ()
115115 self .session .commit ()
116116
117+ def process_run_setup (self , process_name , status , num_runs ):
118+ """
119+ Helper function to setup mutliple process tracking runs for a given process and set to a given status. Used to
120+ test the on_hold status logic.
121+ :param process_name: Name of the process that runs will be created of.
122+ :param status: Status the runs should be changed to
123+ :param num_runs: Number of runs that should be created
124+ :return:
125+ """
126+ i = 1
127+ while i <= num_runs :
128+ process_run = ProcessTracker (
129+ process_name = process_name ,
130+ process_type = "Extract" ,
131+ actor_name = "UnitTesting" ,
132+ tool_name = "Spark" ,
133+ )
134+
135+ process_run .change_run_status (new_status = status )
136+ i += 1
137+ time .sleep (2 )
138+
117139 def test_bulk_change_extract_status (self ):
118140 """
119141 Testing that bulk change occurs when extracts provided.
@@ -644,6 +666,90 @@ def test_initializing_process_tracking(self):
644666
645667 self .assertEqual (expected_result , given_result )
646668
669+ @unittest .skip ("Issue with hanging queries on database." )
670+ def test_process_on_hold_max_failures (self ):
671+ """
672+ Testing that when number of failed processes matches the maximum_sequential_failures (default 5), process run
673+ goes on_hold.
674+ :return:
675+ """
676+
677+ self .process_run_setup (
678+ process_name = "On Hold Max Failures Test" , status = "failed" , num_runs = 5
679+ )
680+
681+ with self .assertRaises (Exception ) as context :
682+ ProcessTracker (
683+ process_name = "On Hold Max Failures Test" ,
684+ process_type = "Extract" ,
685+ actor_name = "UnitTesting" ,
686+ tool_name = "Spark" ,
687+ )
688+
689+ self .assertTrue (
690+ "The process On Hold Max Failures Test is currently running or on_hold."
691+ in str (context .exception )
692+ )
693+
694+ @unittest .skip ("Issue with hanging queries on database." )
695+ def test_process_on_hold_under_max_failures (self ):
696+ """
697+ Testing that when number of failed processes is less than the maximum_sequential_failures (default 5), process run
698+ continues.
699+ :return:
700+ """
701+ process_name = "On Hold Under Max Failures Test"
702+ self .process_run_setup (process_name = process_name , status = "failed" , num_runs = 3 )
703+
704+ process_run = ProcessTracker (
705+ process_name = process_name ,
706+ process_type = "Extract" ,
707+ actor_name = "UnitTesting" ,
708+ tool_name = "Spark" ,
709+ )
710+
711+ current_run_status = (
712+ self .session .query (ProcessTracking )
713+ .join (Process )
714+ .filter (Process .process_name == process_name )
715+ .filter (ProcessTracking .is_latest_run == True )
716+ )
717+ given_result = current_run_status [0 ].process_status_id
718+
719+ expected_result = process_run .process_status_running
720+
721+ self .assertEqual (expected_result , given_result )
722+
723+ def test_process_on_hold_previous_run_on_hold (self ):
724+ """
725+ If the previous run does not get moved from on_hold status, then the next run will not kick off and the process
726+ will remain on_hold.
727+ :return:
728+ """
729+ process_name = "On Hold Previous Run Test"
730+
731+ process_run = ProcessTracker (
732+ process_name = process_name ,
733+ process_type = "Extract" ,
734+ actor_name = "UnitTesting" ,
735+ tool_name = "Spark" ,
736+ )
737+
738+ process_run .change_run_status (new_status = "on hold" )
739+
740+ with self .assertRaises (Exception ) as context :
741+ ProcessTracker (
742+ process_name = process_name ,
743+ process_type = "Extract" ,
744+ actor_name = "UnitTesting" ,
745+ tool_name = "Spark" ,
746+ )
747+
748+ self .assertTrue (
749+ "The process On Hold Previous Run Test is currently running or on hold."
750+ in str (context .exception )
751+ )
752+
647753 def test_register_extracts_by_location_local_file_count (self ):
648754 """
649755 Testing that when the location is local, all the extracts are counted and registered in the location's file count.
@@ -865,8 +971,8 @@ def test_register_new_process_run_exception(self):
865971 self .process_tracker .register_new_process_run ()
866972
867973 return self .assertTrue (
868- "The process Testing Process Tracking Initialization "
869- "is currently running." in str (context .exception )
974+ "The process Testing Process Tracking Initialization is currently running or on hold. "
975+ in str (context .exception )
870976 )
871977
872978 def test_register_new_process_run_with_previous_run (self ):
0 commit comments