From 4a079bfee90a41efc5cc12141c32e438c4754ef2 Mon Sep 17 00:00:00 2001
From: Shlok Kyal <shlok.kyal@gmail.com>
Date: Tue, 26 Dec 2023 17:02:59 +0530
Subject: [PATCH v1] Fix Windows Intermittent Failure

When tests are run on Windows using meson, some tests fails
intermittently. With this fix those intermittent failures
are resolved.
---
 contrib/oid2name/oid2name.c                   | 2 ++
 contrib/vacuumlo/vacuumlo.c                   | 2 ++
 src/backend/main/main.c                       | 2 ++
 src/bin/initdb/initdb.c                       | 2 ++
 src/bin/pg_archivecleanup/pg_archivecleanup.c | 2 ++
 src/bin/pg_basebackup/pg_basebackup.c         | 2 ++
 src/bin/pg_basebackup/pg_receivewal.c         | 2 ++
 src/bin/pg_basebackup/pg_recvlogical.c        | 2 ++
 src/bin/pg_checksums/pg_checksums.c           | 2 ++
 src/bin/pg_config/pg_config.c                 | 1 +
 src/bin/pg_controldata/pg_controldata.c       | 2 ++
 src/bin/pg_ctl/pg_ctl.c                       | 2 ++
 src/bin/pg_dump/pg_dump.c                     | 2 ++
 src/bin/pg_dump/pg_dumpall.c                  | 2 ++
 src/bin/pg_dump/pg_restore.c                  | 2 ++
 src/bin/pg_resetwal/pg_resetwal.c             | 2 ++
 src/bin/pg_rewind/pg_rewind.c                 | 2 ++
 src/bin/pg_test_fsync/pg_test_fsync.c         | 2 ++
 src/bin/pg_test_timing/pg_test_timing.c       | 2 ++
 src/bin/pg_upgrade/option.c                   | 2 ++
 src/bin/pg_verifybackup/pg_verifybackup.c     | 2 ++
 src/bin/pg_waldump/pg_waldump.c               | 2 ++
 src/bin/pgbench/pgbench.c                     | 2 ++
 src/bin/psql/startup.c                        | 3 +++
 src/fe_utils/option_utils.c                   | 2 ++
 src/interfaces/ecpg/preproc/ecpg.c            | 2 ++
 26 files changed, 52 insertions(+)

diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c
index e8c1e2c97b..64c5e2c8ae 100644
--- a/contrib/oid2name/oid2name.c
+++ b/contrib/oid2name/oid2name.c
@@ -106,11 +106,13 @@ get_opts(int argc, char **argv, struct options *my_opts)
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			help(progname);
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("oid2name (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c
index e02d84cc96..29eaa38e10 100644
--- a/contrib/vacuumlo/vacuumlo.c
+++ b/contrib/vacuumlo/vacuumlo.c
@@ -476,11 +476,13 @@ main(int argc, char **argv)
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage(progname);
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("vacuumlo (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/backend/main/main.c b/src/backend/main/main.c
index ed11e8be7f..21bc7c1a40 100644
--- a/src/backend/main/main.c
+++ b/src/backend/main/main.c
@@ -146,11 +146,13 @@ main(int argc, char *argv[])
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			help(progname);
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			fputs(PG_BACKEND_VERSIONSTR, stdout);
+			fflush(stdout);
 			exit(0);
 		}
 
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index e68b40d2b5..750b1ee05d 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -3140,11 +3140,13 @@ main(int argc, char *argv[])
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage(progname);
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("initdb (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_archivecleanup/pg_archivecleanup.c b/src/bin/pg_archivecleanup/pg_archivecleanup.c
index 2c3b301f3b..8122f033ab 100644
--- a/src/bin/pg_archivecleanup/pg_archivecleanup.c
+++ b/src/bin/pg_archivecleanup/pg_archivecleanup.c
@@ -303,11 +303,13 @@ main(int argc, char **argv)
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage();
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_archivecleanup (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 5795b91261..c8cebcedea 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -2404,12 +2404,14 @@ main(int argc, char **argv)
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage();
+			fflush(stdout);
 			exit(0);
 		}
 		else if (strcmp(argv[1], "-V") == 0
 				 || strcmp(argv[1], "--version") == 0)
 		{
 			puts("pg_basebackup (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index d0a4079d50..ce0d5a168d 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -667,12 +667,14 @@ main(int argc, char **argv)
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage();
+			fflush(stdout);
 			exit(0);
 		}
 		else if (strcmp(argv[1], "-V") == 0 ||
 				 strcmp(argv[1], "--version") == 0)
 		{
 			puts("pg_receivewal (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
index 9fe4ac8126..2eb00c9a24 100644
--- a/src/bin/pg_basebackup/pg_recvlogical.c
+++ b/src/bin/pg_basebackup/pg_recvlogical.c
@@ -736,12 +736,14 @@ main(int argc, char **argv)
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage();
+			fflush(stdout);
 			exit(0);
 		}
 		else if (strcmp(argv[1], "-V") == 0 ||
 				 strcmp(argv[1], "--version") == 0)
 		{
 			puts("pg_recvlogical (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c
index 19c083be17..46a0b1d6ff 100644
--- a/src/bin/pg_checksums/pg_checksums.c
+++ b/src/bin/pg_checksums/pg_checksums.c
@@ -455,11 +455,13 @@ main(int argc, char *argv[])
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage();
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_checksums (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_config/pg_config.c b/src/bin/pg_config/pg_config.c
index 70cab817dd..588faf67a9 100644
--- a/src/bin/pg_config/pg_config.c
+++ b/src/bin/pg_config/pg_config.c
@@ -145,6 +145,7 @@ main(int argc, char **argv)
 		if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0)
 		{
 			help();
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 93e0837947..891bf10521 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -116,11 +116,13 @@ main(int argc, char *argv[])
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage(progname);
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_controldata (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 3b145bd838..225537c415 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -2231,11 +2231,13 @@ main(int argc, char **argv)
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			do_help();
+			fflush(stdout);
 			exit(0);
 		}
 		else if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_ctl (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 8c0b5486b9..6773726a64 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -457,11 +457,13 @@ main(int argc, char **argv)
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			help(progname);
+			fflush(stdout);
 			exit_nicely(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_dump (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit_nicely(0);
 		}
 	}
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 92389353a4..fefe02bb2e 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -212,11 +212,13 @@ main(int argc, char *argv[])
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			help();
+			fflush(stdout);
 			exit_nicely(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_dumpall (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit_nicely(0);
 		}
 	}
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index c3beacdec1..e9b5e478d0 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -145,11 +145,13 @@ main(int argc, char **argv)
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage(progname);
+			fflush(stdout);
 			exit_nicely(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_restore (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit_nicely(0);
 		}
 	}
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index 5407f51a4e..3f00bdca6e 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -128,11 +128,13 @@ main(int argc, char *argv[])
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage();
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_resetwal (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index f55ef4f2f8..87eb46b3c6 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -164,11 +164,13 @@ main(int argc, char **argv)
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage(progname);
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_rewind (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_test_fsync/pg_test_fsync.c b/src/bin/pg_test_fsync/pg_test_fsync.c
index 54bc0767f1..2805f6befd 100644
--- a/src/bin/pg_test_fsync/pg_test_fsync.c
+++ b/src/bin/pg_test_fsync/pg_test_fsync.c
@@ -163,11 +163,13 @@ handle_args(int argc, char *argv[])
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			printf(_("Usage: %s [-f FILENAME] [-s SECS-PER-TEST]\n"), progname);
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_test_fsync (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_test_timing/pg_test_timing.c b/src/bin/pg_test_timing/pg_test_timing.c
index c29d6f8762..33e53bb7ab 100644
--- a/src/bin/pg_test_timing/pg_test_timing.c
+++ b/src/bin/pg_test_timing/pg_test_timing.c
@@ -57,11 +57,13 @@ handle_args(int argc, char *argv[])
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			printf(_("Usage: %s [-d DURATION]\n"), progname);
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_test_timing (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c
index b9d900d0db..1a3e59fed9 100644
--- a/src/bin/pg_upgrade/option.c
+++ b/src/bin/pg_upgrade/option.c
@@ -90,11 +90,13 @@ parseCommandLine(int argc, char *argv[])
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage();
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_upgrade (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index 88081f66f7..12d79976b3 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -203,11 +203,13 @@ main(int argc, char **argv)
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage();
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_verifybackup (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c
index a3535bdfa9..ab667e8c29 100644
--- a/src/bin/pg_waldump/pg_waldump.c
+++ b/src/bin/pg_waldump/pg_waldump.c
@@ -840,11 +840,13 @@ main(int argc, char **argv)
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage();
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pg_waldump (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 2e1650d0ad..96c0e081f0 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -6684,11 +6684,13 @@ main(int argc, char **argv)
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			usage();
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			puts("pgbench (PostgreSQL) " PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 78526eb9da..3b543228fa 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -140,11 +140,13 @@ main(int argc, char *argv[])
 		if ((strcmp(argv[1], "-?") == 0) || (argc == 2 && (strcmp(argv[1], "--help") == 0)))
 		{
 			usage(NOPAGER);
+			fflush(stdout);
 			exit(EXIT_SUCCESS);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			showVersion();
+			fflush(stdout);
 			exit(EXIT_SUCCESS);
 		}
 	}
@@ -839,6 +841,7 @@ static void
 showVersion(void)
 {
 	puts("psql (PostgreSQL) " PG_VERSION);
+	fflush(stdout);
 }
 
 
diff --git a/src/fe_utils/option_utils.c b/src/fe_utils/option_utils.c
index d2a3adeb4b..983804c935 100644
--- a/src/fe_utils/option_utils.c
+++ b/src/fe_utils/option_utils.c
@@ -29,11 +29,13 @@ handle_help_version_opts(int argc, char *argv[],
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			hlp(get_progname(argv[0]));
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			printf("%s (PostgreSQL) " PG_VERSION "\n", fixed_progname);
+			fflush(stdout);
 			exit(0);
 		}
 	}
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index 16cfc49e5e..54099b02eb 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -147,11 +147,13 @@ main(int argc, char *const argv[])
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
 			help(progname);
+			fflush(stdout);
 			exit(0);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
 			printf("ecpg (PostgreSQL) %s\n", PG_VERSION);
+			fflush(stdout);
 			exit(0);
 		}
 	}
-- 
2.41.0.windows.3

