diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2015-06-22 21:46:54 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2015-06-22 22:00:24 +0300 |
commit | 43d69b6a65a3ee05f41ed13ac5bf2ca943075e65 (patch) | |
tree | c8ec37696c560d489013704a921906618df815ee /test/style | |
parent | 641046138ce795c1c76c6ce3ab9fdad74bbda9e2 (diff) | |
download | qtlocation-mapboxgl-43d69b6a65a3ee05f41ed13ac5bf2ca943075e65.tar.gz |
Fix resource loading flaky test
When testing failed vector tiles requests, we check for error messages
of a very specific tiles, but mbgl will requests 4 tiles.
We might get the error callback before the tile we are checking for
reports error, so the test fails.
Now we use a regex to match the log message we are looking for.
Diffstat (limited to 'test/style')
-rw-r--r-- | test/style/resource_loading.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/test/style/resource_loading.cpp b/test/style/resource_loading.cpp index 5539988a06..fb6ba744a9 100644 --- a/test/style/resource_loading.cpp +++ b/test/style/resource_loading.cpp @@ -13,6 +13,8 @@ #include <mbgl/util/texture_pool.hpp> #include <mbgl/util/thread.hpp> +#include <regex> + using namespace mbgl; namespace { @@ -123,21 +125,20 @@ void runTestCase(MockFileSource::Type type, // join and cease logging after this point. context.reset(); - const FixtureLogObserver::LogMessage logMessage { - EventSeverity::Error, - Event::Style, - int64_t(-1), - message, - }; + uint32_t match = 0; + std::vector<FixtureLogObserver::LogMessage> logMessages = log->unchecked(); + + for (auto& logMessage : logMessages) { + if (std::regex_match(*logMessage.msg, std::regex(message))) { + match++; + } + } if (type == MockFileSource::Success) { - EXPECT_EQ(log->count(logMessage), 0u); + EXPECT_EQ(match, 0u); } else { - EXPECT_GT(log->count(logMessage), 0u); + EXPECT_GT(match, 0u); } - - // Clear the remaining error messages - log->unchecked().size(); } } @@ -151,7 +152,7 @@ TEST_P(ResourceLoading, Success) { TEST_P(ResourceLoading, RequestFail) { std::stringstream message; - message << "Failed to load [test/fixtures/resources/" << GetParam() << "]: Failed by the test case"; + message << "Failed to load \\[test/fixtures/resources/" << GetParam() << "]: Failed by the test case"; runTestCase(MockFileSource::RequestFail, GetParam(), message.str()); } @@ -163,9 +164,9 @@ TEST_P(ResourceLoading, RequestWithCorruptedData) { message << "Failed to parse "; if (param == "vector.pbf") { - message << "[15/16384/16384]: pbf unknown field type exception"; + message << "\\[15/1638./1638.]: pbf unknown field type exception"; } else { - message << "[test/fixtures/resources/" << param << "]"; + message << "\\[test/fixtures/resources/" << param << "]"; } if (param.find("json") != std::string::npos) { |