Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit db973ff

Browse files
committed
Fix some libpq_pipeline test problems
Test pipeline_abort was not checking that it got the rows it expected in one mode; make it do so. This doesn't fix the actual problem (no idea what that is, yet) but at least it should make it more obvious rather than being visible only as a difference in the trace output. While at it, fix other infelicities in the test: * I reversed the order of result vs. expected in like(). * The output traces from -t are being put in the log dir, which means the buildfarm script uselessly captures them. Put them in a separate dir tmp_check/traces instead, to avoid cluttering the buildfarm results. * Test pipelined_insert was using too large a row count. Reduce that a tad and add a filler column to make each insert a little bulkier, while still keeping enough that a buffer is filled and we have to switch mode.
1 parent b12bd48 commit db973ff

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

src/test/modules/libpq_pipeline/libpq_pipeline.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@ char *tracefile = NULL; /* path to PQtrace() file */
4545
static const char *const drop_table_sql =
4646
"DROP TABLE IF EXISTS pq_pipeline_demo";
4747
static const char *const create_table_sql =
48-
"CREATE UNLOGGED TABLE pq_pipeline_demo(id serial primary key, itemno integer);";
48+
"CREATE UNLOGGED TABLE pq_pipeline_demo(id serial primary key, itemno integer,"
49+
"int8filler int8);";
4950
static const char *const insert_sql =
50-
"INSERT INTO pq_pipeline_demo(itemno) VALUES ($1);";
51+
"INSERT INTO pq_pipeline_demo(itemno) VALUES ($1)";
52+
static const char *const insert_sql2 =
53+
"INSERT INTO pq_pipeline_demo(itemno,int8filler) VALUES ($1, $2)";
5154

52-
/* max char length of an int32, plus sign and null terminator */
55+
/* max char length of an int32/64, plus sign and null terminator */
5356
#define MAXINTLEN 12
57+
#define MAXINT8LEN 20
5458

5559
static void
5660
exit_nicely(PGconn *conn)
@@ -243,6 +247,7 @@ test_pipeline_abort(PGconn *conn)
243247
const char *dummy_params[1] = {"1"};
244248
Oid dummy_param_oids[1] = {INT4OID};
245249
int i;
250+
int gotrows;
246251
bool goterror;
247252

248253
fprintf(stderr, "aborted pipeline... ");
@@ -441,12 +446,14 @@ test_pipeline_abort(PGconn *conn)
441446
pg_fatal("pipeline sync failed: %s", PQerrorMessage(conn));
442447
PQsetSingleRowMode(conn);
443448
goterror = false;
449+
gotrows = 0;
444450
while ((res = PQgetResult(conn)) != NULL)
445451
{
446452
switch (PQresultStatus(res))
447453
{
448454
case PGRES_SINGLE_TUPLE:
449455
printf("got row: %s\n", PQgetvalue(res, 0, 0));
456+
gotrows++;
450457
break;
451458
case PGRES_FATAL_ERROR:
452459
if (strcmp(PQresultErrorField(res, PG_DIAG_SQLSTATE), "22012") != 0)
@@ -463,6 +470,8 @@ test_pipeline_abort(PGconn *conn)
463470
}
464471
if (!goterror)
465472
pg_fatal("did not get division-by-zero error");
473+
if (gotrows != 3)
474+
pg_fatal("did not get three rows");
466475
/* the third pipeline sync */
467476
if ((res = PQgetResult(conn)) == NULL)
468477
pg_fatal("Unexpected NULL result: %s", PQerrorMessage(conn));
@@ -534,15 +543,17 @@ enum PipelineInsertStep
534543
static void
535544
test_pipelined_insert(PGconn *conn, int n_rows)
536545
{
537-
const char *insert_params[1];
538-
Oid insert_param_oids[1] = {INT4OID};
546+
Oid insert_param_oids[2] = {INT4OID, INT8OID};
547+
const char *insert_params[2];
539548
char insert_param_0[MAXINTLEN];
549+
char insert_param_1[MAXINT8LEN];
540550
enum PipelineInsertStep send_step = BI_BEGIN_TX,
541551
recv_step = BI_BEGIN_TX;
542552
int rows_to_send,
543553
rows_to_receive;
544554

545-
insert_params[0] = &insert_param_0[0];
555+
insert_params[0] = insert_param_0;
556+
insert_params[1] = insert_param_1;
546557

547558
rows_to_send = rows_to_receive = n_rows;
548559

@@ -585,8 +596,8 @@ test_pipelined_insert(PGconn *conn, int n_rows)
585596
}
586597

587598
Assert(send_step == BI_PREPARE);
588-
pg_debug("sending: %s\n", insert_sql);
589-
if (PQsendPrepare(conn, "my_insert", insert_sql, 1, insert_param_oids) != 1)
599+
pg_debug("sending: %s\n", insert_sql2);
600+
if (PQsendPrepare(conn, "my_insert", insert_sql2, 2, insert_param_oids) != 1)
590601
pg_fatal("dispatching PREPARE failed: %s", PQerrorMessage(conn));
591602
send_step = BI_INSERT_ROWS;
592603

@@ -712,10 +723,12 @@ test_pipelined_insert(PGconn *conn, int n_rows)
712723

713724
if (send_step == BI_INSERT_ROWS)
714725
{
715-
snprintf(&insert_param_0[0], MAXINTLEN, "%d", rows_to_send);
726+
snprintf(insert_param_0, MAXINTLEN, "%d", rows_to_send);
727+
snprintf(insert_param_1, MAXINT8LEN, "%lld",
728+
(long long) rows_to_send);
716729

717730
if (PQsendQueryPrepared(conn, "my_insert",
718-
1, insert_params, NULL, NULL, 0) == 1)
731+
2, insert_params, NULL, NULL, 0) == 1)
719732
{
720733
pg_debug("sent row %d\n", rows_to_send);
721734

src/test/modules/libpq_pipeline/t/001_libpq_pipeline.pl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
$node->init;
1212
$node->start;
1313

14-
my $numrows = 10000;
14+
my $numrows = 700;
1515
$ENV{PATH} = "$ENV{PATH}:" . getcwd();
1616

1717
my ($out, $err) = run_command([ 'libpq_pipeline', 'tests' ]);
1818
die "oops: $err" unless $err eq '';
1919
my @tests = split(/\s+/, $out);
2020

21+
mkdir "$TestLib::tmp_check/traces";
22+
2123
for my $testname (@tests)
2224
{
2325
my @extraargs = ();
@@ -26,7 +28,7 @@
2628
pipeline_abort transaction disallowed_in_pipeline)) > 0;
2729

2830
# For a bunch of tests, generate a libpq trace file too.
29-
my $traceout = "$TestLib::log_path/$testname.trace";
31+
my $traceout = "$TestLib::tmp_check/traces/$testname.trace";
3032
if ($cmptrace)
3133
{
3234
push @extraargs, "-t", $traceout;
@@ -52,7 +54,7 @@
5254
$result = slurp_file_eval($traceout);
5355
next unless $result ne "";
5456

55-
is($expected, $result, "$testname trace match");
57+
is($result, $expected, "$testname trace match");
5658
}
5759
}
5860

src/test/modules/libpq_pipeline/traces/pipeline_abort.trace

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ F 42 Query "DROP TABLE IF EXISTS pq_pipeline_demo"
55
B 123 NoticeResponse S "NOTICE" V "NOTICE" C "00000" M "table "pq_pipeline_demo" does not exist, skipping" F "SSSS" L "SSSS" R "SSSS" \x00
66
B 15 CommandComplete "DROP TABLE"
77
B 5 ReadyForQuery I
8-
F 83 Query "CREATE UNLOGGED TABLE pq_pipeline_demo(id serial primary key, itemno integer);"
8+
F 99 Query "CREATE UNLOGGED TABLE pq_pipeline_demo(id serial primary key, itemno integer,int8filler int8);"
99
B 17 CommandComplete "CREATE TABLE"
1010
B 5 ReadyForQuery I
11-
F 61 Parse "" "INSERT INTO pq_pipeline_demo(itemno) VALUES ($1);" 1 NNNN
11+
F 60 Parse "" "INSERT INTO pq_pipeline_demo(itemno) VALUES ($1)" 1 NNNN
1212
F 19 Bind "" "" 0 1 1 '1' 1 0
1313
F 6 Describe P ""
1414
F 9 Execute "" 0
1515
F 39 Parse "" "SELECT no_such_function($1)" 1 NNNN
1616
F 19 Bind "" "" 0 1 1 '1' 1 0
1717
F 6 Describe P ""
1818
F 9 Execute "" 0
19-
F 61 Parse "" "INSERT INTO pq_pipeline_demo(itemno) VALUES ($1);" 1 NNNN
19+
F 60 Parse "" "INSERT INTO pq_pipeline_demo(itemno) VALUES ($1)" 1 NNNN
2020
F 19 Bind "" "" 0 1 1 '2' 1 0
2121
F 6 Describe P ""
2222
F 9 Execute "" 0
2323
F 4 Sync
24-
F 61 Parse "" "INSERT INTO pq_pipeline_demo(itemno) VALUES ($1);" 1 NNNN
24+
F 60 Parse "" "INSERT INTO pq_pipeline_demo(itemno) VALUES ($1)" 1 NNNN
2525
F 19 Bind "" "" 0 1 1 '3' 1 0
2626
F 6 Describe P ""
2727
F 9 Execute "" 0

0 commit comments

Comments
 (0)