Skip to content

Commit

Permalink
Add test for MutliTimeout bug
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 5f94f2bfee09705240d2277b1ac9bb344b9d9589
  • Loading branch information
arseny30 authored and levlam committed Jan 29, 2018
1 parent 614c3cf commit b40df8c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions tdactor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set(TDACTOR_TEST_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/test/actors_main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/actors_simple.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/actors_workers.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/actors_bugs.cpp
PARENT_SCOPE
)

Expand Down
49 changes: 49 additions & 0 deletions tdactor/test/actors_bugs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Copyright Aliaksei Levin ([email protected]), Arseny Smirnov ([email protected]) 2014-2018
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/utils/tests.h"

#include "td/actor/Timeout.h"

using namespace td;

TEST(MultiTimeout, bug) {
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(DEBUG));

ConcurrentScheduler sched;
int threads_n = 0;
sched.init(threads_n);

sched.start();
std::unique_ptr<MultiTimeout> multi_timeout;
struct Data {
MultiTimeout *multi_timeout;
};
Data data;

{
auto guard = sched.get_current_guard();
multi_timeout = std::make_unique<MultiTimeout>();
data.multi_timeout = multi_timeout.get();
multi_timeout->set_callback([](void *void_data, int64 key) {
auto &data = *reinterpret_cast<Data *>(void_data);
if (key == 1) {
data.multi_timeout->cancel_timeout(key + 1);
data.multi_timeout->set_timeout_in(key + 2, 1);
} else {
Scheduler::instance()->finish();
}
});
multi_timeout->set_callback_data(&data);
multi_timeout->set_timeout_in(1, 1);
multi_timeout->set_timeout_in(2, 2);
}

while (sched.run_main(10)) {
// empty
}
sched.finish();
}

0 comments on commit b40df8c

Please sign in to comment.