Changeset 164

Show
Ignore:
Timestamp:
05/13/09 21:17:02 (6 months ago)
Author:
miyagawa
Message:

PostgreSQL patch from clkao

Location:
trunk
Files:
20 modified

Legend:

Unmodified
Added
Removed
  • trunk/doc/schema-postgres.sql

    r131 r164  
    3232        grabbed_until   INTEGER NOT NULL, 
    3333        priority        SMALLINT, 
    34         coalesce        VARCHAR(255), 
    35         UNIQUE(funcid, uniqkey) 
     34        coalesce        VARCHAR(255) 
    3635); 
     36 
     37CREATE UNIQUE INDEX job_funcid_uniqkey ON job (funcid, uniqkey); 
    3738 
    3839CREATE INDEX job_funcid_runafter ON job (funcid, run_after); 
  • trunk/t/api.t

    r161 r164  
    88 
    99use TheSchwartz; 
    10 use Test::More tests => 108; 
     10use Test::More tests => 54*3; 
    1111 
    1212run_tests(54, sub { 
  • trunk/t/cleanup.t

    r114 r164  
    77 
    88use TheSchwartz; 
    9 use Test::More tests => 20; 
     9use Test::More tests => 30; 
    1010 
    1111# for testing: 
     
    1515run_tests(10, sub { 
    1616    my $client = test_client(dbs => ['ts1']); 
    17     my $dbh = DBI->connect(dsn_for("ts1"), 'root', ''); 
     17    my $dbh = DBI->connect(dsn_for("ts1"), $ENV{TS_DB_USER}, $ENV{TS_DB_PASS}); 
    1818    $client->can_do("Worker::Fail"); 
    1919    $client->can_do("Worker::Complete"); 
  • trunk/t/coalesce.t

    r84 r164  
    77 
    88use TheSchwartz; 
    9 use Test::More tests => 28; 
     9use Test::More tests => 14 * 3; 
    1010 
    1111run_tests(14, sub { 
  • trunk/t/dead-dbs.t

    r36 r164  
    88 
    99use TheSchwartz; 
    10 use Test::More tests => 4; 
     10use Test::More tests => 6; 
    1111 
    1212run_tests(2, sub { 
  • trunk/t/empty-db.t

    r36 r164  
    88 
    99use TheSchwartz; 
    10 use Test::More tests => 6; 
     10use Test::More tests => 9; 
    1111 
    1212run_tests(3, sub { 
     
    1616                                                { 
    1717                                                    dsn  => dsn_for('tempty1'), 
    18                                                     user => "root", 
    19                                                     pass => "", 
     18                                                    user => $ENV{TS_DB_USER}, 
     19                                                    pass =>  $ENV{TS_DB_PASS}, 
    2020                                                }, 
    2121                                                ]); 
  • trunk/t/evenly-distribute.t

    r89 r164  
    88 
    99use TheSchwartz; 
    10 use Test::More tests => 8; 
     10use Test::More tests => 12; 
    1111 
    1212run_tests(4, sub { 
     
    1919    } 
    2020 
    21     my $db1 = DBI->connect(dsn_for("ts1"), 'root', ''); 
    22     my $db2 = DBI->connect(dsn_for("ts2"), 'root', ''); 
     21    my $db1 = DBI->connect(dsn_for("ts1"), $ENV{TS_DB_USER}, $ENV{TS_DB_PASS}); 
     22    my $db2 = DBI->connect(dsn_for("ts2"), $ENV{TS_DB_USER}, $ENV{TS_DB_PASS}); 
    2323    die unless $db1 && $db2; 
    2424 
  • trunk/t/fail-working-multiple.t

    r84 r164  
    77 
    88use TheSchwartz; 
    9 use Test::More tests => 8; 
     9use Test::More tests => 12; 
    1010 
    1111run_tests(4, sub { 
  • trunk/t/funcid.t

    r42 r164  
    88 
    99use TheSchwartz; 
    10 use Test::More tests => 16; 
     10use Test::More tests => 24; 
    1111 
    1212run_tests(8, sub { 
  • trunk/t/grab_and_work_on.t

    r141 r164  
    77 
    88use TheSchwartz; 
    9 use Test::More tests => 18; 
     9use Test::More tests => 27; 
    1010 
    1111run_tests(9, sub { 
  • trunk/t/high-funcid-starvation.t

    r58 r164  
    88 
    99use TheSchwartz; 
    10 use Test::More tests => 8; 
     10use Test::More tests => 12; 
    1111 
    1212run_tests(4, sub { 
     
    1919    } 
    2020 
    21     my $db1 = DBI->connect(dsn_for("ts1"), 'root', ''); 
     21    my $db1 = DBI->connect(dsn_for("ts1"), $ENV{TS_DB_USER}, $ENV{TS_DB_PASS}); 
    2222    die unless $db1; 
    2323 
  • trunk/t/insert-and-do.t

    r103 r164  
    77 
    88use TheSchwartz; 
    9 use Test::More tests => 52; 
     9use Test::More tests => 26*3; 
    1010 
    1111run_tests(26, sub { 
  • trunk/t/lib/db-common.pl

    r160 r164  
    99 
    1010    run_tests_mysql($n, $code); 
     11    run_tests_pgsql($n, $code); 
    1112    run_tests_sqlite($n, $code); 
    1213} 
     
    2122  SKIP: { 
    2223      local $ENV{USE_MYSQL} = 1; 
     24      local $ENV{TS_DB_USER} ||= 'root'; 
    2325      my $dbh = eval { mysql_dbh() }; 
    2426      skip "MySQL not accessible as root on localhost", $n if $@; 
    2527      skip "InnoDB not available on localhost's MySQL", $n if $innodb && ! has_innodb($dbh); 
     28      $code->(); 
     29  } 
     30} 
     31 
     32sub run_tests_pgsql { 
     33    my ($n, $code) = @_; 
     34  SKIP: { 
     35      local $ENV{USE_PGSQL} = 1; 
     36      local $ENV{TS_DB_USER} ||= 'postgres'; 
     37      my $dbh = eval { pgsql_dbh() }; 
     38      skip "PgSQL not accessible as root on localhost", $n if $@; 
    2639      $code->(); 
    2740  } 
     
    7083                                          map { { 
    7184                                              dsn  => dsn_for($_), 
    72                                               user => "root", 
    73                                               pass => "", 
     85                                              user => $ENV{TS_DB_USER}, 
     86                                              pass => $ENV{TS_DB_PASS}, 
    7487                                              prefix => $pfx, 
    7588                                          } } @$dbs 
     
    92105sub schema_file { 
    93106    return "doc/schema.sql" if $ENV{USE_MYSQL}; 
     107    return "doc/schema-postgres.sql" if $ENV{USE_PGSQL}; 
    94108    return "t/schema-sqlite.sql"; 
    95109} 
     
    109123    if ($ENV{USE_MYSQL}) { 
    110124        return 'dbi:mysql:' . mysql_dbname($dbname); 
     125    } 
     126    elsif ($ENV{USE_PGSQL}) { 
     127        return 'dbi:Pg:dbname=' . mysql_dbname($dbname); 
    111128    } else { 
    112129        return 'dbi:SQLite:dbname=' . db_filename($dbname); 
     
    130147            create_mysql_db(mysql_dbname($dbname)); 
    131148        } 
     149        elsif ($ENV{USE_PGSQL}) { 
     150            create_pgsql_db(mysql_dbname($dbname)); 
     151        } 
    132152        my $dbh = DBI->connect(dsn_for($dbname), 
    133             'root', '', { RaiseError => 1, PrintError => 0 }) 
     153            $ENV{TS_DB_USER}, $ENV{TS_DB_PASS}, { RaiseError => 1, PrintError => 0 }) 
    134154            or die "Couldn't connect: $!\n"; 
    135155        my @sql = load_sql($schema); 
    136156        for my $sql (@sql) { 
    137             $sql =~ s!^\s*create\s+table\s+(\w+)!CREATE TABLE ${pfx}$1!i; 
     157            $sql =~ s!^\s*create\s+table\s+(\w+)!CREATE TABLE ${pfx}$1!mi; 
     158            $sql =~ s!^\s*(create.*?index)\s+(\w+)\s+on\s+(\w+)!$1 $2 ON ${pfx}$3!i; 
    138159            $sql .= " ENGINE=INNODB\n" if $ENV{USE_MYSQL}; 
    139160            $dbh->do($sql); 
     
    148169} 
    149170 
     171my $pg_dbh; 
     172 
     173sub pgsql_dbh { 
     174    return $pg_dbh if $pg_dbh; 
     175    $pg_dbh ||= 
     176        DBI->connect("DBI:Pg:dbname=postgres", "postgres", "", { RaiseError => 1 }) 
     177            or die "Couldn't connect to database"; 
     178} 
     179 
    150180sub create_mysql_db { 
    151181    my $dbname = shift; 
     
    156186    my $dbname = shift; 
    157187    mysql_dbh()->do("DROP DATABASE IF EXISTS $dbname"); 
     188} 
     189 
     190sub create_pgsql_db { 
     191    my $dbname = shift; 
     192    pgsql_dbh()->do("CREATE DATABASE $dbname"); 
     193} 
     194 
     195sub drop_pgsql_db { 
     196    my $dbname = shift; 
     197    undef $pg_dbh; 
     198    eval { pgsql_dbh()->do("DROP DATABASE IF EXISTS $dbname") }; 
    158199} 
    159200 
     
    163204        if ($ENV{USE_MYSQL}) { 
    164205            drop_mysql_db(mysql_dbname($db)); 
     206        } elsif ($ENV{USE_PGSQL}) { 
     207            drop_pgsql_db(mysql_dbname($db)); 
    165208        } else { 
    166209            my $file = db_filename($db); 
  • trunk/t/priority.t

    r136 r164  
    77 
    88use TheSchwartz; 
    9 use Test::More tests => 62; 
     9use Test::More tests => 31*3; 
    1010 
    1111our $record_expected; 
     
    5858    my ($class, $job) = @_; 
    5959    my $priority = $job->priority; 
     60 
    6061    ok((!defined($main::record_expected) && (!defined($priority))) 
    6162        || ($priority == $main::record_expected), "priority matches expected priority"); 
  • trunk/t/replace-with.t

    r84 r164  
    77 
    88use TheSchwartz; 
    9 use Test::More tests => 20; 
     9use Test::More tests => 30; 
    1010 
    1111run_tests(10, sub { 
  • trunk/t/retry-delay.t

    r36 r164  
    88 
    99use TheSchwartz; 
    10 use Test::More tests => 16; 
     10use Test::More tests => 24; 
    1111 
    1212run_tests(8, sub { 
  • trunk/t/scoreboard.t

    r160 r164  
    66require 't/lib/db-common.pl'; 
    77 
    8 use Test::More tests => 20; 
     8use Test::More tests => 30; 
    99 
    1010use TheSchwartz; 
     
    2626                                          map { { 
    2727                                              dsn  => dsn_for($_), 
    28                                               user => "root", 
    29                                               pass => "", 
     28                                              user => $ENV{TS_DB_USER}, 
     29                                              pass => $ENV{TS_DB_PASS}, 
    3030                                              prefix => $pfx, 
    3131                                          } } @$dbs 
  • trunk/t/server-time.t

    r161 r164  
    77 
    88use TheSchwartz; 
    9 use Test::More tests => 4; 
     9use Test::More tests => 6; 
    1010 
    1111run_tests(2, sub { 
  • trunk/t/unique.t

    r64 r164  
    88 
    99use TheSchwartz; 
    10 use Test::More tests => 12; 
     10use Test::More tests => 18; 
    1111 
    1212#use Data::ObjectDriver; 
  • trunk/t/work-before-funcids-exist.t

    r43 r164  
    88 
    99use TheSchwartz; 
    10 use Test::More tests => 4; 
     10use Test::More tests => 6; 
    1111 
    1212run_tests(2, sub {