Skip to content

Commit

Permalink
Some stylistic test changes in preparation for next commits
Browse files Browse the repository at this point in the history
There are zero functional changes - everything has to do with making sure
we are not blindly poking into storage objects which may be changed to
delegates AND to make sure we do not leave any open cursors, which would show
up as deadlocks on multiple connections to the same SQLite file

Read under -w
  • Loading branch information
ribasushi committed Mar 18, 2015
1 parent df604e8 commit b74b15b
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 38 deletions.
2 changes: 0 additions & 2 deletions t/52leaks.t
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ unless (DBICTest::RunMode->is_plain) {
my $rs = $schema->resultset ('Artist');
my $storage = $schema->storage;

ok ($storage->connected, 'we are connected');

my $row_obj = $rs->search({}, { rows => 1})->next; # so that commits/rollbacks work
ok ($row_obj, 'row from db');

Expand Down
8 changes: 5 additions & 3 deletions t/67pager.t
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ $it = $rs->search(
{ order_by => 'title',
rows => 3 }
);
my $page = $it->page(2);

is( $page->count, 2, "standard resultset paged rs count ok" );
{
my $page = $it->page(2);

is( $page->next->title, "Generic Manufactured Singles", "second page of standard resultset ok" );
is( $page->count, 2, "standard resultset paged rs count ok" );

is( $page->next->title, "Generic Manufactured Singles", "second page of standard resultset ok" );
}

# test software-based limit paging
$it = $rs->search(
Expand Down
1 change: 1 addition & 0 deletions t/76select.t
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ my $subsel = $cds->search ({}, {
is ($subsel->count, 2, 'Subselect correctly limited the rs to 2 cds');
is ($subsel->next->title, $cds->next->title, 'First CD title match');
is ($subsel->next->title, $cds->next->title, 'Second CD title match');
$cds->reset;

is($schema->resultset('CD')->current_source_alias, "me", '$rs->current_source_alias returns "me"');

Expand Down
14 changes: 8 additions & 6 deletions t/88result_set_column.t
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ is($rs_title->min, 'Caterwaulin\' Blues', "min okay for title");

cmp_ok($rs_year->sum, '==', 9996, "three artists returned");

my $rso_year = $rs->search({}, { order_by => 'cdid' })->get_column('year');
is($rso_year->next, 1999, "reset okay");
{
my $rso_year = $rs->search({}, { order_by => 'cdid' })->get_column('year');
is($rso_year->next, 1999, "reset okay");

is($rso_year->first, 1999, "first okay");
is($rso_year->first, 1999, "first okay");

warnings_exist (sub {
is($rso_year->single, 1999, "single okay");
}, qr/Query returned more than one row/, 'single warned');
warnings_exist (sub {
is($rso_year->single, 1999, "single okay");
}, qr/Query returned more than one row/, 'single warned');
}


# test distinct propagation
Expand Down
10 changes: 6 additions & 4 deletions t/icdt/engine_specific/sqlite.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ use DBICTest;
no_deploy => 1, # Deploying would cause an early rebless
);

my $storage = $schema->storage;

is(
ref $schema->storage, 'DBIx::Class::Storage::DBI',
ref $storage, 'DBIx::Class::Storage::DBI',
'Starting with generic storage'
);

# Calling date_time_parser should cause the storage to be reblessed,
# so that we can pick up datetime_parser_type from subclasses
my $parser = $schema->storage->datetime_parser();
my $parser = $storage->datetime_parser();

is($parser, 'DateTime::Format::SQLite', 'Got expected storage-set datetime_parser');
isa_ok($schema->storage, 'DBIx::Class::Storage::DBI::SQLite', 'storage');
isa_ok($storage, 'DBIx::Class::Storage::DBI::SQLite', 'storage');

ok(! $schema->storage->connected, 'Not yet connected');
ok(! $storage->connected, 'Not yet connected');
}

# so user's env doesn't screw us
Expand Down
2 changes: 1 addition & 1 deletion t/inflate/serialize.t
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ is_deeply (
);

#===== make sure make_column_dirty interacts reasonably with inflation
$object = $rs->first;
$object = $rs->search({}, { rows => 1 })->next;
$object->update ({serialized => { x => 'y'}});

$object->serialized->{x} = 'z'; # change state without notifying $object
Expand Down
6 changes: 4 additions & 2 deletions t/lib/DBICTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,12 @@ sub init_schema {

my $schema;

my @dsn = $self->_database(%args);

if ($args{compose_connection}) {
$need_global_cleanup = 1;
$schema = DBICTest::Schema->compose_connection(
'DBICTest', $self->_database(%args)
'DBICTest', @dsn
);
} else {
$schema = DBICTest::Schema->compose_namespace('DBICTest');
Expand All @@ -334,7 +336,7 @@ sub init_schema {
}

if ( !$args{no_connect} ) {
$schema = $schema->connect($self->_database(%args));
$schema->connection(@dsn);
}

if ( !$args{no_deploy} ) {
Expand Down
17 changes: 14 additions & 3 deletions t/lib/DBICTest/BaseSchema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use base qw(DBICTest::Base DBIx::Class::Schema);

use Fcntl qw(:DEFAULT :seek :flock);
use Time::HiRes 'sleep';
use Scope::Guard ();
use DBICTest::Util::LeakTracer qw(populate_weakregistry assert_empty_weakregistry);
use DBICTest::Util 'local_umask';
use namespace::clean;
Expand All @@ -23,10 +24,20 @@ sub capture_executed_sql_bind {
local *DBIx::Class::Storage::DBI::_format_for_trace = sub { $_[1] };
Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO;

# can not use local() due to an unknown number of storages
# (think replicated)
my $orig_states = { map
{ $_ => $self->storage->$_ }
qw(debugcb debugobj debug)
};

my $sg = Scope::Guard->new(sub {
$self->storage->$_ ( $orig_states->{$_} ) for keys %$orig_states;
});

local $self->storage->{debugcb};
local $self->storage->{debugobj} = my $tracer_obj = DBICTest::SQLTracerObj->new;
local $self->storage->{debug} = 1;
$self->storage->debugcb(undef);
$self->storage->debugobj( my $tracer_obj = DBICTest::SQLTracerObj->new );
$self->storage->debug(1);

local $Test::Builder::Level = $Test::Builder::Level + 2;
$cref->();
Expand Down
2 changes: 1 addition & 1 deletion t/multi_create/multilev_single_PKeqFK.t
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ for my $type (qw/has_one might_have/) {
my $cd_title = "Test $type cd";
my $artist_names = [ map { "Artist via $type $_" } (1, 2) ];

my $someartist = $artist_rs->next;
my $someartist = $artist_rs->search({}, { rows => 1 })->next;

lives_ok (sub {
my $cd = $schema->resultset('CD')->create ({
Expand Down
2 changes: 1 addition & 1 deletion t/prefetch/standard.t
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ cmp_ok($rs->count, '==', 1, "single artist returned from multi-join");

is($rs->next->name, 'Caterwauler McCrae', "Correct artist returned");

$cd = $schema->resultset('Artist')->first->create_related('cds',
$cd = $schema->resultset('Artist')->search({ artistid => 1 })->first->create_related('cds',
{
title => 'Unproduced Single',
year => 2007
Expand Down
8 changes: 7 additions & 1 deletion t/resultset/update_delete.t
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ $schema->is_executed_sql_bind( sub {

# try the same sql with forced multicolumn in
$schema->is_executed_sql_bind( sub {
local $schema->storage->{_use_multicolumn_in} = 1;

my $orig_umi = $schema->storage->_use_multicolumn_in;
my $sg = Scope::Guard->new(sub {
$schema->storage->_use_multicolumn_in($orig_umi);
});

$schema->storage->_use_multicolumn_in(1);

# this can't actually execute on sqlite
eval { $fks_multi->update ({ read_count => \ 'read_count + 1' }) };
Expand Down
2 changes: 1 addition & 1 deletion t/storage/dbh_do.t
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ is_deeply (

# test nested aliasing
my $res = 'original';
$storage->dbh_do (sub {
$schema->storage->dbh_do (sub {
shift->dbh_do(sub { $_[3] = 'changed' }, @_)
}, $res);

Expand Down
2 changes: 1 addition & 1 deletion t/storage/reconnect.t
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ close $db_file;
# Catch the DBI connection error
local $SIG{__WARN__} = sub {};
throws_ok {
my @art_three = $schema->resultset("Artist")->search( {}, { order_by => { -desc => 'name' } } );
$schema->resultset("Artist")->create({ name => 'not gonna happen' });
} qr/not a database/, 'The operation failed';
}

Expand Down
17 changes: 13 additions & 4 deletions t/storage/savepoints.t
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ for ('', keys %$env2optdep) { SKIP: {

note "Testing $prefix";

local $schema->storage->{debugobj} = my $stats = DBICTest::SVPTracerObj->new;
local $schema->storage->{debug} = 1;
# can not use local() due to an unknown number of storages
# (think replicated)
my $orig_states = { map
{ $_ => $schema->storage->$_ }
qw(debugcb debugobj debug)
};
my $sg = Scope::Guard->new(sub {
$schema->storage->$_ ( $orig_states->{$_} ) for keys %$orig_states;
});
$schema->storage->debugobj (my $stats = DBICTest::SVPTracerObj->new);
$schema->storage->debug (1);

$schema->resultset('Artist')->create({ name => 'foo' });

Expand Down Expand Up @@ -229,12 +238,12 @@ for ('', keys %$env2optdep) { SKIP: {
'rollback from inner transaction';

### cleanupz
$schema->storage->dbh->do ("DROP TABLE artist");
$schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") });
}}

done_testing;

END {
eval { $schema->storage->dbh->do ("DROP TABLE artist") } if defined $schema;
eval { $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") }) } if defined $schema;
undef $schema;
}
16 changes: 8 additions & 8 deletions t/storage/txn.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ my $code = sub {
for my $want (0,1) {
my $schema = DBICTest->init_schema;

is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0');
is( $schema->storage->transaction_depth, 0, 'txn depth starts at 0');

my @titles = map {'txn_do test CD ' . $_} (1..5);
my $artist = $schema->resultset('Artist')->find(1);
Expand All @@ -56,7 +56,7 @@ for my $want (0,1) {
title => "txn_do test CD $_",
})->first->year, 2006, "new CD $_ year correct") for (1..5);

is( $schema->storage->{transaction_depth}, 0, 'txn depth has been reset');
is( $schema->storage->transaction_depth, 0, 'txn depth has been reset');
}

# Test txn_do() @_ aliasing support
Expand All @@ -72,7 +72,7 @@ for my $want (0,1) {
{
my $schema = DBICTest->init_schema;

is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0');
is( $schema->storage->transaction_depth, 0, 'txn depth starts at 0');

my $nested_code = sub {
my ($schema, $artist, $code) = @_;
Expand All @@ -96,7 +96,7 @@ for my $want (0,1) {
})->first->year, 2006, qq{nested txn_do CD$_ year ok}) for (1..10);
is($artist->cds->count, $count_before+10, 'nested txn_do added all CDs');

is( $schema->storage->{transaction_depth}, 0, 'txn depth has been reset');
is( $schema->storage->transaction_depth, 0, 'txn depth has been reset');
}

# test nested txn_begin on fresh connection
Expand Down Expand Up @@ -260,7 +260,7 @@ my $fail_code = sub {
# Test failed txn_do()
for my $pass (1,2) {

is( $schema->storage->{transaction_depth}, 0, "txn depth starts at 0 (pass $pass)");
is( $schema->storage->transaction_depth, 0, "txn depth starts at 0 (pass $pass)");

my $artist = $schema->resultset('Artist')->find(3);

Expand All @@ -274,13 +274,13 @@ my $fail_code = sub {
})->first;
ok(!defined($cd), qq{failed txn_do didn't change the cds table (pass $pass)});

is( $schema->storage->{transaction_depth}, 0, "txn depth has been reset (pass $pass)");
is( $schema->storage->transaction_depth, 0, "txn depth has been reset (pass $pass)");
}


# Test failed txn_do() with failed rollback
{
is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0');
is( $schema->storage->transaction_depth, 0, 'txn depth starts at 0');

my $artist = $schema->resultset('Artist')->find(3);

Expand Down Expand Up @@ -322,7 +322,7 @@ my $fail_code = sub {
{
my $schema = DBICTest->init_schema();

is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0');
is( $schema->storage->transaction_depth, 0, 'txn depth starts at 0');

my $nested_fail_code = sub {
my ($schema, $artist, $code1, $code2) = @_;
Expand Down

0 comments on commit b74b15b

Please sign in to comment.