Skip to content

Commit

Permalink
Run the entire test suite under replicated SQLite on DBICTEST_VIA_REP…
Browse files Browse the repository at this point in the history
…LICATED

There isn't real replication, the reader and writer in fact talk to the same
on-disk file. Still this is effective enough to put into CI.
  • Loading branch information
ribasushi committed Mar 18, 2015
1 parent 7d6c28b commit 8b60b92
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/DBIx/Class.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use DBIx::Class::StartupCheck;
use DBIx::Class::Exception;

__PACKAGE__->mk_group_accessors(inherited => '_skip_namespace_frames');
__PACKAGE__->_skip_namespace_frames('^DBIx::Class|^SQL::Abstract|^Try::Tiny|^Class::Accessor::Grouped|^Context::Preserve');
__PACKAGE__->_skip_namespace_frames('^DBIx::Class|^SQL::Abstract|^Try::Tiny|^Class::Accessor::Grouped|^Context::Preserve|^Moose::Meta::');

# FIXME - this is not really necessary, and is in
# fact going to slow things down a bit
Expand Down
6 changes: 6 additions & 0 deletions maint/travis-ci_scripts/20_install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ if [[ "$POISON_ENV" = "true" ]] ; then
export DBI_DSN="dbi:ODBC:server=NonexistentServerAddress"
export DBI_DRIVER="ADO"

# if we have Moose - try to run everything under replicated
# FIXME - when switching to Moo kill this
if [[ "$CLEANTEST" != "true" ]] && perl -M5.008003 -e 1 &>/dev/null ; then
export DBICTEST_VIA_REPLICATED=1
fi

# some people do in fact set this - boggle!!!
# it of course won't work before 5.8.4
if perl -M5.008004 -e 1 &>/dev/null ; then
Expand Down
3 changes: 2 additions & 1 deletion t/52leaks.t
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ my $weak_registry = {};
my $has_dt;

# Skip the heavy-duty leak tracing when just doing an install
unless (DBICTest::RunMode->is_plain) {
# or when having Moose crap all over everything
if ( !$ENV{DBICTEST_VIA_REPLICATED} and !DBICTest::RunMode->is_plain ) {

# redefine the bless override so that we can catch each and every object created
no warnings qw/redefine once/;
Expand Down
2 changes: 2 additions & 0 deletions t/99dbic_sqlt_parser.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use DBIx::Class::Optional::Dependencies -skip_all_without => 'deploy';
use strict;
use warnings;

BEGIN { $ENV{DBICTEST_VIA_REPLICATED} = 0 }

use Test::More;
use Test::Warn;
use Test::Exception;
Expand Down
13 changes: 9 additions & 4 deletions t/icdt/engine_specific/sqlite.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ use DBICTest;

my $storage = $schema->storage;

is(
ref $storage, 'DBIx::Class::Storage::DBI',
'Starting with generic storage'
);
if ($ENV{DBICTEST_VIA_REPLICATED}) {
$storage = $storage->master;
}
else {
is(
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
Expand Down
13 changes: 12 additions & 1 deletion t/lib/DBICTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ sub _database {
# set a *DBI* disconnect callback, to make sure the physical SQLite
# file is still there (i.e. the test does not attempt to delete
# an open database, which fails on Win32)
if (my $guard_cb = __mk_disconnect_guard($db_file)) {
if (! $storage->{master} and my $guard_cb = __mk_disconnect_guard($db_file)) {
$dbh->{Callbacks} = {
connect => sub { $guard_cb->('connect') },
disconnect => sub { $guard_cb->('disconnect') },
Expand Down Expand Up @@ -320,6 +320,14 @@ sub init_schema {

my $schema;

if (
$ENV{DBICTEST_VIA_REPLICATED} &&=
( !$args{storage_type} && !defined $args{sqlite_use_file} )
) {
$args{storage_type} = ['::DBI::Replicated', { balancer_type => '::Random' }];
$args{sqlite_use_file} = 1;
}

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

if ($args{compose_connection}) {
Expand All @@ -337,6 +345,9 @@ sub init_schema {

if ( !$args{no_connect} ) {
$schema->connection(@dsn);

$schema->storage->connect_replicants(\@dsn)
if $ENV{DBICTEST_VIA_REPLICATED};
}

if ( !$args{no_deploy} ) {
Expand Down
11 changes: 10 additions & 1 deletion t/lib/DBICTest/SQLTracerObj.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ use warnings;

use base 'DBIx::Class::Storage::Statistics';

sub query_start { push @{$_[0]{sqlbinds}}, [ ($_[1] =~ /^\s*(\S+)/)[0], [ $_[1], @{ $_[2]||[] } ] ] }
sub query_start {
my ($self, $sql, $bind) = @_;

my $op = ($sql =~ /^\s*(\S+)/)[0];

$sql =~ s/^ \s* \Q$op\E \s+ \[ .+? \]/$op/x
if $ENV{DBICTEST_VIA_REPLICATED};

push @{$self->{sqlbinds}}, [ $op, [ $sql, @{ $bind || [] } ] ];
}

# who the hell came up with this API >:(
for my $txn (qw(begin rollback commit)) {
Expand Down
10 changes: 6 additions & 4 deletions t/storage/base.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ use Data::Dumper;

my $schema = DBICTest->init_schema( sqlite_use_file => 1 );

is( ref($schema->storage), 'DBIx::Class::Storage::DBI::SQLite',
'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite' );

my $storage = $schema->storage;
$storage->ensure_connected;

is(
ref($storage),
'DBIx::Class::Storage::DBI::SQLite',
'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite'
) unless $ENV{DBICTEST_VIA_REPLICATED};

throws_ok {
$schema->storage->throw_exception('test_exception_42');
Expand Down
4 changes: 4 additions & 0 deletions t/storage/dbh_do.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use DBICTest;
my $schema = DBICTest->init_schema();
my $storage = $schema->storage;

$storage = $storage->master
if $ENV{DBICTEST_VIA_REPLICATED};


# test (re)connection
for my $disconnect (0, 1) {
$schema->storage->_dbh->disconnect if $disconnect;
Expand Down
2 changes: 2 additions & 0 deletions t/storage/debug.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use strict;
use warnings;
no warnings 'once';

BEGIN { $ENV{DBICTEST_VIA_REPLICATED} = 0 }

use Test::More;
use Test::Exception;
use Try::Tiny;
Expand Down
2 changes: 2 additions & 0 deletions t/storage/disable_sth_caching.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use strict;
use warnings;

BEGIN { $ENV{DBICTEST_VIA_REPLICATED} = 0 }

use Test::More;
use lib qw(t/lib);
use DBICTest;
Expand Down
2 changes: 2 additions & 0 deletions t/storage/on_connect_do.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use strict;
use warnings;

BEGIN { $ENV{DBICTEST_VIA_REPLICATED} = 0 }

# !!! do not replace this with done_testing - tests reside in the callbacks
# !!! number of calls is important
use Test::More tests => 13;
Expand Down
13 changes: 13 additions & 0 deletions t/storage/savepoints.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use warnings;

use Test::More;
use Test::Exception;
use DBIx::Class::_Util qw(modver_gt_or_eq sigwarn_silencer);

use lib qw(t/lib);
use DBICTest;
Expand Down Expand Up @@ -227,6 +228,15 @@ for ('', keys %$env2optdep) { SKIP: {

is_deeply( $schema->storage->savepoints, [], 'All savepoints forgotten' );

SKIP: {
skip "Reading inexplicably fails on very old replicated DBD::SQLite<1.33", 1 if (
$ENV{DBICTEST_VIA_REPLICATED}
and
$prefix eq 'SQLite Internal DB'
and
! modver_gt_or_eq('DBD::SQLite', '1.33')
);

ok($ars->search({ name => 'in_outer_transaction' })->first,
'commit from outer transaction');
ok($ars->search({ name => 'in_outer_transaction2' })->first,
Expand All @@ -236,6 +246,7 @@ for ('', keys %$env2optdep) { SKIP: {
is $ars->search({ name => 'in_inner_transaction_rolling_back' })->first,
undef,
'rollback from inner transaction';
}

### cleanupz
$schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") });
Expand All @@ -244,6 +255,8 @@ for ('', keys %$env2optdep) { SKIP: {
done_testing;

END {
local $SIG{__WARN__} = sigwarn_silencer( qr/Internal transaction state of handle/ )
unless modver_gt_or_eq('DBD::SQLite', '1.33');
eval { $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") }) } if defined $schema;
undef $schema;
}
2 changes: 2 additions & 0 deletions xt/extra/lean_startup.t
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ BEGIN {
}
}

BEGIN { $ENV{DBICTEST_VIA_REPLICATED} = 0 }

#######
### This is where the test starts
#######
Expand Down

0 comments on commit 8b60b92

Please sign in to comment.