jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/373526 )
Change subject: Use CopyUploadTimeout setting
......................................................................
Use CopyUploadTimeout setting
It's rather hard ot keep testing this extension
while you have unreliable & slow wifi unless you
can modify the timeout for requests!
Change-Id: I2e86d33ba4b0bb96644589435d9d0dd0f8955c19
---
M src/ServiceWiring.php
M src/Services/Http/HttpRequestExecutor.php
M tests/phpunit/Services/Http/HttpRequestExecutorTest.php
3 files changed, 23 insertions(+), 8 deletions(-)
Approvals:
WMDE-Fisch: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/ServiceWiring.php b/src/ServiceWiring.php
index 4504849..6910d24 100644
--- a/src/ServiceWiring.php
+++ b/src/ServiceWiring.php
@@ -29,8 +29,12 @@
},
'FileImporterHttpRequestExecutor' => function ( MediaWikiServices
$services ) {
+ $timeout = $services->getMainConfig()->get( 'CopyUploadTimeout'
);
$maxFileSize = UploadBase::getMaxUploadSize( 'import' );
- $service = new HttpRequestExecutor( $maxFileSize );
+ $service = new HttpRequestExecutor(
+ $timeout,
+ $maxFileSize
+ );
$service->setLogger( LoggerFactory::getInstance( 'FileImporter'
) );
return $service;
},
diff --git a/src/Services/Http/HttpRequestExecutor.php
b/src/Services/Http/HttpRequestExecutor.php
index fe2b933..9f4500a 100644
--- a/src/Services/Http/HttpRequestExecutor.php
+++ b/src/Services/Http/HttpRequestExecutor.php
@@ -22,17 +22,24 @@
private $requestFactoryCallable;
/**
+ * @var int|bool
+ */
+ private $timeout;
+
+ /**
* @var int|null
*/
private $maxFileSize;
/**
+ * @param int|bool $timeout of http requests in seconds, false for
default
* @param int|null $maxFileSize in bytes
*/
- public function __construct( $maxFileSize = null ) {
+ public function __construct( $timeout = false, $maxFileSize = null ) {
$this->requestFactoryCallable = [ MWHttpRequest::class,
'factory' ];
$this->logger = new NullLogger();
$this->maxFileSize = $maxFileSize;
+ $this->timeout = $timeout;
}
public function setLogger( LoggerInterface $logger ) {
@@ -73,7 +80,6 @@
/**
* TODO proxy? $wgCopyUploadProxy ?
- * TODO timeout $wgCopyUploadTimeout ?
*
* @param string $url
* @param callable|null $callback
@@ -82,14 +88,19 @@
* @return MWHttpRequest
*/
public function executeWithCallback( $url, $callback = null ) {
+ $options = [
+ 'logger' => $this->logger,
+ 'followRedirects' => true,
+ ];
+ if ( $this->timeout !== false ) {
+ $options['timeout'] = $this->timeout;
+ }
+
/** @var MWHttpRequest $request */
$request = call_user_func(
$this->requestFactoryCallable,
$url,
- [
- 'logger' => $this->logger,
- 'followRedirects' => true,
- ],
+ $options,
__METHOD__
);
diff --git a/tests/phpunit/Services/Http/HttpRequestExecutorTest.php
b/tests/phpunit/Services/Http/HttpRequestExecutorTest.php
index 21444cb..e5c64b1 100644
--- a/tests/phpunit/Services/Http/HttpRequestExecutorTest.php
+++ b/tests/phpunit/Services/Http/HttpRequestExecutorTest.php
@@ -22,7 +22,7 @@
* @dataProvider provideTestExecute
*/
public function testExecute( $testUrl, $expectedResult ) {
- $executor = new HttpRequestExecutor();
+ $executor = new HttpRequestExecutor( 10 );
$factoryOverride = function ( $url, $options = null, $caller =
__METHOD__ )
use ( $testUrl, $expectedResult ) {
$this->assertEquals( $testUrl, $url );
--
To view, visit https://gerrit.wikimedia.org/r/373526
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2e86d33ba4b0bb96644589435d9d0dd0f8955c19
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/FileImporter
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Andrew-WMDE <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: WMDE-Fisch <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits