From f7c0e172c67c71602ed0f29f7e2a16eb18ef861a Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Mon, 17 Jun 2013 10:46:53 +0800 Subject: [PATCH] MDL-40207 simplepie: reduce false failures in unit tests The simplepie tests time out too quickly due to a low connect timeout, to fix this, I converted the unit tests to use a high timeout value. --- lib/tests/rsslib_test.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/tests/rsslib_test.php b/lib/tests/rsslib_test.php index 8e9d1a3278e..722522050c9 100644 --- a/lib/tests/rsslib_test.php +++ b/lib/tests/rsslib_test.php @@ -43,14 +43,18 @@ class moodlesimplepie_testcase extends basic_testcase { const INVALIDURL = 'http://download.moodle.org/unittest/rsstest-which-doesnt-exist.xml'; # This tinyurl redirects to th rsstest.xml file const REDIRECTURL = 'http://tinyurl.com/lvyslv'; + # The number of seconds tests should wait for the server to respond (high to prevent false positives). + const TIMEOUT = 10; function setUp() { moodle_simplepie::reset_cache(); } function test_getfeed() { - $feed = new moodle_simplepie(self::VALIDURL); - + $feed = new moodle_simplepie(); + $feed->set_timeout(self::TIMEOUT); + $feed->set_feed_url(self::VALIDURL); + $feed->init(); $this->assertInstanceOf('moodle_simplepie', $feed); $this->assertNull($feed->error(), "Failed to load the sample RSS file. Please check your proxy settings in Moodle. %s"); @@ -108,7 +112,10 @@ EOD; * Test retrieving a url which doesn't exist */ function test_failurl() { - $feed = @new moodle_simplepie(self::INVALIDURL); // we do not want this in php error log + $feed = new moodle_simplepie(); + $feed->set_timeout(self::TIMEOUT); + $feed->set_feed_url(self::INVALIDURL); + @$feed->init(); // We do not want this in php error log. $this->assertNotEmpty($feed->error()); } @@ -135,7 +142,10 @@ EOD; function test_redirect() { global $CFG; - $feed = new moodle_simplepie(self::REDIRECTURL); + $feed = new moodle_simplepie(); + $feed->set_timeout(self::TIMEOUT); + $feed->set_feed_url(self::REDIRECTURL); + $feed->init(); $this->assertNull($feed->error()); $this->assertEquals($feed->get_title(), 'Moodle News');