diff options
author | Huyen Chau Nguyen <hello@chau-nguyen.de> | 2018-10-17 20:15:08 +0200 |
---|---|---|
committer | Huyen Chau Nguyen <hello@chau-nguyen.de> | 2018-10-23 12:47:10 +0200 |
commit | fa78bcadfddb2c1179d929e4a2abcc1b1dd758c6 (patch) | |
tree | f22c92a9fd5051a57753b2a8d26d0bf51ba79d10 /test/storage | |
parent | 40693e00a897a9ab2fa7b15fce21041990745b4b (diff) | |
download | qtlocation-mapboxgl-fa78bcadfddb2c1179d929e4a2abcc1b1dd758c6.tar.gz |
[core] add tests for handling requests with different priorities
- ensure that low priority requests are handled last
- add option to set the number of maximum concurrent requests for tests
- some style fixups
Diffstat (limited to 'test/storage')
-rw-r--r-- | test/storage/offline_download.test.cpp | 2 | ||||
-rw-r--r-- | test/storage/online_file_source.test.cpp | 91 |
2 files changed, 92 insertions, 1 deletions
diff --git a/test/storage/offline_download.test.cpp b/test/storage/offline_download.test.cpp index 01baf29592..4db807a204 100644 --- a/test/storage/offline_download.test.cpp +++ b/test/storage/offline_download.test.cpp @@ -663,7 +663,7 @@ TEST(OfflineDownload, Deactivate) { } -TEST(OfflineDownload, LowPriorityRequests) { +TEST(OfflineDownload, AllOfflineRequestsHaveLowPriority) { OfflineTest test; auto region = test.createRegion(); ASSERT_TRUE(region); diff --git a/test/storage/online_file_source.test.cpp b/test/storage/online_file_source.test.cpp index b5a7c139d3..5021a513e3 100644 --- a/test/storage/online_file_source.test.cpp +++ b/test/storage/online_file_source.test.cpp @@ -425,3 +425,94 @@ TEST(OnlineFileSource, ChangeAPIBaseURL){ fs.setAPIBaseURL(customURL); EXPECT_EQ(customURL, fs.getAPIBaseURL()); } + + +TEST(OnlineFileSource, TEST_REQUIRES_SERVER(LowHighPriorityRequests)) { + util::RunLoop loop; + OnlineFileSource fs; + std::size_t response_counter = 0; + const std::size_t NUM_REQUESTS = 3; + + fs.setMaximumConcurrentRequestsOverride(1); + + NetworkStatus::Set(NetworkStatus::Status::Offline); + + // requesting a low priority resource + Resource low_prio{ Resource::Unknown, "http://127.0.0.1:3000/load/1" }; + low_prio.setPriority(Resource::Priority::Low); + std::unique_ptr<AsyncRequest> req_0 = fs.request(low_prio, [&](Response) { + response_counter++; + req_0.reset(); + EXPECT_EQ(response_counter, NUM_REQUESTS); // make sure this is responded last + loop.stop(); + }); + + // requesting two "regular" resources + Resource regular1{ Resource::Unknown, "http://127.0.0.1:3000/load/2" }; + std::unique_ptr<AsyncRequest> req_1 = fs.request(regular1, [&](Response) { + response_counter++; + req_1.reset(); + }); + Resource regular2{ Resource::Unknown, "http://127.0.0.1:3000/load/3" }; + std::unique_ptr<AsyncRequest> req_2 = fs.request(regular2, [&](Response) { + response_counter++; + req_2.reset(); + }); + + NetworkStatus::Set(NetworkStatus::Status::Online); + + loop.run(); +} + + +TEST(OnlineFileSource, TEST_REQUIRES_SERVER(LowHighPriorityRequestsMany)) { + util::RunLoop loop; + OnlineFileSource fs; + int response_counter = 0; + int correct_low = 0; + int correct_regular = 0; + + + fs.setMaximumConcurrentRequestsOverride(1); + + NetworkStatus::Set(NetworkStatus::Status::Offline); + + std::vector<std::unique_ptr<AsyncRequest>> collector; + + for (int num_reqs = 0; num_reqs < 20; num_reqs++) { + if (num_reqs % 2 == 0) { + std::unique_ptr<AsyncRequest> req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/load/" + std::to_string(num_reqs), Resource::Priority::Regular }, [&](Response) { + response_counter++; + + if (response_counter <= 10) { // count the high priority requests that arrive late correctly + correct_regular++; + } + }); + collector.push_back(std::move(req)); + } + else { + std::unique_ptr<AsyncRequest> req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/load/" + std::to_string(num_reqs), Resource::Priority::Low }, [&](Response) { + response_counter++; + + if (response_counter > 10) { // count the low priority requests that arrive late correctly + correct_low++; + } + + // stop and check correctness after last low priority request is responded + if (20 == response_counter) { + loop.stop(); + for (auto& collected_req : collector) { + collected_req.reset(); + } + ASSERT_TRUE(correct_low >= 9); + ASSERT_TRUE(correct_regular >= 9); + } + }); + collector.push_back(std::move(req)); + } + } + + NetworkStatus::Set(NetworkStatus::Status::Online); + + loop.run(); +}
\ No newline at end of file |