Fix some libpq_pipeline test problems
authorAlvaro Herrera <[email protected]>
Wed, 31 Mar 2021 18:13:42 +0000 (15:13 -0300)
committerAlvaro Herrera <[email protected]>
Wed, 31 Mar 2021 18:14:23 +0000 (15:14 -0300)
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.

src/test/modules/libpq_pipeline/libpq_pipeline.c
src/test/modules/libpq_pipeline/t/001_libpq_pipeline.pl
src/test/modules/libpq_pipeline/traces/pipeline_abort.trace

index 1979f178af7dd06d5bbcaca04b770116c2ea775f..92af8698d69b9a077f2f1f00ad99fdce87a11769 100644 (file)
@@ -45,12 +45,16 @@ char       *tracefile = NULL;   /* path to PQtrace() file */
 static const char *const drop_table_sql =
 "DROP TABLE IF EXISTS pq_pipeline_demo";
 static const char *const create_table_sql =
-"CREATE UNLOGGED TABLE pq_pipeline_demo(id serial primary key, itemno integer);";
+"CREATE UNLOGGED TABLE pq_pipeline_demo(id serial primary key, itemno integer,"
+"int8filler int8);";
 static const char *const insert_sql =
-"INSERT INTO pq_pipeline_demo(itemno) VALUES ($1);";
+"INSERT INTO pq_pipeline_demo(itemno) VALUES ($1)";
+static const char *const insert_sql2 =
+"INSERT INTO pq_pipeline_demo(itemno,int8filler) VALUES ($1, $2)";
 
-/* max char length of an int32, plus sign and null terminator */
+/* max char length of an int32/64, plus sign and null terminator */
 #define MAXINTLEN 12
+#define MAXINT8LEN 20
 
 static void
 exit_nicely(PGconn *conn)
@@ -243,6 +247,7 @@ test_pipeline_abort(PGconn *conn)
    const char *dummy_params[1] = {"1"};
    Oid         dummy_param_oids[1] = {INT4OID};
    int         i;
+   int         gotrows;
    bool        goterror;
 
    fprintf(stderr, "aborted pipeline... ");
@@ -441,12 +446,14 @@ test_pipeline_abort(PGconn *conn)
        pg_fatal("pipeline sync failed: %s", PQerrorMessage(conn));
    PQsetSingleRowMode(conn);
    goterror = false;
+   gotrows = 0;
    while ((res = PQgetResult(conn)) != NULL)
    {
        switch (PQresultStatus(res))
        {
            case PGRES_SINGLE_TUPLE:
                printf("got row: %s\n", PQgetvalue(res, 0, 0));
+               gotrows++;
                break;
            case PGRES_FATAL_ERROR:
                if (strcmp(PQresultErrorField(res, PG_DIAG_SQLSTATE), "22012") != 0)
@@ -463,6 +470,8 @@ test_pipeline_abort(PGconn *conn)
    }
    if (!goterror)
        pg_fatal("did not get division-by-zero error");
+   if (gotrows != 3)
+       pg_fatal("did not get three rows");
    /* the third pipeline sync */
    if ((res = PQgetResult(conn)) == NULL)
        pg_fatal("Unexpected NULL result: %s", PQerrorMessage(conn));
@@ -534,15 +543,17 @@ enum PipelineInsertStep
 static void
 test_pipelined_insert(PGconn *conn, int n_rows)
 {
-   const char *insert_params[1];
-   Oid         insert_param_oids[1] = {INT4OID};
+   Oid         insert_param_oids[2] = {INT4OID, INT8OID};
+   const char *insert_params[2];
    char        insert_param_0[MAXINTLEN];
+   char        insert_param_1[MAXINT8LEN];
    enum PipelineInsertStep send_step = BI_BEGIN_TX,
                recv_step = BI_BEGIN_TX;
    int         rows_to_send,
                rows_to_receive;
 
-   insert_params[0] = &insert_param_0[0];
+   insert_params[0] = insert_param_0;
+   insert_params[1] = insert_param_1;
 
    rows_to_send = rows_to_receive = n_rows;
 
@@ -585,8 +596,8 @@ test_pipelined_insert(PGconn *conn, int n_rows)
    }
 
    Assert(send_step == BI_PREPARE);
-   pg_debug("sending: %s\n", insert_sql);
-   if (PQsendPrepare(conn, "my_insert", insert_sql, 1, insert_param_oids) != 1)
+   pg_debug("sending: %s\n", insert_sql2);
+   if (PQsendPrepare(conn, "my_insert", insert_sql2, 2, insert_param_oids) != 1)
        pg_fatal("dispatching PREPARE failed: %s", PQerrorMessage(conn));
    send_step = BI_INSERT_ROWS;
 
@@ -712,10 +723,12 @@ test_pipelined_insert(PGconn *conn, int n_rows)
 
            if (send_step == BI_INSERT_ROWS)
            {
-               snprintf(&insert_param_0[0], MAXINTLEN, "%d", rows_to_send);
+               snprintf(insert_param_0, MAXINTLEN, "%d", rows_to_send);
+               snprintf(insert_param_1, MAXINT8LEN, "%lld",
+                        (long long) rows_to_send);
 
                if (PQsendQueryPrepared(conn, "my_insert",
-                                       1, insert_params, NULL, NULL, 0) == 1)
+                                       2, insert_params, NULL, NULL, 0) == 1)
                {
                    pg_debug("sent row %d\n", rows_to_send);
 
index f20a6a29bd7591261bc83ddfaa3b9ff91bf8604e..f8e39b58131d4157af72a796fec3c418537dc0ca 100644 (file)
@@ -11,13 +11,15 @@ my $node = get_new_node('main');
 $node->init;
 $node->start;
 
-my $numrows = 10000;
+my $numrows = 700;
 $ENV{PATH} = "$ENV{PATH}:" . getcwd();
 
 my ($out, $err) = run_command([ 'libpq_pipeline', 'tests' ]);
 die "oops: $err" unless $err eq '';
 my @tests = split(/\s+/, $out);
 
+mkdir "$TestLib::tmp_check/traces";
+
 for my $testname (@tests)
 {
    my @extraargs = ();
@@ -26,7 +28,7 @@ for my $testname (@tests)
          pipeline_abort transaction disallowed_in_pipeline)) > 0;
 
    # For a bunch of tests, generate a libpq trace file too.
-   my $traceout = "$TestLib::log_path/$testname.trace";
+   my $traceout = "$TestLib::tmp_check/traces/$testname.trace";
    if ($cmptrace)
    {
        push @extraargs, "-t", $traceout;
@@ -52,7 +54,7 @@ for my $testname (@tests)
        $result = slurp_file_eval($traceout);
        next unless $result ne "";
 
-       is($expected, $result, "$testname trace match");
+       is($result, $expected, "$testname trace match");
    }
 }
 
index 2967b70b754658e1b8c865b52e1c03a5b434ab3f..6aacca03bfa010e71bd9ab65c4c0d2543b9d66d5 100644 (file)
@@ -5,10 +5,10 @@ F 42  Query    "DROP TABLE IF EXISTS pq_pipeline_demo"
 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
 B  15  CommandComplete  "DROP TABLE"
 B  5   ReadyForQuery    I
-F  83  Query    "CREATE UNLOGGED TABLE pq_pipeline_demo(id serial primary key, itemno integer);"
+F  99  Query    "CREATE UNLOGGED TABLE pq_pipeline_demo(id serial primary key, itemno integer,int8filler int8);"
 B  17  CommandComplete  "CREATE TABLE"
 B  5   ReadyForQuery    I
-F  61  Parse    "" "INSERT INTO pq_pipeline_demo(itemno) VALUES ($1);" 1 NNNN
+F  60  Parse    "" "INSERT INTO pq_pipeline_demo(itemno) VALUES ($1)" 1 NNNN
 F  19  Bind     "" "" 0 1 1 '1' 1 0
 F  6   Describe     P ""
 F  9   Execute  "" 0
@@ -16,12 +16,12 @@ F   39  Parse    "" "SELECT no_such_function($1)" 1 NNNN
 F  19  Bind     "" "" 0 1 1 '1' 1 0
 F  6   Describe     P ""
 F  9   Execute  "" 0
-F  61  Parse    "" "INSERT INTO pq_pipeline_demo(itemno) VALUES ($1);" 1 NNNN
+F  60  Parse    "" "INSERT INTO pq_pipeline_demo(itemno) VALUES ($1)" 1 NNNN
 F  19  Bind     "" "" 0 1 1 '2' 1 0
 F  6   Describe     P ""
 F  9   Execute  "" 0
 F  4   Sync
-F  61  Parse    "" "INSERT INTO pq_pipeline_demo(itemno) VALUES ($1);" 1 NNNN
+F  60  Parse    "" "INSERT INTO pq_pipeline_demo(itemno) VALUES ($1)" 1 NNNN
 F  19  Bind     "" "" 0 1 1 '3' 1 0
 F  6   Describe     P ""
 F  9   Execute  "" 0