jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1225003?usp=email )

Change subject: tests: Fix flaky test_watch by using polling instead of fixed 
sleep
......................................................................

tests: Fix flaky test_watch by using polling instead of fixed sleep

The test_watch test in TestPageUserAction was failing intermittently because
it relied on a fixed 15-second sleep to wait for a watchlist update (unwatch)
to propagate. If the server or test environment was slow, the page would
still appear in the watchlist after the sleep, causing the assertion
assertNotIn to fail.

This patch replaces the fixed time.sleep(15) with a retry loop that polls
watched_pages every second for up to 30 seconds. This ensures:
* The test passes as soon as the change propagates (potentially faster).
* The test is robust against delays up to 30 seconds, reducing flakiness.

Bug: T414166
Change-Id: I3bc6a6d7a819e2f8548b49b1e6badd67b823865f
---
M AUTHORS.rst
M tests/page_tests.py
2 files changed, 10 insertions(+), 2 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/AUTHORS.rst b/AUTHORS.rst
index 04188ba..135011d 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -302,6 +302,7 @@


     Sanjai Siddharthan
+    Sarthak Singh
     Serio Santoro
     Scot Wilcoxon
     Shardul C
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 1b1791e..6de059a 100755
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -1105,8 +1105,15 @@
         rv = userpage.watch(expiry='5 seconds')
         self.assertTrue(rv)
         self.assertIn(userpage, userpage.site.watched_pages(**wp_params))
-        time.sleep(15)
-        self.assertNotIn(userpage, userpage.site.watched_pages(**wp_params))
+        # Wait for the expiry to pass
+        time.sleep(5)
+        # Retry check for unwatch to propagate for up to 30 seconds
+        for _ in range(30):
+            time.sleep(1)
+            if userpage not in userpage.site.watched_pages(**wp_params):
+                break
+        else:
+            self.fail('unwatch failed')


 class TestPageDelete(TestCase):

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1225003?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I3bc6a6d7a819e2f8548b49b1e6badd67b823865f
Gerrit-Change-Number: 1225003
Gerrit-PatchSet: 7
Gerrit-Owner: SarthakSingh2904 <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to