Rework handling of pending data for backend statistics
[pgsql.git] / src / test / modules / libpq_pipeline / t / 001_libpq_pipeline.pl
blobe301c37826459c54ba4cb1b924e638ba6b46a2c9
2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
4 use strict;
5 use warnings FATAL => 'all';
7 use PostgreSQL::Test::Cluster;
8 use PostgreSQL::Test::Utils;
9 use Test::More;
11 # Use Test::Differences if installed, and select unified diff output.
12 BEGIN
14 eval {
15 require Test::Differences;
16 Test::Differences->import;
17 unified_diff();
20 # No dice -- fall back to 'is'
21 *eq_or_diff = \&is if $@;
24 my $node = PostgreSQL::Test::Cluster->new('main');
25 $node->init;
26 $node->start;
28 my $numrows = 700;
30 my ($out, $err) = run_command([ 'libpq_pipeline', 'tests' ]);
31 die "oops: $err" unless $err eq '';
32 my @tests = split(/\s+/, $out);
34 mkdir "$PostgreSQL::Test::Utils::tmp_check/traces";
36 for my $testname (@tests)
38 my @extraargs = ('-r', $numrows);
39 my $cmptrace = grep(/^$testname$/,
40 qw(simple_pipeline nosync multi_pipelines prepared singlerow
41 pipeline_abort pipeline_idle transaction
42 disallowed_in_pipeline)) > 0;
44 # For a bunch of tests, generate a libpq trace file too.
45 my $traceout =
46 "$PostgreSQL::Test::Utils::tmp_check/traces/$testname.trace";
47 if ($cmptrace)
49 push @extraargs, "-t", $traceout;
52 # Execute the test
53 $node->command_ok(
55 'libpq_pipeline', @extraargs,
56 $testname, $node->connstr('postgres')
58 "libpq_pipeline $testname");
60 # Compare the trace, if requested
61 if ($cmptrace)
63 my $expected;
64 my $result;
66 $expected = slurp_file_eval("traces/$testname.trace");
67 next unless $expected ne "";
68 $result = slurp_file_eval($traceout);
69 next unless $result ne "";
71 eq_or_diff($result, $expected, "$testname trace match");
75 $node->stop('fast');
77 done_testing();
79 sub slurp_file_eval
81 my $filepath = shift;
82 my $contents;
84 eval { $contents = slurp_file($filepath); };
85 if ($@)
87 fail "reading $filepath: $@";
88 return "";
90 return $contents;