Skip to content

Commit 6590735

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feature/pure_sql
# Conflicts: # test/install_tests.sql
2 parents 898bec2 + bcfbb5f commit 6590735

File tree

13 files changed

+151
-75
lines changed

13 files changed

+151
-75
lines changed

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The framework follows industry standards and best patterns of modern Unit Testin
1111
- [Advanced data comparison](userguide/advanced_data_comparison.md)
1212
- [Running unit tests](userguide/running-unit-tests.md)
1313
- [Querying for test suites](userguide/querying_suites.md)
14-
- [Testing best pracitces](userguide/best-practices.md)
14+
- [Testing best practices](userguide/best-practices.md)
1515
- [Upgrade utPLSQL](userguide/upgrade.md)
1616
- Reporting
1717
- [Using reporters](userguide/reporters.md)

source/core/ut_savepoint_seq.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
create sequence ut_savepoint_seq
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2018 utPLSQL Project
5+
Licensed under the Apache License, Version 2.0 (the "License"):
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
start with 1 cache 20;

source/core/ut_utils.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ create or replace package body ut_utils is
5252

5353
function gen_savepoint_name return varchar2 is
5454
begin
55-
return '"'|| utl_raw.cast_to_varchar2(utl_encode.base64_encode(sys_guid()))||'"';
55+
return 's'||trim(to_char(ut_savepoint_seq.nextval,'0000000000000000000000000000'));
5656
end;
5757

5858
procedure debug_log(a_message varchar2) is

source/core/ut_utils.pks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ create or replace package ut_utils authid definer is
2121
*
2222
*/
2323

24-
gc_version constant varchar2(50) := 'v3.1.4.2619-develop';
24+
gc_version constant varchar2(50) := 'v3.1.4.2653-develop';
2525

2626
subtype t_executable_type is varchar2(30);
2727
gc_before_all constant t_executable_type := 'beforeall';

source/install.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ alter session set current_schema = &&ut3_owner;
5050
@@install_component.sql 'core/types/ut_reporters_info.tps'
5151
@@install_component.sql 'core/ut_utils.pks'
5252
@@install_component.sql 'core/ut_metadata.pks'
53+
@@install_component.sql 'core/ut_savepoint_seq.sql'
5354
@@install_component.sql 'core/ut_utils.pkb'
5455
@@install_component.sql 'core/ut_metadata.pkb'
5556
@@install_component.sql 'reporters/ut_ansiconsole_helper.pks'

source/uninstall_objects.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ drop package ut_ansiconsole_helper;
195195

196196
drop package ut_utils;
197197

198+
drop sequence ut_savepoint_seq;
199+
198200
drop type ut_documentation_reporter force;
199201

200202
drop type ut_teamcity_reporter force;

test/api/test_ut_run.pkb

Lines changed: 89 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -697,19 +697,33 @@ create or replace package body test_ut_run is
697697
execute immediate q'[drop package empty_suite]';
698698
end;
699699

700-
procedure create_test_suite is
700+
procedure create_db_link is
701701
l_service_name varchar2(100);
702702
pragma autonomous_transaction;
703703
begin
704704
select global_name into l_service_name from global_name;
705705
execute immediate
706-
'create public database link db_loopback connect to ut3_tester identified by ut3
707-
using ''(DESCRIPTION=
708-
(ADDRESS=(PROTOCOL=TCP)
709-
(HOST='||sys_context('userenv','SERVER_HOST')||')
706+
'create public database link db_loopback connect to ut3_tester identified by ut3
707+
using ''(DESCRIPTION=
708+
(ADDRESS=(PROTOCOL=TCP)
709+
(HOST='||sys_context('userenv','SERVER_HOST')||')
710710
(PORT=1521)
711711
)
712712
(CONNECT_DATA=(SERVICE_NAME='||l_service_name||')))''';
713+
end;
714+
715+
procedure drop_db_link is
716+
begin
717+
execute immediate 'drop public database link db_loopback';
718+
exception
719+
when others then
720+
null;
721+
end;
722+
723+
procedure create_test_suite is
724+
pragma autonomous_transaction;
725+
begin
726+
create_db_link;
713727
execute immediate q'[
714728
create or replace package stateful_package as
715729
function get_state return varchar2;
@@ -794,9 +808,9 @@ Failures:%
794808
procedure drop_test_suite is
795809
pragma autonomous_transaction;
796810
begin
811+
drop_db_link;
797812
execute immediate 'drop package stateful_package';
798813
execute immediate 'drop package test_stateful';
799-
begin execute immediate 'drop public database link db_loopback'; exception when others then null; end;
800814
end;
801815

802816
procedure run_in_invalid_state is
@@ -919,28 +933,84 @@ Failures:%
919933

920934
procedure create_bad_annot is
921935
pragma autonomous_transaction;
922-
begin
923-
execute immediate q'[
924-
create or replace package bad_annotations as
925-
--%suite
936+
begin
937+
execute immediate q'[
938+
create or replace package bad_annotations as
939+
--%suite
926940

927-
--%context
941+
--%context
928942

929-
--%test(invalidspecs)
930-
procedure test1;
943+
--%test(invalidspecs)
944+
procedure test1;
931945

932-
end;]';
946+
end;]';
933947

934-
execute immediate q'[
935-
create or replace package body bad_annotations as
936-
procedure test1 is begin ut.expect(1).to_equal(1); end;
937-
end;]';
948+
execute immediate q'[
949+
create or replace package body bad_annotations as
950+
procedure test1 is begin ut.expect(1).to_equal(1); end;
951+
end;]';
952+
953+
end;
938954

939-
end;
940955
procedure drop_bad_annot is
941956
pragma autonomous_transaction;
942957
begin
943958
execute immediate 'drop package bad_annotations';
944959
end;
960+
961+
procedure savepoints_on_db_links is
962+
l_results clob;
963+
begin
964+
ut3.ut.run('test_distributed_savepoint');
965+
l_results := core.get_dbms_output_as_clob();
966+
ut.expect(l_results).to_be_like('%1 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%');
967+
end;
968+
969+
procedure create_suite_with_link is
970+
pragma autonomous_transaction;
971+
begin
972+
create_db_link;
973+
execute immediate 'create table tst(id number(18,0))';
974+
execute immediate q'[
975+
create or replace package test_distributed_savepoint is
976+
--%suite
977+
--%suitepath(alltests)
978+
979+
--%beforeall
980+
procedure setup;
981+
982+
--%test
983+
procedure test;
984+
end;]';
985+
986+
execute immediate q'[
987+
create or replace package body test_distributed_savepoint is
988+
989+
g_expected constant integer := 1;
990+
991+
procedure setup is
992+
begin
993+
insert into tst@db_loopback values(g_expected);
994+
end;
995+
996+
procedure test is
997+
l_actual integer := 0;
998+
begin
999+
select id into l_actual from tst@db_loopback;
1000+
1001+
ut.expect(l_actual).to_equal(g_expected);
1002+
end;
1003+
1004+
end;]';
1005+
end;
1006+
1007+
procedure drop_suite_with_link is
1008+
pragma autonomous_transaction;
1009+
begin
1010+
drop_db_link;
1011+
execute immediate 'drop table tst';
1012+
execute immediate 'drop package test_distributed_savepoint';
1013+
end;
1014+
9451015
end;
9461016
/

test/api/test_ut_run.pks

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ create or replace package test_ut_run is
5656
--%aftertest(drop_failing_beforeall_suite)
5757
procedure run_proc_fail_child_suites;
5858

59+
--%test(Savepoints are working properly on distributed transactions - Issue #839)
60+
--%beforetest(create_suite_with_link)
61+
--%aftertest(drop_suite_with_link)
62+
procedure savepoints_on_db_links;
63+
procedure create_suite_with_link;
64+
procedure drop_suite_with_link;
65+
5966
--%endcontext
6067

6168
--%context(run_proc_transaction_control)

test/core/min_grant_user/test_min_grant_user.pkb

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,5 @@
11
create or replace package body test_min_grant_user is
22

3-
procedure create_ut3$user#_tests is
4-
pragma autonomous_transaction;
5-
begin
6-
execute immediate q'[
7-
create or replace package ut3$user#.test_cursor_grants is
8-
--%suite()
9-
10-
procedure run;
11-
12-
--%test(execute join by test)
13-
procedure test_join_by_cursor;
14-
end;
15-
]';
16-
execute immediate q'[
17-
create or replace package body ut3$user#.test_cursor_grants is
18-
procedure run is
19-
begin
20-
ut3.ut.run('test_cursor_grants');
21-
end;
22-
procedure test_join_by_cursor is
23-
l_actual SYS_REFCURSOR;
24-
l_expected SYS_REFCURSOR;
25-
begin
26-
--Arrange
27-
open l_actual for select owner, object_name,object_type from all_objects where owner = user
28-
order by 1,2,3 asc;
29-
open l_expected for select owner, object_name,object_type from all_objects where owner = user
30-
order by 1,2,3 desc;
31-
32-
--Act
33-
ut3.ut.expect(l_actual).to_equal(l_expected).join_by('OWNER');
34-
35-
end;
36-
37-
38-
end;
39-
]';
40-
end;
41-
42-
procedure drop_ut3$user#_tests is
43-
pragma autonomous_transaction;
44-
begin
45-
execute immediate q'[drop package ut3$user#.test_cursor_grants]';
46-
end;
47-
48-
49-
503
procedure test_join_by_cursor is
514
l_results clob;
525
begin

test/core/min_grant_user/test_min_grant_user.pks

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ create or replace package test_min_grant_user is
33
--%suite(minimum grant user tests)
44
--%suitepath(utplsql.core)
55

6-
--%beforeall
7-
procedure create_ut3$user#_tests;
8-
9-
--%afterall
10-
procedure drop_ut3$user#_tests;
11-
126
--%test(execute join by test)
137
procedure test_join_by_cursor;
148

0 commit comments

Comments
 (0)