Page MenuHomePhabricator

TestSiteGenerators.test_unconnected occasionally fails
Closed, ResolvedPublic

Description

https://travis-ci.org/wikimedia/pywikibot-core/jobs/224622765

_____________________ TestSiteGenerators.test_unconnected ______________________

self = <tests.site_tests.TestSiteGenerators testMethod=test_unconnected>

    def test_unconnected(self):

        """Test that the ItemPage returned raises NoPage."""

        if not self.site.data_repository():

            raise unittest.SkipTest('Site is not using a Wikibase repository')

        if self.site.hostname() == 'test.wikipedia.org':

            raise unittest.SkipTest('test.wikipedia is misconfigured; T85358')

        cnt = 0

        start_time = datetime.now() - timedelta(minutes=5)

        # Pages which have been connected recently may still be reported as

        # unconnected. So try on an version that is a few minutes older if the

        # tested site appears as a sitelink.

        for page in self.site.unconnected_pages(total=5):

            try:

                item = pywikibot.ItemPage.fromPage(page)

            except pywikibot.NoPage:

                pass

            else:

                revisions = list(item.revisions(total=1, starttime=start_time,

                                                content=True))

                if revisions:

                    sitelinks = json.loads(revisions[0].text)['sitelinks']

                    self.assertNotIn(

                        self.site.dbName(), sitelinks,

                        'Page "{0}" is connected to a Wikibase '

>                       'repository'.format(page.title()))

E                   AssertionError: 'enwiki' unexpectedly found in {'enwiki': {'title': 'Ravinder K. Jain', 'badges': [], 'site': 'enwiki'}} : Page "Ravinder K. Jain" is connected to a Wikibase repository

There is a bot that creates items for newly created pages of English Wikipedia. See:

The test already tries to ignore any item revision that is at least 5 minutes old, but apparently there is a flaw in the logic or maybe the 5 minute buffer is not enough, or both.

Event Timeline

I think the test should use datetime.utcnow instead of datetime.now because MediaWiki expects UTC timestamps. I'm also going to propose to increase the timedelta from 5 to 10 minutes.

Change 349736 had a related patch set uploaded (by Dalba):
[pywikibot/core@master] site_tests.py: Use datetime.utcnow() instead of datetime.now()

https://gerrit.wikimedia.org/r/349736

After running the amended test a few times, it seems that even 15 minutes is not enough, i.e. a page can appear in unconnected_pages even 15 minutes after being connected to an item. Therefore I've increase the timedelta to 30 minutes in the patch above .

Change 349736 merged by jenkins-bot:
[pywikibot/core@master] site_tests.py: Use datetime.utcnow() instead of datetime.now()

https://gerrit.wikimedia.org/r/349736

Thanks to Xqt for reviewing.

This is an odd one. ويكي الكتب:كيويكس has been connected to wikidata almost a day ago but still appears as unconnected on the local site.

Change 378237 had a related patch set uploaded (by Dalba; owner: Dalba):
[pywikibot/core@master] site_tests: Tolerate UnconnectedPages that have been connected in the past 24h

https://gerrit.wikimedia.org/r/378237

Change 378237 abandoned by Dalba:
site_tests: Tolerate UnconnectedPages that have been connected in the past 24h

Reason:
A test failed after 23 hours.[1]
This change not going to fix the issue.

[1]: https://travis-ci.org/wikimedia/pywikibot-core/jobs/275803332

https://gerrit.wikimedia.org/r/378237

Dalba triaged this task as High priority.Sep 16 2017, 3:01 AM

This test is the sole reason that the past 4 builds have failed: 4318, 4319, 4320, 4321

Change 378377 had a related patch set uploaded (by Dalba; owner: Dalba):
[pywikibot/core@master] Fix test_unconnected and test_unconnected_with_repo

https://gerrit.wikimedia.org/r/378377

Change 378377 merged by jenkins-bot:
[pywikibot/core@master] Fix test_unconnected and test_unconnected_with_repo

https://gerrit.wikimedia.org/r/378377