From 7f706b5b4b166e4ac60ffc3d2e59d0c094886882 Mon Sep 17 00:00:00 2001
From: Melanie Plageman <melanieplageman@gmail.com>
Date: Wed, 12 Aug 2026 12:29:54 -0400
Subject: [PATCH v16 15/21] Add COPY FROM write combining test

COPY into an unlogged table uses BAS_BULKWRITE and now combines its
writes via the centered eager-clean path used by client backends.

Note that BAS_BULKREAD uses the same eager clean path but is more
expensive to test due to requiring a table 4x shared buffers and
avoiding interactions with readahead, so we haven't included a test for
that.
---
 .../modules/test_aio/t/005_write_combining.pl | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/src/test/modules/test_aio/t/005_write_combining.pl b/src/test/modules/test_aio/t/005_write_combining.pl
index ed41651e87c..2ccf10cf2c0 100644
--- a/src/test/modules/test_aio/t/005_write_combining.pl
+++ b/src/test/modules/test_aio/t/005_write_combining.pl
@@ -29,6 +29,7 @@ my $block_size = $node->safe_psql('postgres',
 test_checkpointer_combines_writes($node, $block_size);
 test_regular_backend_combines_writes($node, $block_size);
 test_eager_clean_combines_writes($node, $block_size);
+test_copy_from_combines_writes($node, $block_size);
 
 $node->stop();
 
@@ -186,6 +187,33 @@ sub allocate_until_blocks_clean
 	$psql->query_safe('SELECT pg_stat_force_next_flush()');
 }
 
+sub test_copy_from_combines_writes
+{
+	my ($node, $block_size) = @_;
+
+	$node->safe_psql(
+		'postgres', qq(
+	CREATE UNLOGGED TABLE wc_copy (id int, payload text);
+	CHECKPOINT;
+	));
+
+	# Feed the rows to "COPY ... FROM STDIN" inline on psql's stdin.
+	my $rows = 200000;
+	my $payload = '0' x 200;
+	my $copy_data = '';
+	$copy_data .= "$_\t$payload\n" for (1 .. $rows);
+
+	$node->safe_psql('postgres', "SELECT pg_stat_reset_shared('io')");
+	$node->safe_psql('postgres',
+		"COPY wc_copy FROM STDIN;\n" . $copy_data . "\\.\n");
+	$node->safe_psql('postgres', 'SELECT pg_stat_force_next_flush()');
+
+	assert_combined_writes($node, 'copy from', 'client backend', 'bulkwrite',
+		$block_size);
+	is($node->safe_psql('postgres', "SELECT count(*) FROM wc_copy"),
+		$rows, 'copy from inserted rows');
+}
+
 sub test_checkpointer_combines_writes
 {
 	my ($node, $block_size) = @_;
-- 
2.47.3

