"Fossies" - the Fresh Open Source Software Archive

Member "Apache-Session-1.93/t/99mysqllock.t" (12 Apr 2014, 2005 Bytes) of package /linux/www/Apache-Session-1.93.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 use Test::More;
    2 
    3 #plan skip_all => "Not running RDBM tests without APACHE_SESSION_MAINTAINER=1"
    4 #  unless $ENV{APACHE_SESSION_MAINTAINER};
    5 plan skip_all => "Optional modules (Test::Database, DBD::mysql, DBI) not installed"
    6   unless eval {
    7                require Test::Database;
    8                require DBD::mysql;
    9                require DBI;
   10               };
   11 
   12 if ($ENV{TRAVIS}) {
   13     my $cfg = << 'EOT';
   14     driver_dsn  = dbi:mysql:
   15     username    = root
   16 EOT
   17     Test::Database->load_config(\$cfg);
   18 }
   19 
   20 my @db_handles = Test::Database->handles('mysql');
   21 
   22 plan skip_all => "No mysql handle reported by Test::Database"
   23   unless @db_handles;
   24 
   25 my $mysql = $db_handles[0];
   26 my $dsn = $mysql->dsn();
   27 my $uname = $mysql->username();
   28 my $upass = $mysql->password();
   29 
   30 my $dbh  = DBI->connect($dsn, $uname, $upass);
   31 plan skip_all => "Cannot connect to DB specified in Test::Database config"
   32   unless $dbh;
   33 
   34 plan tests => 4;
   35 
   36 my $package = 'Apache::Session::Lock::MySQL';
   37 use_ok $package;
   38 
   39 my $session = {
   40     args => {
   41         LockDataSource => $dsn,
   42         LockUserName   => $uname,
   43         LockPassword   => $upass,
   44     },
   45     data => {
   46         _session_id => '09876543210987654321098765432109',
   47     }
   48 };
   49 
   50 my $lock = $package->new;
   51 my $sth  = $dbh->prepare(q{SELECT GET_LOCK('Apache-Session-09876543210987654321098765432109', 0)});
   52 my $sth2 = $dbh->prepare(q{SELECT RELEASE_LOCK('Apache-Session-09876543210987654321098765432109')});
   53 
   54 $lock->acquire_write_lock($session);
   55 
   56 $sth->execute();
   57 is +($sth->fetchrow_array)[0], 0, 'could not get lock';
   58 
   59 $lock->release_write_lock($session);
   60 
   61 $sth->execute();
   62 is +($sth->fetchrow_array)[0], 1, 'could get lock';
   63 
   64 $sth2->execute;
   65 undef $lock;
   66 
   67 $session->{args}->{LockHandle} = $dbh;
   68 
   69 $lock = $package->new;
   70 
   71 $lock->acquire_read_lock($session);
   72 
   73 $sth->execute();
   74 $sth->execute();
   75 is +($sth->fetchrow_array)[0], 1, 'could get lock';
   76 
   77 undef $lock;
   78 
   79 $sth->finish;
   80 $sth2->finish;
   81 $dbh->disconnect;