File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 77### Added
88
99- Catch ` InterruptExecution ` during rollbacks so that the experiment terminates
10- gracefully [ #132 ] [ 132 ]
10+ gracefully [ #132 ] [ 132 ] . The remaining rollbacks are not applied.
11+ - Catch ` SIGINT ` and ` SystemExit ` during rollbacks so that the experiment
12+ terminates gracefully [ #133 ] [ 133 ] . The remaining rollbacks are not applied.
1113
1214[ 132 ] : https://github.com/chaostoolkit/chaostoolkit-lib/issues/132
15+ [ 133 ] : https://github.com/chaostoolkit/chaostoolkit-lib/issues/133
1316
1417## [ 1.7.0] [ ] - 2019-09-21
1518
Original file line number Diff line number Diff line change @@ -254,6 +254,11 @@ def run_experiment(experiment: Experiment,
254254 except InterruptExecution as i :
255255 journal ["status" ] = "interrupted"
256256 logger .fatal (str (i ))
257+ except (KeyboardInterrupt , SystemExit ):
258+ journal ["status" ] = "interrupted"
259+ logger .warn (
260+ "Received an exit signal."
261+ "Terminating now without running the remaining rollbacks." )
257262
258263 journal ["end" ] = datetime .utcnow ().isoformat ()
259264 journal ["duration" ] = time .time () - started_at
Original file line number Diff line number Diff line change @@ -187,6 +187,36 @@ def handler(signum, frame):
187187 pytest .fail ("we should have swalled the InterruptExecution exception" )
188188
189189
190+ def test_can_interrupt_rollbacks_on_SystemExit ():
191+ def handler (signum , frame ):
192+ raise SystemExit ()
193+
194+ signal .signal (signal .SIGALRM , handler )
195+ signal .alarm (1 )
196+
197+ try :
198+ journal = run_experiment (experiments .ExperimentWithRollbackLongPause )
199+ assert isinstance (journal , dict )
200+ assert journal ["status" ] == "interrupted"
201+ except SystemExit :
202+ pytest .fail ("we should have swalled the SystemExit exception" )
203+
204+
205+ def test_can_interrupt_rollbacks_on_SIGINT ():
206+ def handler (signum , frame ):
207+ raise KeyboardInterrupt ()
208+
209+ signal .signal (signal .SIGALRM , handler )
210+ signal .alarm (1 )
211+
212+ try :
213+ journal = run_experiment (experiments .ExperimentWithRollbackLongPause )
214+ assert isinstance (journal , dict )
215+ assert journal ["status" ] == "interrupted"
216+ except SystemExit :
217+ pytest .fail ("we should have swalled the KeyboardInterrupt exception" )
218+
219+
190220def test_probes_can_reference_each_other ():
191221 experiment = experiments .RefProbeExperiment .copy ()
192222 experiment ["dry" ] = True
You can’t perform that action at this time.
0 commit comments