Skip to content

Commit 6bf2c8e

Browse files
committed
Added ability to control rollback bekavior of a test-run.
1 parent d887889 commit 6bf2c8e

12 files changed

Lines changed: 231 additions & 54 deletions

source/api/ut.pkb

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ create or replace package body ut is
1818
*/
1919

2020
g_nls_date_format varchar2(4000);
21+
gc_fail_on_errors constant boolean := false;
2122

2223
function version return varchar2 is
2324
begin
@@ -117,7 +118,6 @@ create or replace package body ut is
117118
a_client_character_set varchar2 := null
118119
) is
119120
pragma autonomous_transaction;
120-
c_fail_on_errors constant boolean := false;
121121
begin
122122
a_reporter := coalesce(a_reporter,ut_documentation_reporter());
123123
ut_runner.run(
@@ -129,7 +129,7 @@ create or replace package body ut is
129129
a_test_file_mappings,
130130
a_include_objects,
131131
a_exclude_objects,
132-
c_fail_on_errors,
132+
gc_fail_on_errors,
133133
a_client_character_set
134134
);
135135
rollback;
@@ -147,7 +147,6 @@ create or replace package body ut is
147147
a_client_character_set varchar2 := null
148148
) is
149149
pragma autonomous_transaction;
150-
c_fail_on_errors constant boolean := false;
151150
begin
152151
a_reporter := coalesce(a_reporter,ut_documentation_reporter());
153152
ut_runner.run(
@@ -159,7 +158,7 @@ create or replace package body ut is
159158
ut_file_mapper.build_file_mappings(a_test_files),
160159
a_include_objects,
161160
a_exclude_objects,
162-
c_fail_on_errors,
161+
gc_fail_on_errors,
163162
a_client_character_set
164163
);
165164
rollback;
@@ -406,21 +405,39 @@ create or replace package body ut is
406405
a_test_file_mappings ut_file_mappings := null,
407406
a_include_objects ut_varchar2_list := null,
408407
a_exclude_objects ut_varchar2_list := null,
409-
a_client_character_set varchar2 := null
408+
a_client_character_set varchar2 := null,
409+
a_force_manual_rollback boolean := false
410410
) is
411411
l_reporter ut_reporter_base := a_reporter;
412412
begin
413-
run_autonomous(
414-
a_paths,
415-
l_reporter,
416-
ut_utils.boolean_to_int(a_color_console),
417-
a_coverage_schemes,
418-
a_source_file_mappings,
419-
a_test_file_mappings,
420-
a_include_objects,
421-
a_exclude_objects,
422-
a_client_character_set
423-
);
413+
if a_force_manual_rollback then
414+
l_reporter := coalesce(l_reporter,ut_documentation_reporter());
415+
ut_runner.run(
416+
a_paths,
417+
ut_reporters(l_reporter),
418+
a_color_console,
419+
a_coverage_schemes,
420+
a_source_file_mappings,
421+
a_test_file_mappings,
422+
a_include_objects,
423+
a_exclude_objects,
424+
gc_fail_on_errors,
425+
a_client_character_set,
426+
a_force_manual_rollback
427+
);
428+
else
429+
run_autonomous(
430+
a_paths,
431+
l_reporter,
432+
ut_utils.boolean_to_int(a_color_console),
433+
a_coverage_schemes,
434+
a_source_file_mappings,
435+
a_test_file_mappings,
436+
a_include_objects,
437+
a_exclude_objects,
438+
a_client_character_set
439+
);
440+
end if;
424441
if l_reporter is of (ut_output_reporter_base) then
425442
treat(l_reporter as ut_output_reporter_base).lines_to_dbms_output();
426443
end if;
@@ -436,25 +453,23 @@ create or replace package body ut is
436453
a_test_files ut_varchar2_list,
437454
a_include_objects ut_varchar2_list := null,
438455
a_exclude_objects ut_varchar2_list := null,
439-
a_client_character_set varchar2 := null
456+
a_client_character_set varchar2 := null,
457+
a_force_manual_rollback boolean := false
440458
) is
441459
l_reporter ut_reporter_base := a_reporter;
442460
begin
443-
run_autonomous(
461+
ut.run(
444462
a_paths,
445463
l_reporter,
446-
ut_utils.boolean_to_int(a_color_console),
464+
a_color_console,
447465
a_coverage_schemes,
448-
a_source_files,
449-
a_test_files,
466+
ut_file_mapper.build_file_mappings(a_source_files),
467+
ut_file_mapper.build_file_mappings(a_test_files),
450468
a_include_objects,
451469
a_exclude_objects,
452-
a_client_character_set
470+
a_client_character_set,
471+
a_force_manual_rollback
453472
);
454-
if l_reporter is of (ut_output_reporter_base) then
455-
treat(l_reporter as ut_output_reporter_base).lines_to_dbms_output();
456-
end if;
457-
raise_if_packages_invalidated();
458473
end;
459474

460475
procedure run(
@@ -465,7 +480,8 @@ create or replace package body ut is
465480
a_test_file_mappings ut_file_mappings := null,
466481
a_include_objects ut_varchar2_list := null,
467482
a_exclude_objects ut_varchar2_list := null,
468-
a_client_character_set varchar2 := null
483+
a_client_character_set varchar2 := null,
484+
a_force_manual_rollback boolean := false
469485
) is
470486
begin
471487
ut.run(
@@ -477,7 +493,8 @@ create or replace package body ut is
477493
a_test_file_mappings,
478494
a_include_objects,
479495
a_exclude_objects,
480-
a_client_character_set
496+
a_client_character_set,
497+
a_force_manual_rollback
481498
);
482499
end;
483500

@@ -489,7 +506,8 @@ create or replace package body ut is
489506
a_test_files ut_varchar2_list,
490507
a_include_objects ut_varchar2_list := null,
491508
a_exclude_objects ut_varchar2_list := null,
492-
a_client_character_set varchar2 := null
509+
a_client_character_set varchar2 := null,
510+
a_force_manual_rollback boolean := false
493511
) is
494512
begin
495513
ut.run(
@@ -501,7 +519,8 @@ create or replace package body ut is
501519
a_test_files,
502520
a_include_objects,
503521
a_exclude_objects,
504-
a_client_character_set
522+
a_client_character_set,
523+
a_force_manual_rollback
505524
);
506525
end;
507526

@@ -514,7 +533,8 @@ create or replace package body ut is
514533
a_test_file_mappings ut_file_mappings := null,
515534
a_include_objects ut_varchar2_list := null,
516535
a_exclude_objects ut_varchar2_list := null,
517-
a_client_character_set varchar2 := null
536+
a_client_character_set varchar2 := null,
537+
a_force_manual_rollback boolean := false
518538
) is
519539
begin
520540
ut.run(
@@ -526,7 +546,8 @@ create or replace package body ut is
526546
a_test_file_mappings,
527547
a_include_objects,
528548
a_exclude_objects,
529-
a_client_character_set
549+
a_client_character_set,
550+
a_force_manual_rollback
530551
);
531552
end;
532553

@@ -539,7 +560,8 @@ create or replace package body ut is
539560
a_test_files ut_varchar2_list,
540561
a_include_objects ut_varchar2_list := null,
541562
a_exclude_objects ut_varchar2_list := null,
542-
a_client_character_set varchar2 := null
563+
a_client_character_set varchar2 := null,
564+
a_force_manual_rollback boolean := false
543565
) is
544566
begin
545567
ut.run(
@@ -551,7 +573,8 @@ create or replace package body ut is
551573
a_test_files,
552574
a_include_objects,
553575
a_exclude_objects,
554-
a_client_character_set
576+
a_client_character_set,
577+
a_force_manual_rollback
555578
);
556579
end;
557580

source/api/ut.pks

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ create or replace package ut authid current_user as
125125
a_test_file_mappings ut_file_mappings := null,
126126
a_include_objects ut_varchar2_list := null,
127127
a_exclude_objects ut_varchar2_list := null,
128-
a_client_character_set varchar2 := null
128+
a_client_character_set varchar2 := null,
129+
a_force_manual_rollback boolean := false
129130
);
130131

131132
procedure run(
@@ -136,7 +137,8 @@ create or replace package ut authid current_user as
136137
a_test_files ut_varchar2_list,
137138
a_include_objects ut_varchar2_list := null,
138139
a_exclude_objects ut_varchar2_list := null,
139-
a_client_character_set varchar2 := null
140+
a_client_character_set varchar2 := null,
141+
a_force_manual_rollback boolean := false
140142
);
141143

142144
procedure run(
@@ -148,7 +150,8 @@ create or replace package ut authid current_user as
148150
a_test_file_mappings ut_file_mappings := null,
149151
a_include_objects ut_varchar2_list := null,
150152
a_exclude_objects ut_varchar2_list := null,
151-
a_client_character_set varchar2 := null
153+
a_client_character_set varchar2 := null,
154+
a_force_manual_rollback boolean := false
152155
);
153156

154157
procedure run(
@@ -160,7 +163,8 @@ create or replace package ut authid current_user as
160163
a_test_files ut_varchar2_list,
161164
a_include_objects ut_varchar2_list := null,
162165
a_exclude_objects ut_varchar2_list := null,
163-
a_client_character_set varchar2 := null
166+
a_client_character_set varchar2 := null,
167+
a_force_manual_rollback boolean := false
164168
);
165169

166170
procedure run(
@@ -172,7 +176,8 @@ create or replace package ut authid current_user as
172176
a_test_file_mappings ut_file_mappings := null,
173177
a_include_objects ut_varchar2_list := null,
174178
a_exclude_objects ut_varchar2_list := null,
175-
a_client_character_set varchar2 := null
179+
a_client_character_set varchar2 := null,
180+
a_force_manual_rollback boolean := false
176181
);
177182

178183
procedure run(
@@ -184,7 +189,8 @@ create or replace package ut authid current_user as
184189
a_test_files ut_varchar2_list,
185190
a_include_objects ut_varchar2_list := null,
186191
a_exclude_objects ut_varchar2_list := null,
187-
a_client_character_set varchar2 := null
192+
a_client_character_set varchar2 := null,
193+
a_force_manual_rollback boolean := false
188194
);
189195

190196
/**

source/api/ut_runner.pkb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ create or replace package body ut_runner is
4242
return l_result;
4343
end;
4444

45-
procedure finish_run(a_run ut_run) is
45+
procedure finish_run(a_run ut_run, a_force_manual_rollback boolean) is
4646
begin
4747
ut_utils.cleanup_temp_tables;
4848
ut_event_manager.trigger_event(ut_utils.gc_finalize, a_run);
4949
ut_metadata.reset_source_definition_cache;
5050
ut_utils.read_cache_to_dbms_output();
5151
ut_coverage_helper.cleanup_tmp_table();
52+
if not a_force_manual_rollback then
53+
rollback;
54+
end if;
5255
end;
5356

5457

@@ -83,7 +86,8 @@ create or replace package body ut_runner is
8386
a_include_objects ut_varchar2_list := null,
8487
a_exclude_objects ut_varchar2_list := null,
8588
a_fail_on_errors boolean := false,
86-
a_client_character_set varchar2 := null
89+
a_client_character_set varchar2 := null,
90+
a_force_manual_rollback boolean := false
8791
) is
8892
l_run ut_run;
8993
l_coverage_schema_names ut_varchar2_rows;
@@ -137,16 +141,18 @@ create or replace package body ut_runner is
137141
set(a_test_file_mappings),
138142
a_client_character_set
139143
);
144+
if a_force_manual_rollback then
145+
l_run.set_rollback_type(ut_utils.gc_rollback_manual, a_force=>true);
146+
end if;
147+
140148
l_run.do_execute();
141149

142-
finish_run(l_run);
143-
rollback;
150+
finish_run(l_run, a_force_manual_rollback);
144151
exception
145152
when others then
146-
finish_run(l_run);
153+
finish_run(l_run, a_force_manual_rollback);
147154
dbms_output.put_line(dbms_utility.format_error_backtrace);
148155
dbms_output.put_line(dbms_utility.format_error_stack);
149-
rollback;
150156
raise;
151157
end;
152158
if a_fail_on_errors and l_run.result in (ut_utils.gc_failure, ut_utils.gc_error) then

source/api/ut_runner.pks

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ create or replace package ut_runner authid current_user is
4343
* @param a_include_objects list of database objects (in format 'owner.name') that coverage should be reported on
4444
* @param a_exclude_objects list of database objects (in format 'owner.name') that coverage should be skipped for
4545
* @param a_fail_on_errors true/false - should an exception be thrown when tests are completed with failures/errors
46+
* @param a_force_manual_rollback true/false - should the transaction control be forced to --%rollback(manual) and no rollback issued at the end of the run
4647
*
4748
* @example
4849
* Parameter `a_paths` accepts values of the following formats:
@@ -65,7 +66,8 @@ create or replace package ut_runner authid current_user is
6566
a_include_objects ut_varchar2_list := null,
6667
a_exclude_objects ut_varchar2_list := null,
6768
a_fail_on_errors boolean := false,
68-
a_client_character_set varchar2 := null
69+
a_client_character_set varchar2 := null,
70+
a_force_manual_rollback boolean := false
6971
);
7072

7173
/**

source/core/types/ut_logical_suite.tpb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ create or replace type body ut_logical_suite as
5151
self.calc_execution_result();
5252
end;
5353

54-
overriding member procedure set_rollback_type(self in out nocopy ut_logical_suite, a_rollback_type integer) is
54+
overriding member procedure set_rollback_type(self in out nocopy ut_logical_suite, a_rollback_type integer, a_force boolean := false) is
5555
begin
56-
self.rollback_type := coalesce(self.rollback_type, a_rollback_type);
56+
self.rollback_type := case when a_force then a_rollback_type else coalesce(self.rollback_type, a_rollback_type) end;
5757
for i in 1 .. self.items.count loop
58-
self.items(i).set_rollback_type(self.rollback_type);
58+
self.items(i).set_rollback_type(self.rollback_type, a_force);
5959
end loop;
6060
end;
6161

source/core/types/ut_logical_suite.tps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ create or replace type ut_logical_suite under ut_suite_item (
2727
member function is_valid(self in out nocopy ut_logical_suite) return boolean,
2828
member procedure add_item(self in out nocopy ut_logical_suite, a_item ut_suite_item),
2929
overriding member procedure mark_as_skipped(self in out nocopy ut_logical_suite),
30-
overriding member procedure set_rollback_type(self in out nocopy ut_logical_suite, a_rollback_type integer),
30+
overriding member procedure set_rollback_type(self in out nocopy ut_logical_suite, a_rollback_type integer, a_force boolean := false),
3131
overriding member function do_execute(self in out nocopy ut_logical_suite) return boolean,
3232
overriding member procedure calc_execution_result(self in out nocopy ut_logical_suite),
3333
overriding member procedure mark_as_errored(self in out nocopy ut_logical_suite, a_error_stack_trace varchar2),

source/core/types/ut_run.tpb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ create or replace type body ut_run as
7575
return l_completed_without_errors;
7676
end;
7777

78+
overriding member procedure set_rollback_type(self in out nocopy ut_run, a_rollback_type integer, a_force boolean := false) is
79+
begin
80+
self.rollback_type := case when a_force then a_rollback_type else coalesce(self.rollback_type, a_rollback_type) end;
81+
for i in 1 .. self.items.count loop
82+
self.items(i).set_rollback_type(self.rollback_type, a_force);
83+
end loop;
84+
end;
85+
7886
overriding member procedure calc_execution_result(self in out nocopy ut_run) is
7987
l_result integer(1);
8088
begin

source/core/types/ut_run.tps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ create or replace type ut_run under ut_suite_item (
3737
) return self as result,
3838
overriding member procedure mark_as_skipped(self in out nocopy ut_run),
3939
overriding member function do_execute(self in out nocopy ut_run) return boolean,
40+
overriding member procedure set_rollback_type(self in out nocopy ut_run, a_rollback_type integer, a_force boolean := false),
4041
overriding member procedure calc_execution_result(self in out nocopy ut_run),
4142
overriding member procedure mark_as_errored(self in out nocopy ut_run, a_error_stack_trace varchar2),
4243
overriding member function get_error_stack_traces return ut_varchar2_list,

source/core/types/ut_suite_item.tpb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ create or replace type body ut_suite_item as
3737
return ut_utils.int_to_boolean(self.disabled_flag);
3838
end;
3939

40-
member procedure set_rollback_type(self in out nocopy ut_suite_item, a_rollback_type integer) is
40+
member procedure set_rollback_type(self in out nocopy ut_suite_item, a_rollback_type integer, a_force boolean := false) is
4141
begin
42-
self.rollback_type := coalesce(self.rollback_type, a_rollback_type);
42+
self.rollback_type := case when a_force then a_rollback_type else coalesce(self.rollback_type, a_rollback_type) end;
4343
end;
4444

4545
member function get_rollback_type return integer is

0 commit comments

Comments
 (0)