testcases/FS/transact.pm

filter: Statementstmt 17.5% 16 / 91 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 2 totaltotal 17.6% 21 / 119 SCAR 33.3
CC
6
Cov
15%
test_isolation
20.0
test_transact
12.0
BEGIN
1.0
CRAP 27.8
« testcases/FS/placeholders.pm ↑ Summary testcases/FS/basic.pm »
1 package XAO::testcases::FS::transact;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use XAO::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use XAO::Objects;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Error qw(:try);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use base qw(XAO::testcases::FS::base);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub test_transact {
10 0 ▶ my $self=shift;
Subroutine test_transact: not called CC=3 SCAR=24.8
Pod undocumented
11  
12 0 my $odb=$self->{odb};
13 0 ▶ $self->assert(defined($odb) && ref($odb),
Condition0%0/3
defined $odb && ref $odb
!ll&&!rl&&r
000
MC/DC0%0/2
defined $odb && ref $odb
defined $odb ref $odb
Truth table0%0/3
A && B
A= defined $odbB= ref $odb
ABresult
0X0
100
111
14 'Object database creating failure');
15  
16 ##
17 # Testing just normal stuff, this should work even where there is no
18 # support of transactions.
19 #
20 0 my $customer=$odb->fetch('/Customers/c1');
21 0 $self->assert(! $odb->transact_active,
22 "1 - Transaction is active before transact_begin()");
23 0 $odb->transact_begin;
24 0 $self->assert($odb->transact_active,
25 "1 - Transaction is not active after transact_begin()");
26 0 my $text='test' . time;
27 0 $customer->put(name => $text);
28 0 $customer=$odb->fetch('/Customers')->get('c1');
29 0 my $got=$customer->get('name');
30 0 $self->assert($got eq $text,
31 "1a - Got wrong value '$got', expected '$text'");
32 0 $odb->transact_commit;
33 0 $self->assert(! $odb->transact_active,
34 "1 - Transaction is still active after transact_commit()");
35 0 $customer=$odb->fetch('/Customers')->get('c1');
36 0 $got=$customer->get('name');
37 0 $self->assert($got eq $text,
38 "1b - Got wrong value '$got', expected '$text'");
39  
40 ##
41 # Testing roll back. Will only work if there is real support for
42 # transactions. We still go through the ordeal and then check if
43 # driver correctly reports its transactions support status.
44 #
45 0 my $pname=$odb->fetch('/')->get('project');
46 0 $odb->transact_begin;
47 0 my $newtext=$text."NEW";
48 0 $customer->put(name => $newtext);
49 0 $got=$odb->fetch('/Customers/c1/name');
50 0 $self->assert($got eq $newtext,
51 "2a - Got wrong value '$got', expected '$newtext'");
52 0 $odb->fetch('/')->put(project => 'foobar');
53 0 $odb->transact_rollback;
54 0 $got=$odb->fetch('/Customers/c1/name');
55 0 ▶ if($odb->transact_can) {
Branch: 1 branch
BranchTrueFalseTotal
if ($odb->transact_can) { } 0 0 0
56 0 $self->assert($got eq $text,
57 "2b - Got wrong value '$got', expected '$text'");
58 0 $self->assert($odb->fetch('/project') eq $pname,
59 "2c - Got wrong value for /project, expected '$pname'");
60 }
61 else {
62 0 $self->assert($got eq $newtext,
63 "2d - Got a value that would be expected from\n" .
64 "a driver that supports transaction ($got),\n" .
65 "expected '$newtext'");
66 0 return;
67 }
68 }
69  
70 sub test_isolation {
71 0 ▶ my $self=shift;
Subroutine test_isolation: not called CC=4 SCAR=30.0
Pod undocumented
72  
73 0 my $odb1=$self->{odb};
74 0 ▶ $self->assert(defined($odb1) && ref($odb1),
Condition0%0/3
defined $odb1 && ref $odb1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $odb1 && ref $odb1
defined $odb1 ref $odb1
Truth table0%0/3
A && B
A= defined $odb1B= ref $odb1
ABresult
0X0
100
111
75 '1 - Object database creating failure');
76  
77 0 ▶ if(! $odb1->transact_can) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($odb1->transact_can) 0 0 0
78 0 print STDERR "Driver does not support transactions\n";
79 0 return;
80 }
81  
82 0 my $oa=$self->{odb_args};
83 my $odb2=XAO::Objects->new(objname => 'FS::Glue',
84 dsn => $oa->{dsn},
85 user => $oa->{user},
86 0 password => $oa->{password});
87 0 ▶ $self->assert(defined($odb2) && ref($odb2),
Condition0%0/3
defined $odb2 && ref $odb2
!ll&&!rl&&r
000
MC/DC0%0/2
defined $odb2 && ref $odb2
defined $odb2 ref $odb2
Truth table0%0/3
A && B
A= defined $odb2B= ref $odb2
ABresult
0X0
100
111
88 '2 - Object database creating failure');
89  
90 0 my $o1c1=$odb1->fetch('/Customers/c1');
91 0 my $o1c2=$odb1->fetch('/Customers/c2');
92 0 my $o2c1=$odb2->fetch('/Customers/c1');
93 0 my $o2c2=$odb2->fetch('/Customers/c2');
94  
95 0 $o1c2->put(name => 'c2_init');
96 0 $o1c1->put(name => 'o1c1_before');
97 0 $odb1->transact_begin;
98 0 $o1c1->put(name => 'o1c1_after');
99  
100 0 my $got=$o1c1->get('name');
101 0 $self->assert($got eq 'o1c1_after',
102 "3 - isolation failure - got '$got', expected 'o1c1_after'");
103 0 $got=$o2c1->get('name');
104 0 $self->assert($got eq 'o1c1_before',
105 "4 - isolation failure - got '$got', expected 'o1c1_before'");
106  
107 # Once we begin a transaction values are frozen and o1c2 should read
108 # c2_init even after it was changed outside of odb2 transaction.
109 #
110 0 $o2c2->put(name => 'o2c2_before');
111 0 $got=$o2c2->get('name');
112 0 $self->assert($got eq 'o2c2_before',
113 "5 - isolation failure - got '$got', expected 'o2c2_before'");
114 0 $got=$o1c2->get('name');
115 0 $self->assert($got eq 'c2_init',
116 "6 - isolation failure - got '$got', expected 'c2_init'");
117  
118 0 $odb2->transact_begin;
119 0 $o2c2->put(name => 'o2c2_after');
120  
121 0 $got=$o2c2->get('name');
122 0 $self->assert($got eq 'o2c2_after',
123 "7 - isolation failure - got '$got', expected 'o2c2_after'");
124 0 $got=$o1c2->get('name');
125 0 $self->assert($got eq 'c2_init',
126 "8 - isolation failure - got '$got', expected 'c2_init'");
127  
128 0 $odb1->transact_commit;
129 0 $got=$o1c1->get('name');
130 0 $self->assert($got eq 'o1c1_after',
131 "9 - isolation failure - got '$got', expected 'o1c1_after'");
132 0 $got=$o2c1->get('name');
133 0 $self->assert($got eq 'o1c1_before',
134 "10 - isolation failure - got '$got', expected 'o1c1_before'");
135  
136 0 $odb2->transact_rollback;
137 0 $got=$o1c2->get('name');
138 0 $self->assert($got eq 'o2c2_before',
139 "11 - isolation failure - got '$got', expected 'o2c2_before'");
140 0 $got=$o2c2->get('name');
141 0 $self->assert($got eq 'o2c2_before',
142 "12 - isolation failure - got '$got', expected 'o2c2_before'");
143  
144 # once our transaction has been rolled back we should start getting
145 # the value committed by odb1 transaction
146 #
147 0 $got=$o2c1->get('name');
148 0 $self->assert($got eq 'o1c1_after',
149 "13 - isolation failure - got '$got', expected 'o1c1_after'");
150 }
151  
152 1 1;
« testcases/FS/placeholders.pm ↑ Summary testcases/FS/basic.pm »