Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Gorshenin <y@maps.me>2017-10-26 16:37:51 +0300
committerr.kuznetsov <r.kuznetsov@corp.mail.ru>2017-11-09 13:20:24 +0300
commit11a7e8143fde697ededf3f01d873fba7e1549c51 (patch)
tree3bd78970cb63d680a2c8c22264af4f20774fecf8 /storage
parent246ac82146cf34a6816323bd8ee958ba75f830c3 (diff)
[storage] One more test on failing network policy.
Diffstat (limited to 'storage')
-rw-r--r--storage/storage_tests/storage_tests.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp
index 792f1dba8f..c8f0380039 100644
--- a/storage/storage_tests/storage_tests.cpp
+++ b/storage/storage_tests/storage_tests.cpp
@@ -42,9 +42,11 @@
#include "base/scope_guard.hpp"
#include "base/string_utils.hpp"
+#include "std/algorithm.hpp"
#include "std/bind.hpp"
#include "std/condition_variable.hpp"
#include "std/exception.hpp"
+#include "std/iterator.hpp"
#include "std/map.hpp"
#include "std/mutex.hpp"
#include "std/shared_ptr.hpp"
@@ -68,6 +70,28 @@ public:
bool IsDownloadingAllowed() override { return false; }
};
+class SometimesFailingDownloadingPolicy : public DownloadingPolicy
+{
+public:
+ SometimesFailingDownloadingPolicy(vector<uint64_t> const & failedRequests)
+ : m_failedRequests(failedRequests)
+ {
+ sort(m_failedRequests.begin(), m_failedRequests.end());
+ }
+
+ bool IsDownloadingAllowed() override
+ {
+ auto const allowed =
+ !binary_search(m_failedRequests.begin(), m_failedRequests.end(), m_request);
+ ++m_request;
+ return allowed;
+ }
+
+private:
+ vector<uint64_t> m_failedRequests;
+ uint64_t m_request = 0;
+};
+
string const kSingleMwmCountriesTxt = string(R"({
"id": "Countries",
"v": )" + strings::to_string(version::FOR_TESTING_SINGLE_MWM1) + R"(,
@@ -1822,4 +1846,56 @@ UNIT_TEST(StorageTest_FalsePolicy)
storage.DownloadCountry(countryId, MapOptions::Map);
}
}
+
+UNIT_CLASS_TEST(StorageTest, MultipleMaps)
+{
+ // This test tries do download all maps from Russian Federation, but
+ // network policy sometimes changes, therefore some countries won't
+ // be downloaded.
+
+ vector<uint64_t> const failedRequests {{5, 10, 21}};
+ TEST(is_sorted(failedRequests.begin(), failedRequests.end()), ());
+
+ SometimesFailingDownloadingPolicy policy(failedRequests);
+ Storage storage;
+ storage.SetDownloadingPolicy(&policy);
+
+ auto const nodeId = storage.FindCountryIdByFile("Russian Federation");
+ TCountriesVec children;
+ storage.GetChildren(nodeId, children);
+ vector<bool> downloaded(children.size());
+
+ auto const onStatusChange = [&](TCountryId const &id) {
+ auto const status = storage.CountryStatusEx(id);
+ if (status != Status::EOnDisk)
+ return;
+
+ auto const it = find(children.cbegin(), children.cend(), id);
+ if (it == children.end())
+ return;
+
+ downloaded[distance(children.cbegin(), it)] = true;
+ };
+
+ auto const onProgress = [&](TCountryId const & /* countryId */,
+ TLocalAndRemoteSize const & /* progress */) {};
+
+ auto const slot = storage.Subscribe(onStatusChange, onProgress);
+ MY_SCOPE_GUARD(cleanup, [&]() { storage.Unsubscribe(slot); });
+
+ storage.Init(&OnCountryDownloaded /* didDownload */,
+ [](TCountryId const &, TLocalFilePtr const) { return false; } /* willDelete */);
+ storage.SetDownloaderForTesting(make_unique<FakeMapFilesDownloader>(runner));
+ storage.DownloadNode(nodeId);
+ runner.Run();
+
+ for (size_t i = 0; i < downloaded.size(); ++i)
+ {
+ auto const expected = !binary_search(failedRequests.begin(), failedRequests.end(), i);
+ TEST_EQUAL(downloaded[i], expected, ("Unexpected status for country:", children[i]));
+ }
+
+ // Unfortunately, whole country was not downloaded.
+ TEST_EQUAL(storage.CountryStatusEx(nodeId), Status::ENotDownloaded, ());
+}
} // namespace storage