test fixes
This commit is contained in:
parent
e2e82edefb
commit
33e8e0890b
@ -109,45 +109,42 @@ void file_manager::close_all(const std::string &api_path) {
|
||||
return;
|
||||
}
|
||||
|
||||
handles = iter->second->get_handles();
|
||||
auto closeable_file = iter->second;
|
||||
|
||||
for (auto &handle : handles) {
|
||||
open_file_lookup_[api_path]->remove(handle);
|
||||
handles = closeable_file->get_handles();
|
||||
for (auto handle : handles) {
|
||||
closeable_file->remove(handle);
|
||||
}
|
||||
|
||||
auto file = open_file_lookup_.at(api_path);
|
||||
open_file_lookup_.erase(api_path);
|
||||
file_lock.unlock();
|
||||
|
||||
file->close();
|
||||
closeable_file->close();
|
||||
}
|
||||
|
||||
void file_manager::close_timed_out_files() {
|
||||
unique_recur_mutex_lock file_lock(open_file_mtx_);
|
||||
auto closeable_list = std::accumulate(
|
||||
open_file_lookup_.begin(), open_file_lookup_.end(),
|
||||
std::vector<std::string>{}, [](auto items, const auto &item) -> auto {
|
||||
if (item.second->get_open_file_count() == 0U &&
|
||||
item.second->can_close()) {
|
||||
items.emplace_back(item.first);
|
||||
}
|
||||
return items;
|
||||
});
|
||||
|
||||
std::vector<std::shared_ptr<i_closeable_open_file>> open_files{};
|
||||
for (const auto &api_path : closeable_list) {
|
||||
auto closeable_file = open_file_lookup_.at(api_path);
|
||||
open_file_lookup_.erase(api_path);
|
||||
open_files.push_back(closeable_file);
|
||||
auto closeable_list =
|
||||
std::accumulate(open_file_lookup_.begin(), open_file_lookup_.end(),
|
||||
std::vector<std::shared_ptr<i_closeable_open_file>>{},
|
||||
[](auto items, const auto &item) -> auto {
|
||||
if (item.second->get_open_file_count() == 0U &&
|
||||
item.second->can_close()) {
|
||||
items.push_back(item.second);
|
||||
}
|
||||
return items;
|
||||
});
|
||||
for (const auto &closeable_file : closeable_list) {
|
||||
open_file_lookup_.erase(closeable_file->get_api_path());
|
||||
}
|
||||
closeable_list.clear();
|
||||
file_lock.unlock();
|
||||
|
||||
for (auto &closeable_file : open_files) {
|
||||
for (auto &closeable_file : closeable_list) {
|
||||
closeable_file->close();
|
||||
event_system::instance().raise<download_timeout>(
|
||||
closeable_file->get_api_path());
|
||||
}
|
||||
closeable_list.clear();
|
||||
}
|
||||
|
||||
auto file_manager::create(const std::string &api_path, api_meta_map &meta,
|
||||
|
@ -1315,6 +1315,9 @@ TEST(file_manager,
|
||||
EXPECT_CALL(mp, set_item_meta("/test_open.txt", META_SOURCE, _))
|
||||
.WillOnce(Return(api_error::success));
|
||||
|
||||
EXPECT_CALL(*non_writeable, has_handle(1)).WillOnce([]() -> bool {
|
||||
return true;
|
||||
});
|
||||
EXPECT_TRUE(fm.get_open_file(handle, true, f));
|
||||
EXPECT_NE(non_writeable.get(), f.get());
|
||||
EXPECT_EQ(std::size_t(1U), fm.get_open_file_count());
|
||||
@ -1495,6 +1498,10 @@ TEST(file_manager, open_file_creates_source_path_if_empty) {
|
||||
#else
|
||||
EXPECT_EQ(api_error::success, fm.open(of, O_RDWR, handle, f));
|
||||
#endif
|
||||
EXPECT_CALL(*of, has_handle(1)).Times(2).WillRepeatedly([]() -> bool {
|
||||
return true;
|
||||
});
|
||||
|
||||
EXPECT_TRUE(fm.get_open_file(1U, true, f));
|
||||
EXPECT_EQ(std::size_t(1U), fm.get_open_file_count());
|
||||
EXPECT_TRUE(f);
|
||||
@ -1546,6 +1553,8 @@ TEST(file_manager, open_file_first_file_handle_is_not_zero) {
|
||||
#else
|
||||
EXPECT_EQ(api_error::success, fm.open(of, O_RDWR, handle, f));
|
||||
#endif
|
||||
EXPECT_CALL(*of, has_handle(1)).WillOnce([]() -> bool { return true; });
|
||||
|
||||
EXPECT_TRUE(fm.get_open_file(1U, true, f));
|
||||
EXPECT_GT(handle, std::uint64_t(0U));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user