rollback and commit both work. Need to add MORE and MORE tests
[dbsrgits/DBM-Deep.git] / t / 33_transaction_commit.t
CommitLineData
359a01ac 1use strict;
2use Test::More tests => 13;
3use Test::Exception;
4use t::common qw( new_fh );
5
6use_ok( 'DBM::Deep' );
7
8my ($fh, $filename) = new_fh();
9my $db1 = DBM::Deep->new(
10 file => $filename,
11 locking => 1,
12 autoflush => 1,
13);
14
15my $db2 = DBM::Deep->new(
16 file => $filename,
17 locking => 1,
18 autoflush => 1,
19);
20
21$db1->{x} = 'y';
22is( $db1->{x}, 'y', "Before transaction, DB1's X is Y" );
23is( $db2->{x}, 'y', "Before transaction, DB2's X is Y" );
24
25$db1->begin_work;
26
27is( $db1->{x}, 'y', "DB1 transaction started, no actions - DB1's X is Y" );
28is( $db2->{x}, 'y', "DB1 transaction started, no actions - DB2's X is Y" );
29
30$db1->{x} = 'z';
31is( $db1->{x}, 'z', "Within DB1 transaction, DB1's X is Z" );
32is( $db2->{x}, 'y', "Within DB1 transaction, DB2's X is still Y" );
33
34$db2->{other_x} = 'foo';
35is( $db2->{other_x}, 'foo', "DB2 set other_x within DB1's transaction, so DB2 can see it" );
36is( $db1->{other_x}, undef, "Since other_x was added after the transaction began, DB1 doesn't see it." );
37
38$db1->commit;
39
25c7c8d6 40is( $db1->{x}, 'z', "After commit, DB1's X is Y" );
41is( $db2->{x}, 'z', "After commit, DB2's X is Y" );
359a01ac 42
43is( $db1->{other_x}, 'foo', "After DB1 transaction is over, DB1 can see other_x" );
44is( $db2->{other_x}, 'foo', "After DB1 transaction is over, DB2 can still see other_x" );