diff --git a/src/test/recovery/t/001_stream_rep.pl b/src/test/recovery/t/001_stream_rep.pl
index 266d27c..b397e3e 100644
--- a/src/test/recovery/t/001_stream_rep.pl
+++ b/src/test/recovery/t/001_stream_rep.pl
@@ -196,7 +196,7 @@ $node_standby_2->safe_psql('postgres',
 	'ALTER SYSTEM SET hot_standby_feedback = on;');
 $node_standby_2->reload;
 replay_check();
-sleep(2);
+$node_master->poll_query_until('postgres', q[SELECT xmin IS NOT NULL AND catalog_xmin IS NULL from pg_replication_slots WHERE slot_name = '] . $slotname_1 . q[']);
 
 ($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1);
 isnt($xmin, '', 'non-cascaded slot xmin non-null with hs feedback');
@@ -236,7 +236,7 @@ $node_standby_2->safe_psql('postgres',
 	'ALTER SYSTEM SET hot_standby_feedback = off;');
 $node_standby_2->reload;
 replay_check();
-sleep(2);
+$node_master->poll_query_until('postgres', q[SELECT xmin IS NULL AND catalog_xmin IS NULL from pg_replication_slots WHERE slot_name = '] . $slotname_1 . q[']);
 
 ($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1);
 is($xmin, '', 'non-cascaded slot xmin null with hs feedback reset');
@@ -265,6 +265,8 @@ isnt($xmin, '', 'cascaded slot xmin non-null with postgres shut down');
 # Xmin from a previous run should be cleared on startup.
 $node_standby_2->start;
 
+$node_standby_1->poll_query_until('postgres', q[SELECT xmin IS NULL from pg_replication_slots WHERE slot_name = '] . $slotname_2 . q[']);
+
 ($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
 is($xmin, '',
 	'cascaded slot xmin reset after startup with hs feedback reset');
