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