mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
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: * Introduced a way to set the timeout during intitial construction * Converted the unit tests to use a high timeout value
This commit is contained in:
parent
f192883305
commit
f1da132271
@ -52,8 +52,9 @@ class moodle_simplepie extends SimplePie {
|
||||
* with Moodle defaults.
|
||||
*
|
||||
* @param string $feedurl optional URL of the feed
|
||||
* @param int $timeout how many seconds requests should wait for server response
|
||||
*/
|
||||
public function __construct($feedurl = null) {
|
||||
public function __construct($feedurl = null, $timeout = 2) {
|
||||
$cachedir = moodle_simplepie::get_cache_directory();
|
||||
check_dir_exists($cachedir);
|
||||
|
||||
@ -70,7 +71,7 @@ class moodle_simplepie extends SimplePie {
|
||||
$this->set_output_encoding('UTF-8');
|
||||
|
||||
// default to a short timeout as most operations will be interactive
|
||||
$this->set_timeout(2);
|
||||
$this->set_timeout($timeout);
|
||||
|
||||
// 1 hour default cache
|
||||
$this->set_cache_location($cachedir);
|
||||
|
@ -37,19 +37,21 @@ require_once($CFG->libdir.'/simplepie/moodle_simplepie.php');
|
||||
|
||||
class moodlesimplepie_testcase extends basic_testcase {
|
||||
|
||||
# A url we know exists and is valid
|
||||
// A url we know exists and is valid.
|
||||
const VALIDURL = 'http://download.moodle.org/unittest/rsstest.xml';
|
||||
# A url which we know doesn't exist
|
||||
// A url which we know doesn't exist.
|
||||
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';
|
||||
// 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(self::VALIDURL, self::TIMEOUT);
|
||||
|
||||
$this->assertInstanceOf('moodle_simplepie', $feed);
|
||||
|
||||
@ -109,7 +111,7 @@ 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(self::INVALIDURL, self::TIMEOUT); // we do not want this in php error log
|
||||
|
||||
$this->assertNotEmpty($feed->error());
|
||||
}
|
||||
@ -136,7 +138,7 @@ EOD;
|
||||
function test_redirect() {
|
||||
global $CFG;
|
||||
|
||||
$feed = new moodle_simplepie(self::REDIRECTURL);
|
||||
$feed = new moodle_simplepie(self::REDIRECTURL, self::TIMEOUT);
|
||||
|
||||
$this->assertNull($feed->error());
|
||||
$this->assertEquals($feed->get_title(), 'Moodle News');
|
||||
|
Loading…
x
Reference in New Issue
Block a user