All tests pass except for the transaction tests under MySQL. InnoDB sucks
[dbsrgits/DBM-Deep.git] / t / 45_references.t
1 use strict;
2 use warnings FATAL => 'all';
3
4 use Test::More;
5 use Test::Exception;
6 use t::common qw( new_dbm );
7
8 use_ok( 'DBM::Deep' );
9
10 if ( $ENV{NO_TEST_TRANSACTIONS} ) {
11     done_testing;
12     exit;
13 }
14
15 my $dbm_factory = new_dbm(
16     locking => 1,
17     autoflush => 1,
18     num_txns  => 16,
19 );
20 while ( my $dbm_maker = $dbm_factory->() ) {
21     my $db1 = $dbm_maker->();
22     my $db2 = $dbm_maker->();
23
24     $db1->{foo} = 5;
25     $db1->{bar} = $db1->{foo};
26
27     is( $db1->{foo}, 5, "Foo is still 5" );
28     is( $db1->{bar}, 5, "Bar is now 5" );
29
30     $db1->{foo} = 6;
31
32     is( $db1->{foo}, 6, "Foo is now 6" );
33     is( $db1->{bar}, 5, "Bar is still 5" );
34
35     $db1->{foo} = [ 1 .. 3 ];
36     $db1->{bar} = $db1->{foo};
37
38     is( $db1->{foo}[1], 2, "Foo[1] is still 2" );
39     is( $db1->{bar}[1], 2, "Bar[1] is now 2" );
40
41     $db1->{foo}[3] = 42;
42
43     is( $db1->{foo}[3], 42, "Foo[3] is now 42" );
44     is( $db1->{bar}[3], 42, "Bar[3] is also 42" );
45
46     delete $db1->{foo};
47     is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
48
49     $db1->{foo} = $db1->{bar};
50     $db2->begin_work;
51
52         delete $db2->{bar};
53         delete $db2->{foo};
54
55         is( $db2->{bar}, undef, "It's deleted in the transaction" );
56         is( $db1->{bar}[3], 42, "... but not in the main" );
57
58     $db2->rollback;
59
60     # Why hasn't this failed!? Is it because stuff isn't getting deleted as
61     # expected? I need a test that walks the sectors
62     is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
63     is( $db2->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
64
65     delete $db1->{foo};
66
67     is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
68 }
69
70 done_testing;
71
72 __END__
73 $db2->begin_work;
74
75   delete $db2->{bar};
76
77 $db2->commit;
78
79 ok( !exists $db1->{bar}, "After commit, bar is gone" );