This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test Map object destruction with pending requests
Test whenever destroying a Map object with requests pending works and is done quickly. The test injects artificial delays in selected requests and tries to destroy the Map object afterwards. Currently glyph requests are skipped because there is a bug being worked on in a different issue.
- Loading branch information
Showing
4 changed files
with
188 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "../fixtures/fixture_log_observer.hpp" | ||
#include "../fixtures/util.hpp" | ||
#include "mock_file_source.hpp" | ||
|
||
#include <mbgl/map/map.hpp> | ||
#include <mbgl/map/still_image.hpp> | ||
#include <mbgl/platform/default/headless_display.hpp> | ||
#include <mbgl/platform/default/headless_view.hpp> | ||
#include <mbgl/util/io.hpp> | ||
#include <mbgl/util/run_loop.hpp> | ||
#include <mbgl/util/uv_detail.hpp> | ||
|
||
using namespace mbgl; | ||
|
||
class PendingResourcesTest : public ::testing::TestWithParam<std::string> { | ||
}; | ||
|
||
// This test will load a Style but one of the resources requested will not be | ||
// replied immediately like the others. We get an notification by the | ||
// MockFileSource when some resource is artificially delayed and we destroy | ||
// the Map object after that. The idea here is to test if these pending requests | ||
// are getting canceled correctly if on shutdown. | ||
TEST_P(PendingResourcesTest, DeleteMapObjectWithPendingRequest) { | ||
// TODO: The glyphs test is blocked by the issue #1664. | ||
if (GetParam() == "glyphs.pbf") { | ||
return; | ||
} | ||
|
||
util::RunLoop loop(uv_default_loop()); | ||
|
||
auto display = std::make_shared<mbgl::HeadlessDisplay>(); | ||
HeadlessView view(display); | ||
MockFileSource fileSource(MockFileSource::SuccessWithDelay, GetParam()); | ||
|
||
std::unique_ptr<Map> map = std::make_unique<Map>(view, fileSource, MapMode::Still); | ||
|
||
uv::async endTest(loop.get(), [&map, &loop] { | ||
map.reset(); | ||
loop.stop(); | ||
}); | ||
|
||
endTest.unref(); | ||
fileSource.setOnRequestDelayedCallback([&endTest] { endTest.send(); }); | ||
|
||
const std::string style = util::read_file("test/fixtures/resources/style.json"); | ||
map->resize(1000, 1000, 1.0); | ||
map->setStyleJSON(style, "."); | ||
|
||
map->renderStill([&endTest](std::exception_ptr, std::unique_ptr<const StillImage>) { | ||
EXPECT_TRUE(false) << "Should never happen."; | ||
}); | ||
|
||
uv_run(loop.get(), UV_RUN_DEFAULT); | ||
} | ||
|
||
// In the test data below, "sprite" will match both "sprite.json" and "sprite.png" and cause two | ||
// requests to be canceled. "resources" will match everything but in practice will only test the | ||
// cancellation of the sprites and "source.json" because we only load the rest after "source.json" | ||
// gets parsed. | ||
INSTANTIATE_TEST_CASE_P(ResourceLoader, PendingResourcesTest, | ||
::testing::Values("source.json", "sprite.json", "sprite.png", "sprite", "vector.pbf", "glyphs.pbf", "resources")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters