~ubuntu-branches/ubuntu/precise/libdbd-pg-perl/precise

« back to all changes in this revision

Viewing changes to t/dbdpg_test_setup.pl

  • Committer: Bazaar Package Importer
  • Author(s): Gunnar Wolf
  • Date: 2008-06-06 12:55:26 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20080606125526-bz1nh7rmt7bpf12w
Tags: 2.8.0-1
* New upstream release
* Added myself as an uploader

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
                if ($arg->{dbquotes}) {
81
81
                        $testdsn =~ s/$alias\s*=(\w+)/'db="'.lc $2.'"'/e;
82
82
                }
 
83
 
83
84
                eval {
84
85
                        $dbh = DBI->connect($testdsn, $testuser, '',
85
86
                                                                {RaiseError => 1, PrintError => 0, AutoCommit => 1});
86
87
                };
87
 
                if ($@) {
88
 
                        if ($@ !~ /domain socket/ or 16 != $helpconnect) {
89
 
                                return $helpconnect, $@, undef;
90
 
                        }
91
 
 
92
 
                        ## If we created it, and it was shut down, start it up again
93
 
                        warn "Restarting test database $testdsn at $testdir\n";
94
 
 
95
 
                        my $COM = qq{$pg_ctl -l $testdir/dbdpg_test.logfile -D $testdir start};
96
 
                        if ($su) {
97
 
                                $COM = qq{su -m $su -c "$COM"};
98
 
                        }
99
 
                        $info = '';
100
 
                        eval { $info = qx{$COM}; };
101
 
                        if ($@ or $info !~ /\w/) {
102
 
                                $@ = "Could not startup new database ($@) ($info)";
103
 
                                return $helpconnect, $@, undef;
104
 
                        }
105
 
                        ## Wait for it to startup and verify the connection
106
 
                        sleep 1;
107
 
                        my $loop = 1;
108
 
                  STARTUP: {
109
 
                                eval {
110
 
                                        $dbh = DBI->connect($testdsn, $testuser, '',
111
 
                                                                                {RaiseError => 1, PrintError => 0, AutoCommit => 1});
112
 
                                };
113
 
                                if ($@ =~ /starting up/ or $@ =~ /PGSQL\.\d+/) {
114
 
                                        if ($loop++ < 20) {
115
 
                                                sleep 1;
116
 
                                                redo STARTUP;
 
88
 
 
89
                goto GOTDBH unless $@;
 
90
 
 
91
                if ($@ =~ /invalid connection option/) {
 
92
                        return $helpconnect, $@, undef;
 
93
                }
 
94
 
 
95
                ## If this was created by us, try and restart it
 
96
                if (16 == $helpconnect) {
 
97
 
 
98
                        ## Bypass if the testdir has been removed
 
99
                        if (! -e $testdir) {
 
100
                                warn "Test directory $testdir has been removed, will recreate from scratch\n";
 
101
                        }
 
102
                        else {
 
103
                                warn "Restarting test database $testdsn at $testdir\n";
 
104
 
 
105
                                my $COM = qq{$pg_ctl -l $testdir/dbdpg_test.logfile -D $testdir start};
 
106
                                if ($su) {
 
107
                                        $COM = qq{su -m $su -c "$COM"};
 
108
                                }
 
109
                                $info = '';
 
110
                                eval { $info = qx{$COM}; };
 
111
                                if ($@ or $info !~ /\w/) {
 
112
                                        $@ = "Could not startup new database ($@) ($info)";
 
113
                                        return $helpconnect, $@, undef;
 
114
                                }
 
115
                                ## Wait for it to startup and verify the connection
 
116
                                sleep 1;
 
117
                                my $loop = 1;
 
118
                          STARTUP: {
 
119
                                        eval {
 
120
                                                $dbh = DBI->connect($testdsn, $testuser, '',
 
121
                                                                                        {RaiseError => 1, PrintError => 0, AutoCommit => 1});
 
122
                                        };
 
123
                                        if ($@ =~ /starting up/ or $@ =~ /PGSQL\.\d+/) {
 
124
                                                if ($loop++ < 20) {
 
125
                                                        sleep 1;
 
126
                                                        redo STARTUP;
 
127
                                                }
117
128
                                        }
118
129
                                }
119
 
                        }
120
 
 
121
 
                        if ($@) {
122
 
                                return $helpconnect, $@, $dbh;
123
 
                        }
124
 
 
125
 
                } ## end got an error on connect attempt
126
 
 
127
 
                ## We've got a good connection, so do final tweaks and return
128
 
                goto GOTDBH;
 
130
 
 
131
                                if ($@) {
 
132
                                        return $helpconnect, $@, $dbh;
 
133
                                }
 
134
 
 
135
                                ## We've got a good connection, so do final tweaks and return
 
136
                                goto GOTDBH;
 
137
 
 
138
                        } ## end testdir exists
 
139
 
 
140
                } ## end error and we created this database
129
141
 
130
142
        } ## end got testdsn and testuser
131
143
 
132
 
        ## No previous info, so start connection attempt from scratch
 
144
        ## No previous info (or failed attempt), so start new connection attempt from scratch
133
145
 
134
146
        $testdsn ||= $ENV{DBI_DSN};
135
147
        $testuser ||= $ENV{DBI_USER};