From 82cdee92c3726a7f248849a310ec3f392ba02384 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Date: Fri, 4 Mar 2022 11:03:12 +0900
Subject: [PATCH] Wait for process termination during isolation tests

slot_creation_error.spec and temp-schema-cleanup.spec used
pg_terminate_backend() without specifying timeout, thus there may be a
case of proceeding to the next step before the process actually
terminates then false failure.

Supply timeout to pg_terminate_backend() so that it waits for process
termination to avoid that failure mode.
---
 contrib/test_decoding/expected/slot_creation_error.out | 2 +-
 contrib/test_decoding/specs/slot_creation_error.spec   | 2 +-
 src/test/isolation/expected/temp-schema-cleanup.out    | 2 +-
 src/test/isolation/specs/temp-schema-cleanup.spec      | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/test_decoding/expected/slot_creation_error.out b/contrib/test_decoding/expected/slot_creation_error.out
index 043bdae0a2..3707482cb8 100644
--- a/contrib/test_decoding/expected/slot_creation_error.out
+++ b/contrib/test_decoding/expected/slot_creation_error.out
@@ -87,7 +87,7 @@ step s2_init:
     SELECT 'init' FROM pg_create_logical_replication_slot('slot_creation_error', 'test_decoding');
  <waiting ...>
 step s1_terminate_s2: 
-    SELECT pg_terminate_backend(pid)
+    SELECT pg_terminate_backend(pid, 180000)
     FROM pg_stat_activity
     WHERE application_name = 'isolation/slot_creation_error/s2';
 
diff --git a/contrib/test_decoding/specs/slot_creation_error.spec b/contrib/test_decoding/specs/slot_creation_error.spec
index 6816696b9d..32161b9e7f 100644
--- a/contrib/test_decoding/specs/slot_creation_error.spec
+++ b/contrib/test_decoding/specs/slot_creation_error.spec
@@ -13,7 +13,7 @@ step s1_cancel_s2 {
 }
 
 step s1_terminate_s2 {
-    SELECT pg_terminate_backend(pid)
+    SELECT pg_terminate_backend(pid, 180000)
     FROM pg_stat_activity
     WHERE application_name = 'isolation/slot_creation_error/s2';
 }
diff --git a/src/test/isolation/expected/temp-schema-cleanup.out b/src/test/isolation/expected/temp-schema-cleanup.out
index 35b91d9e45..cb4302739a 100644
--- a/src/test/isolation/expected/temp-schema-cleanup.out
+++ b/src/test/isolation/expected/temp-schema-cleanup.out
@@ -83,7 +83,7 @@ exec
 (1 row)
 
 step s1_exit: 
-    SELECT pg_terminate_backend(pg_backend_pid());
+    SELECT pg_terminate_backend(pg_backend_pid(), 180000);
 
 FATAL:  terminating connection due to administrator command
 server closed the connection unexpectedly
diff --git a/src/test/isolation/specs/temp-schema-cleanup.spec b/src/test/isolation/specs/temp-schema-cleanup.spec
index a9417b7e90..f0d3928996 100644
--- a/src/test/isolation/specs/temp-schema-cleanup.spec
+++ b/src/test/isolation/specs/temp-schema-cleanup.spec
@@ -47,7 +47,7 @@ step s1_discard_temp {
 }
 
 step s1_exit {
-    SELECT pg_terminate_backend(pg_backend_pid());
+    SELECT pg_terminate_backend(pg_backend_pid(), 180000);
 }
 
 
-- 
2.27.0

