summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/consistent_snapshot.pl107
-rw-r--r--tests/mysql_client_fw.c2
-rw-r--r--tests/mysql_client_test.c99
3 files changed, 192 insertions, 16 deletions
diff --git a/tests/consistent_snapshot.pl b/tests/consistent_snapshot.pl
new file mode 100755
index 00000000000..9e53eaea6a1
--- /dev/null
+++ b/tests/consistent_snapshot.pl
@@ -0,0 +1,107 @@
+#! /usr/bin/perl
+
+# Test START TRANSACTION WITH CONSISTENT SNAPSHOT.
+# With MWL#116, this is implemented so it is actually consistent.
+
+use strict;
+use warnings;
+
+use DBI;
+
+my $UPDATERS= 10;
+my $READERS= 5;
+
+my $ROWS= 50;
+my $DURATION= 20;
+
+my $stop_time= time() + $DURATION;
+
+sub my_connect {
+ my $dbh= DBI->connect("dbi:mysql:mysql_socket=/tmp/mysql.sock;database=test",
+ "root", undef, { RaiseError=>1, PrintError=>0, AutoCommit=>0});
+ $dbh->do("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ");
+ $dbh->do("SET SESSION autocommit = 0");
+ return $dbh;
+}
+
+sub my_setup {
+ my $dbh= my_connect();
+
+ $dbh->do("DROP TABLE IF EXISTS test_consistent_snapshot1, test_consistent_snapshot2");
+ $dbh->do(<<TABLE);
+CREATE TABLE test_consistent_snapshot1 (
+ a INT PRIMARY KEY,
+ b INT NOT NULL
+) ENGINE=InnoDB
+TABLE
+ $dbh->do(<<TABLE);
+CREATE TABLE test_consistent_snapshot2(
+ a INT PRIMARY KEY,
+ b INT NOT NULL
+) ENGINE=PBXT
+TABLE
+
+ for (my $i= 0; $i < $ROWS; $i++) {
+ my $value= int(rand()*1000);
+ $dbh->do("INSERT INTO test_consistent_snapshot1 VALUES (?, ?)", undef,
+ $i, $value);
+ $dbh->do("INSERT INTO test_consistent_snapshot2 VALUES (?, ?)", undef,
+ $i, -$value);
+ }
+ $dbh->commit();
+ $dbh->disconnect();
+}
+
+sub my_updater {
+ my $dbh= my_connect();
+
+ while (time() < $stop_time) {
+ my $i1= int(rand()*$ROWS);
+ my $i2= int(rand()*$ROWS);
+ my $v= int(rand()*99)-49;
+ $dbh->do("UPDATE test_consistent_snapshot1 SET b = b + ? WHERE a = ?",
+ undef, $v, $i1);
+ $dbh->do("UPDATE test_consistent_snapshot2 SET b = b - ? WHERE a = ?",
+ undef, $v, $i2);
+ $dbh->commit();
+ }
+
+ $dbh->disconnect();
+ exit(0);
+}
+
+sub my_reader {
+ my $dbh= my_connect();
+
+ my $iteration= 0;
+ while (time() < $stop_time) {
+ $dbh->do("START TRANSACTION WITH CONSISTENT SNAPSHOT");
+ my $s1= $dbh->selectrow_arrayref("SELECT SUM(b) FROM test_consistent_snapshot1");
+ $s1= $s1->[0];
+ my $s2= $dbh->selectrow_arrayref("SELECT SUM(b) FROM test_consistent_snapshot2");
+ $s2= $s2->[0];
+ $dbh->commit();
+ if ($s1 + $s2 != 0) {
+ print STDERR "Found inconsistency, s1=$s1 s2=$s2 iteration=$iteration\n";
+ last;
+ }
+ ++$iteration;
+ }
+
+ $dbh->disconnect();
+ exit(0);
+}
+
+my_setup();
+
+for (1 .. $UPDATERS) {
+ fork() || my_updater();
+}
+
+for (1 .. $READERS) {
+ fork() || my_reader();
+}
+
+waitpid(-1, 0) for (1 .. ($UPDATERS + $READERS));
+
+print "All checks done\n";
diff --git a/tests/mysql_client_fw.c b/tests/mysql_client_fw.c
index 28e2e79e7b0..222e5a75055 100644
--- a/tests/mysql_client_fw.c
+++ b/tests/mysql_client_fw.c
@@ -351,7 +351,7 @@ static MYSQL* client_connect(ulong flag, uint protocol, my_bool auto_reconnect)
have_innodb= check_have_innodb(mysql);
if (!opt_silent)
- fprintf(stdout, "OK");
+ fprintf(stdout, "OK\n");
return mysql;
}
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 5f9d7bc76c8..9632b4fdca7 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -441,7 +441,7 @@ static void test_prepare_field_result()
myquery(rc);
rc= mysql_query(mysql, "CREATE TABLE test_prepare_field_result(int_c int, "
- "var_c varchar(50), ts_c timestamp(14), "
+ "var_c varchar(50), ts_c timestamp, "
"char_c char(4), date_c date, extra tinyint)");
myquery(rc);
@@ -3236,11 +3236,11 @@ static void test_fetch_date()
myquery(rc);
rc= mysql_query(mysql, "CREATE TABLE test_bind_result(c1 date, c2 time, \
- c3 timestamp(14), \
+ c3 timestamp, \
c4 year, \
c5 datetime, \
- c6 timestamp(4), \
- c7 timestamp(6))");
+ c6 timestamp, \
+ c7 timestamp)");
myquery(rc);
rc= mysql_query(mysql, "SET SQL_MODE=''");
@@ -3554,7 +3554,7 @@ static void test_prepare_ext()
" c12 numeric(8, 4),"
" c13 date,"
" c14 datetime,"
- " c15 timestamp(14),"
+ " c15 timestamp,"
" c16 time,"
" c17 year,"
" c18 bit,"
@@ -4588,7 +4588,7 @@ static void test_manual_sample()
}
if (mysql_query(mysql, "CREATE TABLE test_table(col1 int, col2 varchar(50), \
col3 smallint, \
- col4 timestamp(14))"))
+ col4 timestamp)"))
{
fprintf(stderr, "\n create table failed");
fprintf(stderr, "\n %s", mysql_error(mysql));
@@ -5498,7 +5498,7 @@ static void test_date()
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_date");
myquery(rc);
- rc= mysql_query(mysql, "CREATE TABLE test_date(c1 TIMESTAMP(14), \
+ rc= mysql_query(mysql, "CREATE TABLE test_date(c1 TIMESTAMP, \
c2 TIME, \
c3 DATETIME, \
c4 DATE)");
@@ -5564,10 +5564,10 @@ static void test_date_ts()
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_date");
myquery(rc);
- rc= mysql_query(mysql, "CREATE TABLE test_date(c1 TIMESTAMP(10), \
- c2 TIMESTAMP(14), \
+ rc= mysql_query(mysql, "CREATE TABLE test_date(c1 TIMESTAMP, \
+ c2 TIMESTAMP, \
c3 TIMESTAMP, \
- c4 TIMESTAMP(6))");
+ c4 TIMESTAMP)");
myquery(rc);
@@ -7256,7 +7256,7 @@ static void test_fetch_seek()
myquery(rc);
- rc= mysql_query(mysql, "create table t1(c1 int primary key auto_increment, c2 char(10), c3 timestamp(14))");
+ rc= mysql_query(mysql, "create table t1(c1 int primary key auto_increment, c2 char(10), c3 timestamp)");
myquery(rc);
rc= mysql_query(mysql, "insert into t1(c2) values('venu'), ('mysql'), ('open'), ('source')");
@@ -8026,7 +8026,7 @@ static void test_ts()
char name;
char query[MAX_TEST_QUERY_LENGTH];
const char *queries [3]= {"SELECT a, b, c FROM test_ts WHERE %c=?",
- "SELECT a, b, c FROM test_ts WHERE %c=?",
+ "SELECT a, b, c FROM test_ts WHERE %c=CAST(? AS TIME)",
"SELECT a, b, c FROM test_ts WHERE %c=CAST(? AS DATE)"};
myheader("test_ts");
@@ -11445,7 +11445,7 @@ static void test_datetime_ranges()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
- DIE_UNLESS(mysql_warning_count(mysql) != 6);
+ DIE_UNLESS(mysql_warning_count(mysql) == 6);
verify_col_data("t1", "year", "0000-00-00 00:00:00");
verify_col_data("t1", "month", "0000-00-00 00:00:00");
@@ -11476,7 +11476,7 @@ static void test_datetime_ranges()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
- DIE_UNLESS(mysql_warning_count(mysql) != 3);
+ DIE_UNLESS(mysql_warning_count(mysql) == 3);
verify_col_data("t1", "year", "0000-00-00 00:00:00");
verify_col_data("t1", "month", "0000-00-00 00:00:00");
@@ -17462,8 +17462,76 @@ static void test_bug56976()
}
/*
- Bug#13001491: MYSQL_REFRESH CRASHES WHEN STORED ROUTINES ARE RUN CONCURRENTLY.
+ Test that CLIENT_PROGRESS works.
*/
+
+uint progress_stage, progress_max_stage, progress_count;
+
+static void report_progress(const MYSQL *mysql __attribute__((unused)),
+ uint stage, uint max_stage,
+ double progress __attribute__((unused)),
+ const char *proc_info __attribute__((unused)),
+ uint proc_info_length __attribute__((unused)))
+{
+ progress_stage= stage;
+ progress_max_stage= max_stage;
+ progress_count++;
+}
+
+
+static void test_progress_reporting()
+{
+ int rc, i;
+ MYSQL* conn;
+
+ /* Progress reporting doesn't work yet with embedded server */
+ if (embedded_server_arg_count)
+ return;
+
+ myheader("test_progress_reporting");
+
+ conn= client_connect(CLIENT_PROGRESS, MYSQL_PROTOCOL_TCP, 0);
+ DIE_UNLESS(conn->client_flag & CLIENT_PROGRESS);
+
+ mysql_options(conn, MYSQL_PROGRESS_CALLBACK, (void*) report_progress);
+ rc= mysql_query(conn, "set @save=@@global.progress_report_time");
+ myquery(rc);
+ rc= mysql_query(conn, "set @@global.progress_report_time=1");
+ myquery(rc);
+
+ rc= mysql_query(conn, "drop table if exists t1,t2");
+ myquery(rc);
+ rc= mysql_query(conn, "create table t1 (f2 varchar(255)) engine=aria");
+ myquery(rc);
+ rc= mysql_query(conn, "create table t2 like t1");
+ myquery(rc);
+ rc= mysql_query(conn, "insert into t1 (f2) values (repeat('a',100)),(repeat('b',200)),(repeat('c',202)),(repeat('d',202)),(repeat('e',202)),(repeat('f',202)),(repeat('g',23))");
+ myquery(rc);
+ for (i= 0 ; i < 5 ; i++)
+ {
+ rc= mysql_query(conn, "insert into t2 (f2) select f2 from t1");
+ myquery(rc);
+ rc= mysql_query(conn, "insert into t1 (f2) select f2 from t2");
+ myquery(rc);
+ }
+ rc= mysql_query(conn, "alter table t1 add f1 int primary key auto_increment, add key (f2), order by f2");
+ myquery(rc);
+ if (!opt_silent)
+ printf("Got progress_count: %u stage: %u max_stage: %u\n",
+ progress_count, progress_stage, progress_max_stage);
+ DIE_UNLESS(progress_count > 0 && progress_stage >=2 && progress_max_stage == 3);
+ myquery(rc);
+ rc= mysql_query(conn, "set @@global.progress_report_time=@save");
+ myquery(rc);
+ client_disconnect(conn, 0);
+}
+
+
+/*
+ Bug#13001491: MYSQL_REFRESH CRASHES WHEN STORED ROUTINES ARE RUN
+ CONCURRENTLY.
+*/
+
static void test_bug13001491()
{
int rc;
@@ -17788,6 +17856,7 @@ static struct my_tests_st my_tests[]= {
{ "test_bug47485", test_bug47485 },
{ "test_bug58036", test_bug58036 },
{ "test_bug56976", test_bug56976 },
+ { "test_progress_reporting", test_progress_reporting },
{ "test_bug13001491", test_bug13001491 },
{ 0, 0 }
};