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.
This commit is contained in:
Thiago Marcos P. Santos
2015-06-22 21:46:54 +03:00
parent 641046138c
commit 43d69b6a65

View File

@@ -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();
if (type == MockFileSource::Success) {
EXPECT_EQ(log->count(logMessage), 0u);
} else {
EXPECT_GT(log->count(logMessage), 0u);
for (auto& logMessage : logMessages) {
if (std::regex_match(*logMessage.msg, std::regex(message))) {
match++;
}
}
// Clear the remaining error messages
log->unchecked().size();
if (type == MockFileSource::Success) {
EXPECT_EQ(match, 0u);
} else {
EXPECT_GT(match, 0u);
}
}
}
@@ -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) {