From 52c0430c1a901c2628b26a4dd68786aebee966e6 Mon Sep 17 00:00:00 2001
From: Petr Jelinek <pjmodos@pjmodos.net>
Date: Mon, 24 Apr 2017 07:14:59 +0200
Subject: [PATCH 1/3] Add check-walsender-sql make target

Checks the SQL over walsender interface by running the standard set of
regression tests against it.

This also adds new option to pg_regress called --replication-connection
which makes pg_regress connect with replication=database connection
option.

New alternative output for largeobject test has been added as the
replication connection does not support fastpath function calls.
---
 GNUmakefile.in                         | 2 +-
 src/test/regress/GNUmakefile           | 3 +++
 src/test/regress/expected/horology.out | 2 +-
 src/test/regress/pg_regress.c          | 6 ++++++
 src/test/regress/pg_regress.h          | 1 +
 src/test/regress/pg_regress_main.c     | 3 ++-
 src/test/regress/sql/horology.sql      | 2 +-
 7 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/GNUmakefile.in b/GNUmakefile.in
index dc76a5d..9b68a2e 100644
--- a/GNUmakefile.in
+++ b/GNUmakefile.in
@@ -63,7 +63,7 @@ distclean maintainer-clean:
 	@rm -rf autom4te.cache/
 	rm -f config.cache config.log config.status GNUmakefile
 
-check check-tests installcheck installcheck-parallel installcheck-tests:
+check check-tests check-walsender-sql installcheck installcheck-parallel installcheck-tests:
 	$(MAKE) -C src/test/regress $@
 
 $(call recurse,check-world,src/test src/pl src/interfaces/ecpg contrib src/bin,check)
diff --git a/src/test/regress/GNUmakefile b/src/test/regress/GNUmakefile
index b923ea1..7739018 100644
--- a/src/test/regress/GNUmakefile
+++ b/src/test/regress/GNUmakefile
@@ -132,6 +132,9 @@ check: all tablespace-setup
 check-tests: all tablespace-setup
 	$(pg_regress_check) $(REGRESS_OPTS) $(MAXCONNOPT) $(TESTS) $(EXTRA_TESTS)
 
+check-walsender-sql: temp-install all tablespace-setup
+	$(pg_regress_check) $(REGRESS_OPTS) --schedule=$(srcdir)/serial_schedule --replication-connection $(MAXCONNOPT) $(EXTRA_TESTS)
+
 installcheck: all tablespace-setup
 	$(pg_regress_installcheck) $(REGRESS_OPTS) --schedule=$(srcdir)/serial_schedule $(EXTRA_TESTS)
 
diff --git a/src/test/regress/expected/horology.out b/src/test/regress/expected/horology.out
index f9d12e0..3848482 100644
--- a/src/test/regress/expected/horology.out
+++ b/src/test/regress/expected/horology.out
@@ -3109,7 +3109,7 @@ ERROR:  date/time field value out of range: "2016 367"
 --
 SET TIME ZONE 'America/New_York';
 SET TIME ZONE '-1.5';
-SHOW TIME ZONE;
+SHOW TIMEZONE;
     TimeZone    
 ----------------
  <-01:30>+01:30
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index b685aeb..a1831c5 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -75,6 +75,7 @@ char	   *inputdir = ".";
 char	   *outputdir = ".";
 char	   *bindir = PGBINDIR;
 char	   *launcher = NULL;
+bool		replication_connection = false;
 static _stringlist *loadlanguage = NULL;
 static _stringlist *loadextension = NULL;
 static int	max_connections = 0;
@@ -2000,6 +2001,7 @@ help(void)
 	printf(_("  --max-connections=N       maximum number of concurrent connections\n"));
 	printf(_("                            (default is 0, meaning unlimited)\n"));
 	printf(_("  --outputdir=DIR           place output files in DIR (default \".\")\n"));
+	printf(_("  --replication-connection  use replication connection to run tests\n"));
 	printf(_("  --schedule=FILE           use test ordering schedule from FILE\n"));
 	printf(_("                            (can be used multiple times to concatenate)\n"));
 	printf(_("  --temp-instance=DIR       create a temporary instance in DIR\n"));
@@ -2048,6 +2050,7 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
 		{"launcher", required_argument, NULL, 21},
 		{"load-extension", required_argument, NULL, 22},
 		{"config-auth", required_argument, NULL, 24},
+		{"replication-connection", no_argument, NULL, 25},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -2161,6 +2164,9 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
 			case 24:
 				config_auth_datadir = pg_strdup(optarg);
 				break;
+			case 25:
+				replication_connection = true;
+				break;
 			default:
 				/* getopt_long already emitted a complaint */
 				fprintf(stderr, _("\nTry \"%s -h\" for more information.\n"),
diff --git a/src/test/regress/pg_regress.h b/src/test/regress/pg_regress.h
index f7745b1..8d552e0 100644
--- a/src/test/regress/pg_regress.h
+++ b/src/test/regress/pg_regress.h
@@ -41,6 +41,7 @@ extern bool debug;
 extern char *inputdir;
 extern char *outputdir;
 extern char *launcher;
+extern bool replication_connection;
 
 extern const char *basic_diff_opts;
 extern const char *pretty_diff_opts;
diff --git a/src/test/regress/pg_regress_main.c b/src/test/regress/pg_regress_main.c
index 298ed75..3b6ba35 100644
--- a/src/test/regress/pg_regress_main.c
+++ b/src/test/regress/pg_regress_main.c
@@ -70,10 +70,11 @@ psql_start_test(const char *testname,
 	putenv(appnameenv);
 
 	snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
-			 "\"%s%spsql\" -X -a -q -d \"%s\" < \"%s\" > \"%s\" 2>&1",
+			 "\"%s%spsql\" -X -a -q -d \"dbname=%s%s\" < \"%s\" > \"%s\" 2>&1",
 			 bindir ? bindir : "",
 			 bindir ? "/" : "",
 			 dblist->str,
+			 replication_connection ? " replication=database" : "",
 			 infile,
 			 outfile);
 
diff --git a/src/test/regress/sql/horology.sql b/src/test/regress/sql/horology.sql
index a7bc9dc..11e8e03 100644
--- a/src/test/regress/sql/horology.sql
+++ b/src/test/regress/sql/horology.sql
@@ -517,7 +517,7 @@ SELECT to_date('2016 367', 'YYYY DDD');
 SET TIME ZONE 'America/New_York';
 SET TIME ZONE '-1.5';
 
-SHOW TIME ZONE;
+SHOW TIMEZONE;
 
 SELECT '2012-12-12 12:00'::timestamptz;
 SELECT '2012-12-12 12:00 America/New_York'::timestamptz;
-- 
2.7.4

