From 76148b67c27d30ba0eb5508407f7182fbf3fa1fa Mon Sep 17 00:00:00 2001
From: Melanie Plageman <melanieplageman@gmail.com>
Date: Wed, 12 Aug 2026 12:29:54 -0400
Subject: [PATCH v17 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 1/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 fbebe822e0e..8feab88806b 100644
--- a/src/test/modules/test_aio/t/005_write_combining.pl
+++ b/src/test/modules/test_aio/t/005_write_combining.pl
@@ -33,6 +33,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();
 
@@ -208,6 +209,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
+		  . "\\.\nSELECT pg_stat_force_next_flush();\n");
+
+	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.43.0

