Skip to content

Commit

Permalink
Merge fbc24b9 into ad54806
Browse files Browse the repository at this point in the history
  • Loading branch information
jgebal committed Feb 21, 2019
2 parents ad54806 + fbc24b9 commit 740687a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
10 changes: 8 additions & 2 deletions source/core/types/ut_suite_item.tpb
Expand Up @@ -61,18 +61,24 @@ create or replace type body ut_suite_item as

member procedure rollback_to_savepoint(self in out nocopy ut_suite_item, a_savepoint varchar2) is
ex_savepoint_not_exists exception;
l_transaction_invalidators clob;
pragma exception_init(ex_savepoint_not_exists, -1086);
begin
if get_rollback_type() = ut_utils.gc_rollback_auto and a_savepoint is not null then
execute immediate 'rollback to ' || a_savepoint;
end if;
exception
when ex_savepoint_not_exists then
l_transaction_invalidators :=
lower( ut_utils.indent_lines( ut_utils.table_to_clob( self.get_transaction_invalidators() ), 2, true ) );
if length(l_transaction_invalidators) > 3000 then
l_transaction_invalidators := substr(l_transaction_invalidators,1,3000)||'...';
end if;
put_warning(
'Unable to perform automatic rollback after test'
|| case when self_type like '%SUITE' then ' suite' end || '. '
|| case when self_type like '%SUITE' then ' suite' when self_type like '%CONTEXT' then ' context' end || '. '
||'An implicit or explicit commit/rollback occurred in procedures:'||chr(10)
||lower(ut_utils.indent_lines(ut_utils.table_to_clob(self.get_transaction_invalidators()), 2, true))||chr(10)
||l_transaction_invalidators||chr(10)
||'Use the "--%rollback(manual)" annotation or remove commit/rollback/ddl statements that are causing the issue.'
);
end;
Expand Down
15 changes: 15 additions & 0 deletions test/core/test_ut_suite.pkb
Expand Up @@ -140,5 +140,20 @@ create or replace package body test_ut_suite is
begin
test_rollback_type('test_failure', ut3.ut_utils.gc_rollback_manual, be_greater_than(0) );
end;

procedure trim_transaction_invalidators is
l_suite ut3.ut_suite;
begin
--arrange
l_suite := ut3.ut_suite(a_object_owner => USER, a_object_name => 'UT_EXAMPLE_TESTS', a_line_no=> 1);
for i in 1 .. 100 loop
l_suite.add_transaction_invalidator('schema_name.package_name.procedure_name'||i);
end loop;
--Act
l_suite.rollback_to_savepoint('dummy_savepoint');
--Assert
ut.expect(l_suite.warnings.count).to_equal(1);
end;

end;
/
3 changes: 3 additions & 0 deletions test/core/test_ut_suite.pks
Expand Up @@ -33,5 +33,8 @@ create or replace package test_ut_suite is
--%test(rollback(manual) - disables automatic rollback after a suite even if test fails)
procedure rollback_manual_on_failure;

--%test(Transaction invalidators list is trimmed in warnings when too long)
procedure trim_transaction_invalidators;

end;
/

0 comments on commit 740687a

Please sign in to comment.