Skip to content

Commit d42f991

Browse files
Use thread in PartitionsRepositoryTest (#1460)
To ensure parsing is in another thread so we can cancel it Relates-To: OLPEDGE-2845 Signed-off-by: Rustam Gamidov <ext-rustam.gamidov@here.com>
1 parent 52e22af commit d42f991

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

olp-cpp-sdk-dataservice-read/tests/PartitionsRepositoryTest.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,15 +1706,18 @@ TEST_F(PartitionsRepositoryTest, ParsePartitionsStream) {
17061706
auto async_stream = std::make_shared<repository::AsyncJsonStream>();
17071707
client::ApiNoResponse response;
17081708
client::CancellationContext context_to_cancel;
1709+
std::promise<void> parsing_promise;
17091710

1710-
std::future<void> parsing_future = std::async(std::launch::async, [&]() {
1711+
std::thread([&]() {
17111712
response =
17121713
repository.ParsePartitionsStream(async_stream, {}, context_to_cancel);
1713-
});
1714+
parsing_promise.set_value();
1715+
}).detach();
17141716

17151717
context_to_cancel.CancelOperation();
17161718

1717-
EXPECT_EQ(parsing_future.wait_for(kTimeout), std::future_status::ready);
1719+
EXPECT_EQ(parsing_promise.get_future().wait_for(kTimeout),
1720+
std::future_status::ready);
17181721
EXPECT_FALSE(response.IsSuccessful());
17191722
EXPECT_EQ(response.GetError().GetErrorCode(),
17201723
olp::client::ErrorCode::Cancelled);

0 commit comments

Comments
 (0)