Skip to content

Commit a17189f

Browse files
committed
Fix test t/41int_min_max.t to use temporary tables
Sometimes CREATE TABLE statement throws following error: Deadlock found when trying to get lock; try restarting transaction
1 parent 9c0a139 commit a17189f

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

t/41int_min_max.t

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if ($dbh->{mariadb_serverversion} < 50002) {
1717
"SKIP TEST: You must have MySQL version 5.0.2 and greater for this test to run";
1818
}
1919
# nostrict tests + strict tests + init/tear down commands
20-
plan tests => (19*8 + 19*8 + 4) * 2;
20+
plan tests => (19*8 + 19*8 + 3) * 2;
2121

2222
my $table = 'dbd_mysql_t41minmax'; # name of the table we will be using
2323
my $mode; # 'strict' or 'nostrict' corresponds to strict SQL mode
@@ -26,9 +26,8 @@ sub test_int_type ($$$$) {
2626
my ($perl_type, $mariadb_type, $min, $max) = @_;
2727

2828
# Create the table
29-
ok($dbh->do(qq{DROP TABLE IF EXISTS $table}), "removing $table");
3029
ok($dbh->do(qq{
31-
CREATE TABLE `$table` (
30+
CREATE TEMPORARY TABLE `$table` (
3231
`id` int not null auto_increment,
3332
`val` $mariadb_type,
3433
primary key (id)
@@ -38,7 +37,7 @@ sub test_int_type ($$$$) {
3837
my ($store, $retrieve); # statements
3938
my $read_value; # retrieved value
4039
ok($store = $dbh->prepare("INSERT INTO $table (val) VALUES (?)"));
41-
ok($retrieve = $dbh->prepare("SELECT val from $table where id=(SELECT MAX(id) FROM $table)"));
40+
ok($retrieve = $dbh->prepare("SELECT val from $table ORDER BY id DESC LIMIT 1"));
4241

4342
########################################
4443
# Insert allowed min value
@@ -107,6 +106,8 @@ sub test_int_type ($$$$) {
107106
($read_value) = $retrieve->fetchrow_array();
108107
cmp_ok($read_value, 'eq', $max, "retrieved maximal value for type $mariadb_type, mode=$mode");
109108
};
109+
110+
ok($dbh->do(qq{DROP TEMPORARY TABLE `$table`}), "removing $table");
110111
}
111112

112113
$dbh->disconnect;
@@ -141,7 +142,5 @@ test_int_type(DBI::SQL_INTEGER, 'int unsigned', 0, 2**32-1);
141142
test_int_type(DBI::SQL_BIGINT, 'bigint signed', -2**63, 2**63-1);
142143
test_int_type(DBI::SQL_BIGINT, 'bigint unsigned', 0, 2**64-1);
143144

144-
ok ($dbh->do("DROP TABLE $table"));
145-
146145
ok $dbh->disconnect;
147146
}

0 commit comments

Comments
 (0)