From 50c90f9174fd2d695e4cb1fdc95283e9c0f465f0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 12 Jan 2019 15:35:44 +0100 Subject: [PATCH 1/2] Use wxScopedPtr<> in URL unit test Don't leak the stream if an error happens in the rest of the test. --- tests/uris/url.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/uris/url.cpp b/tests/uris/url.cpp index 8fbb208927..0520a8be99 100644 --- a/tests/uris/url.cpp +++ b/tests/uris/url.cpp @@ -22,6 +22,7 @@ #include "wx/url.h" #include "wx/mstream.h" +#include "wx/scopedptr.h" // ---------------------------------------------------------------------------- // test class @@ -73,7 +74,7 @@ void URLTestCase::GetInputStream() wxURL url("http://www.wxwidgets.org/assets/img/header-logo.png"); CPPUNIT_ASSERT_EQUAL(wxURL_NOERR, url.GetError()); - wxInputStream *in_stream = url.GetInputStream(); + wxScopedPtr in_stream(url.GetInputStream()); CPPUNIT_ASSERT(in_stream); CPPUNIT_ASSERT(in_stream->IsOk()); @@ -81,9 +82,6 @@ void URLTestCase::GetInputStream() CPPUNIT_ASSERT(in_stream->Read(ostream).GetLastError() == wxSTREAM_EOF); CPPUNIT_ASSERT_EQUAL(17334, ostream.GetSize()); - - // we have to delete the object created by GetInputStream() - delete in_stream; } void URLTestCase::CopyAndAssignment() From 3c468260ff9ef97733a353f2ed9acaebcf90d429 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 12 Jan 2019 15:39:09 +0100 Subject: [PATCH 2/2] Retry in URL test when running in a CI environment There are episodic failures in this test when running under AppVeyor, check if retrying to connect can work around them. --- tests/uris/url.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/uris/url.cpp b/tests/uris/url.cpp index 0520a8be99..afda05f6d7 100644 --- a/tests/uris/url.cpp +++ b/tests/uris/url.cpp @@ -23,6 +23,7 @@ #include "wx/url.h" #include "wx/mstream.h" #include "wx/scopedptr.h" +#include "wx/utils.h" // ---------------------------------------------------------------------------- // test class @@ -75,6 +76,15 @@ void URLTestCase::GetInputStream() CPPUNIT_ASSERT_EQUAL(wxURL_NOERR, url.GetError()); wxScopedPtr in_stream(url.GetInputStream()); + if ( !in_stream && IsAutomaticTest() ) + { + // Sometimes the connection fails during CI runs, try to connect once + // again if this happens in the hope it was just a transient error. + wxSleep(3); + WARN("Connection to www.wxwidgets.org failed, retrying..."); + in_stream.reset(url.GetInputStream()); + } + CPPUNIT_ASSERT(in_stream); CPPUNIT_ASSERT(in_stream->IsOk());