Skip to content

Commit 80cd90b

Browse files
Allow to cancel partitions stream on parsing (#1462)
PartitionsSaxHandler::Abort() was useless. And it is not enough to Abort() when we are waiting for characters in the stream. Relates-To: OLPEDGE-2859 Signed-off-by: Rustam Gamidov <ext-rustam.gamidov@here.com>
1 parent d42f991 commit 80cd90b

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

olp-cpp-sdk-dataservice-read/src/repositories/PartitionsRepository.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2023 HERE Europe B.V.
2+
* Copyright (C) 2019-2024 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -633,8 +633,10 @@ client::ApiNoResponse PartitionsRepository::ParsePartitionsStream(
633633
auto partitions_handler =
634634
std::make_shared<repository::PartitionsSaxHandler>(partition_callback);
635635

636-
auto reader_cancellation_token =
637-
client::CancellationToken([=]() { partitions_handler->Abort(); });
636+
auto reader_cancellation_token = client::CancellationToken([=]() {
637+
partitions_handler->Abort();
638+
async_stream->CloseStream(client::ApiError::Cancelled());
639+
});
638640

639641
if (!context.ExecuteOrCancelled(
640642
[=]() { return reader_cancellation_token; })) {

olp-cpp-sdk-dataservice-read/src/repositories/PartitionsSaxHandler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023 HERE Europe B.V.
2+
* Copyright (C) 2023-2024 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -149,7 +149,7 @@ bool PartitionsSaxHandler::EndArray(unsigned int) {
149149

150150
bool PartitionsSaxHandler::Default() { return false; }
151151

152-
void PartitionsSaxHandler::Abort() { continue_parsing_.store(true); }
152+
void PartitionsSaxHandler::Abort() { continue_parsing_.store(false); }
153153

154154
PartitionsSaxHandler::State PartitionsSaxHandler::ProcessNextAttribute(
155155
const char* name, unsigned int /*length*/) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2023 HERE Europe B.V.
2+
* Copyright (C) 2019-2024 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1714,6 +1714,8 @@ TEST_F(PartitionsRepositoryTest, ParsePartitionsStream) {
17141714
parsing_promise.set_value();
17151715
}).detach();
17161716

1717+
// give the parsing time to start
1718+
std::this_thread::sleep_for(std::chrono::milliseconds(100u));
17171719
context_to_cancel.CancelOperation();
17181720

17191721
EXPECT_EQ(parsing_promise.get_future().wait_for(kTimeout),

0 commit comments

Comments
 (0)