Merge branch 'webrequest-tests'

Make wxWebRequest CI tests more reliable by using local httpbin
instance.

See https://github.com/wxWidgets/wxWidgets/pull/2183
This commit is contained in:
Vadim Zeitlin
2021-01-27 17:55:42 +01:00
4 changed files with 77 additions and 24 deletions

View File

@@ -71,4 +71,24 @@ before_build:
build_script: c:\projects\wxwidgets\build\tools\appveyor.bat build_script: c:\projects\wxwidgets\build\tools\appveyor.bat
before_test:
- ps: |
Write-Output "Getting and launching httpbin."
$env:PATH = "C:\Python35;C:\Python35\Scripts;" + $env:PATH
pip.exe --disable-pip-version-check install httpbin
Start-Job -Name wx_httpbin { python.exe -m httpbin.core 2>&1 > c:\projects\wxwidgets\httpbin.log }
Start-Sleep -Seconds 5
curl.exe -s http://127.0.0.1:5000/ip > $null
if ($lastExitCode -eq "0") {
$env:WX_TEST_WEBREQUEST_URL="http://127.0.0.1:5000"
}
else {
Write-Error "Disabling wxWebRequest tests as launching httpbin failed."
$env:WX_TEST_WEBREQUEST_URL="0"
}
test_script: c:\projects\wxwidgets\build\tools\appveyor-test.bat test_script: c:\projects\wxwidgets\build\tools\appveyor-test.bat
after_test:
- ps: |
Stop-Job -Name wx_httpbin

View File

@@ -59,4 +59,7 @@ goto :eof
echo. echo.
echo !!! Non-GUI test failed. echo !!! Non-GUI test failed.
echo. echo.
goto :eof echo --- httpbin output ---
type c:\projects\wxwidgets\httpbin.log
echo --- httpbin output end ---
exit /b 1

View File

@@ -12,6 +12,27 @@ wxBUILD_ARGS="-j$wxPROC_COUNT"
# messages from WebKit tests that we're not interested in. # messages from WebKit tests that we're not interested in.
export NO_AT_BRIDGE=1 export NO_AT_BRIDGE=1
launch_httpbin() {
echo 'travis_fold:start:httpbin'
echo 'Running httpbin...'
# Prefer to use docker if it's available as it's more robust than dealing
# with pip -- but we need to have a fallback as at least Mac builds don't
# have docker.
if command -v docker; then
docker pull kennethreitz/httpbin
docker run -d -p 80:80 kennethreitz/httpbin
WX_TEST_WEBREQUEST_URL="http://localhost"
else
pip install httpbin
python -m httpbin.core &
WX_TEST_WEBREQUEST_URL="http://localhost:5000"
fi
export WX_TEST_WEBREQUEST_URL
echo 'travis_fold:end:httpbin'
}
case $wxTOOLSET in case $wxTOOLSET in
cmake) cmake)
if [ -z $wxCMAKE_TESTS ]; then wxCMAKE_TESTS=CONSOLE_ONLY; fi if [ -z $wxCMAKE_TESTS ]; then wxCMAKE_TESTS=CONSOLE_ONLY; fi
@@ -42,6 +63,8 @@ case $wxTOOLSET in
echo 'travis_fold:end:install' echo 'travis_fold:end:install'
if [ "$wxCMAKE_TESTS" != "OFF" ]; then if [ "$wxCMAKE_TESTS" != "OFF" ]; then
launch_httpbin
echo 'travis_fold:start:testing' echo 'travis_fold:start:testing'
echo 'Testing...' echo 'Testing...'
ctest -V -C Debug -E "test_drawing" --output-on-failure --interactive-debug-mode 0 . ctest -V -C Debug -E "test_drawing" --output-on-failure --interactive-debug-mode 0 .
@@ -124,6 +147,8 @@ case $wxTOOLSET in
exit 0 exit 0
fi fi
launch_httpbin
echo 'travis_fold:start:testing' echo 'travis_fold:start:testing'
echo 'Testing...' echo 'Testing...'
pushd tests pushd tests

View File

@@ -27,11 +27,15 @@
#include "wx/filename.h" #include "wx/filename.h"
#include "wx/wfstream.h" #include "wx/wfstream.h"
// This test uses https://httpbin.org by default, but this can be overridden by // This test uses httpbin service and by default uses the mirror at the
// setting WX_TEST_WEBREQUEST_URL, e.g. when running httpbin locally in a // location below, which seems to be more reliable than the main site at
// docker container. This variable can also be set to a special value "0" to // https://httpbin.org. Any other mirror, including a local one, which can be
// disable running the test entirely. // set by running kennethreitz/httpbin Docker container, can be used by setting
static const char* WX_TEST_WEBREQUEST_URL_DEFAULT = "https://httpbin.org"; // WX_TEST_WEBREQUEST_URL environment variable to its URL.
//
// This variable can also be set to a special value "0" to disable running the
// test entirely.
static const char* WX_TEST_WEBREQUEST_URL_DEFAULT = "https://nghttp2.org/httpbin";
class RequestFixture : public wxTimer class RequestFixture : public wxTimer
{ {
@@ -46,8 +50,19 @@ public:
// it returns false, as this indicates that web requests tests are disabled. // it returns false, as this indicates that web requests tests are disabled.
bool InitBaseURL() bool InitBaseURL()
{ {
if ( !wxGetEnv("WX_TEST_WEBREQUEST_URL", &baseURL) ) if ( wxGetEnv("WX_TEST_WEBREQUEST_URL", &baseURL) )
{
static bool s_shown = false;
if ( !s_shown )
{
s_shown = true;
WARN("Using non-default root URL " << baseURL);
}
}
else
{
baseURL = WX_TEST_WEBREQUEST_URL_DEFAULT; baseURL = WX_TEST_WEBREQUEST_URL_DEFAULT;
}
return baseURL != "0"; return baseURL != "0";
} }
@@ -107,7 +122,7 @@ public:
void RunLoopWithTimeout() void RunLoopWithTimeout()
{ {
StartOnce(10000); // Ensure that we exit the loop after 10s. StartOnce(30000); // Ensure that we exit the loop after 30s.
loop.Run(); loop.Run();
Stop(); Stop();
} }
@@ -232,24 +247,14 @@ TEST_CASE_METHOD(RequestFixture,
if ( !InitBaseURL() ) if ( !InitBaseURL() )
return; return;
// We can't use the same httpbin.org server that we use for the other tests Create("/status/418");
// for this one because it doesn't return anything in the body when
// returning an error status code, so use another one.
CreateAbs("https://httpstat.us/418");
Run(wxWebRequest::State_Failed, 0); Run(wxWebRequest::State_Failed, 0);
// For some reason, this test doesn't work with libcurl included in Ubuntu CHECK( request.GetResponse().GetStatus() == 418 );
// 14.04, so skip it.
const int status = request.GetResponse().GetStatus(); const wxString& response = request.GetResponse().AsString();
if ( status == 0 ) INFO( "Response: " << response);
{ CHECK( response.Contains("teapot") );
WARN("Status code not returned.");
}
else
{
CHECK( status == 418 );
CHECK( request.GetResponse().AsString() == "418 I'm a teapot" );
}
} }
TEST_CASE_METHOD(RequestFixture, TEST_CASE_METHOD(RequestFixture,