Skip to content

Commit a8e6c69

Browse files
Add static task scheduler instance for stream writing tests.
This should temporary fix the issue when the task is capturing the last reference to task scheduler. This behavior will be fixed in the future. Resolves: OLPEDGE-962 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent 264bab6 commit a8e6c69

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

tests/functional/olp-cpp-sdk-dataservice-write/DataserviceWriteStreamLayerClientCacheTest.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class DataserviceWriteStreamLayerClientCacheTest : public ::testing::Test {
9595
static void SetUpTestSuite() {
9696
s_network = olp::client::OlpClientSettingsFactory::
9797
CreateDefaultNetworkRequestHandler();
98+
s_task_scheduler =
99+
olp::client::OlpClientSettingsFactory::CreateDefaultTaskScheduler(1u);
98100
}
99101

100102
virtual void SetUp() override {
@@ -145,8 +147,7 @@ class DataserviceWriteStreamLayerClientCacheTest : public ::testing::Test {
145147
olp::client::OlpClientSettings settings;
146148
settings.authentication_settings = auth_client_settings;
147149
settings.network_request_handler = network;
148-
settings.task_scheduler =
149-
olp::client::OlpClientSettingsFactory::CreateDefaultTaskScheduler(1u);
150+
settings.task_scheduler = s_task_scheduler;
150151

151152
disk_cache_ = std::make_shared<olp::cache::DefaultCache>();
152153
EXPECT_EQ(disk_cache_->Open(),
@@ -171,6 +172,7 @@ class DataserviceWriteStreamLayerClientCacheTest : public ::testing::Test {
171172

172173
protected:
173174
static std::shared_ptr<olp::http::Network> s_network;
175+
static std::shared_ptr<olp::thread::TaskScheduler> s_task_scheduler;
174176

175177
std::shared_ptr<StreamLayerClient> client_;
176178
std::shared_ptr<std::vector<unsigned char>> data_;
@@ -185,6 +187,13 @@ class DataserviceWriteStreamLayerClientCacheTest : public ::testing::Test {
185187
std::shared_ptr<olp::http::Network>
186188
DataserviceWriteStreamLayerClientCacheTest::s_network;
187189

190+
// Static network instance is necessary as it needs to outlive any created
191+
// clients. This is a known limitation as triggered send requests capture the
192+
// task_scheduler instance inside the callbacks, and it could happen that the
193+
// task is trying to destroy task scheduler, that will result in a crash.
194+
std::shared_ptr<olp::thread::TaskScheduler>
195+
DataserviceWriteStreamLayerClientCacheTest::s_task_scheduler;
196+
188197
TEST_F(DataserviceWriteStreamLayerClientCacheTest, Queue) {
189198
auto error = client_->Queue(
190199
PublishDataRequest().WithData(data_).WithLayerId(GetTestLayer()));

tests/functional/olp-cpp-sdk-dataservice-write/DataserviceWriteStreamLayerClientTest.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ class DataserviceWriteStreamLayerClientTest : public ::testing::Test {
160160
static void SetUpTestSuite() {
161161
s_network = olp::client::OlpClientSettingsFactory::
162162
CreateDefaultNetworkRequestHandler();
163+
s_task_scheduler =
164+
olp::client::OlpClientSettingsFactory::CreateDefaultTaskScheduler(1u);
163165
}
164166

165167
virtual std::shared_ptr<StreamLayerClient> CreateStreamLayerClient() {
@@ -181,8 +183,7 @@ class DataserviceWriteStreamLayerClientTest : public ::testing::Test {
181183
olp::client::OlpClientSettings settings;
182184
settings.authentication_settings = auth_client_settings;
183185
settings.network_request_handler = network;
184-
settings.task_scheduler =
185-
olp::client::OlpClientSettingsFactory::CreateDefaultTaskScheduler(1u);
186+
settings.task_scheduler = s_task_scheduler;
186187

187188
return std::make_shared<StreamLayerClient>(
188189
olp::client::HRN{GetTestCatalog()}, StreamLayerClientSettings{},
@@ -203,6 +204,7 @@ class DataserviceWriteStreamLayerClientTest : public ::testing::Test {
203204

204205
protected:
205206
static std::shared_ptr<olp::http::Network> s_network;
207+
static std::shared_ptr<olp::thread::TaskScheduler> s_task_scheduler;
206208

207209
std::shared_ptr<StreamLayerClient> client_;
208210
std::shared_ptr<std::vector<unsigned char>> data_;
@@ -215,6 +217,13 @@ class DataserviceWriteStreamLayerClientTest : public ::testing::Test {
215217
std::shared_ptr<olp::http::Network>
216218
DataserviceWriteStreamLayerClientTest::s_network;
217219

220+
// Static network instance is necessary as it needs to outlive any created
221+
// clients. This is a known limitation as triggered send requests capture the
222+
// task_scheduler instance inside the callbacks, and it could happen that the
223+
// task is trying to destroy task scheduler, that will result in a crash.
224+
std::shared_ptr<olp::thread::TaskScheduler>
225+
DataserviceWriteStreamLayerClientTest::s_task_scheduler;
226+
218227
TEST_F(DataserviceWriteStreamLayerClientTest, PublishData) {
219228
auto response =
220229
client_

0 commit comments

Comments
 (0)