From c8f23b7de82a24e034dc9268a8dbd5f41f2a1cd4 Mon Sep 17 00:00:00 2001 From: Michiel Beijen Date: Thu, 3 Oct 2013 16:34:24 +0200 Subject: [PATCH] Added test file for rt85919. --- t/rt85919-fetch-lost-connection.t | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 t/rt85919-fetch-lost-connection.t diff --git a/t/rt85919-fetch-lost-connection.t b/t/rt85919-fetch-lost-connection.t new file mode 100644 index 00000000..9d189ef7 --- /dev/null +++ b/t/rt85919-fetch-lost-connection.t @@ -0,0 +1,44 @@ +use strict; +use warnings; +use DBI; +use Test::More; +use lib 't', '.'; +use vars qw($table $test_dsn $test_user $test_password $mdriver); +require 'lib.pl'; + +my $dbh; +eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password, + { RaiseError => 1, PrintError => 0, AutoCommit => 0 });}; +if ($@) { + plan skip_all => "ERROR: $@. Can't continue test"; +} +my $sth; +my $ok = eval { + print "Connecting...\n"; + ok( $sth = $dbh->do('SET wait_timeout = 5'), 'set wait_timeout'); + print "Sleeping...\n"; + sleep 7; + my $sql = 'SELECT 1'; + if (1) { + ok( $sth = $dbh->prepare($sql), 'prepare SQL'); + ok( $sth->execute(), 'execute SQL'); + my @res = $sth->fetchrow_array(); + is ( $res[0], undef, 'no rows returned'); + ok( $sth->finish(), 'finish'); + $sth = undef; + } + else { + print "Selecting...\n"; + my @res = $dbh->selectrow_array($sql); + } + $dbh->disconnect(); + $dbh = undef; + 1; +}; +if (not $ok) { + is ( $DBI::err, 2006, 'Received error 2006' ); + is ( $DBI::errstr, 'MySQL server has gone away', 'Received MySQL server has gone away'); + eval { $sth->finish(); } if defined $sth; + eval { $dbh->disconnect(); } if defined $dbh; +} +done_testing();