Skip to content

Commit

Permalink
MDL-40207 simplepie: reduce false failures in unit tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danpoltawski committed Jun 17, 2013
1 parent eabe1d3 commit 5d44714
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/tests/rsslib_test.php
Expand Up @@ -43,14 +43,18 @@ class moodlesimplepie_testcase extends basic_testcase {
const INVALIDURL = 'http://download.moodle.org/unittest/rsstest-which-doesnt-exist.xml'; const INVALIDURL = 'http://download.moodle.org/unittest/rsstest-which-doesnt-exist.xml';
# This tinyurl redirects to th rsstest.xml file # This tinyurl redirects to th rsstest.xml file
const REDIRECTURL = 'http://tinyurl.com/lvyslv'; 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() { function setUp() {
moodle_simplepie::reset_cache(); moodle_simplepie::reset_cache();
} }


function test_getfeed() { 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->assertInstanceOf('moodle_simplepie', $feed);


$this->assertNull($feed->error(), "Failed to load the sample RSS file. Please check your proxy settings in Moodle. %s"); $this->assertNull($feed->error(), "Failed to load the sample RSS file. Please check your proxy settings in Moodle. %s");
Expand Down Expand Up @@ -108,7 +112,10 @@ function test_getfeed() {
* Test retrieving a url which doesn't exist * Test retrieving a url which doesn't exist
*/ */
function test_failurl() { 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()); $this->assertNotEmpty($feed->error());
} }
Expand All @@ -135,7 +142,10 @@ function test_failproxy() {
function test_redirect() { function test_redirect() {
global $CFG; 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->assertNull($feed->error());
$this->assertEquals($feed->get_title(), 'Moodle News'); $this->assertEquals($feed->get_title(), 'Moodle News');
Expand Down

0 comments on commit 5d44714

Please sign in to comment.