Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend the disk-io stress test to ensure more invariants #7756

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 39 additions & 11 deletions tools/disk_io_stress_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,21 @@ int run_test(test_case const& t)
std::vector<char> write_buffer(lt::default_block_size);

int outstanding = 0;
std::set<int> in_flight;

lt::add_torrent_params atp;

disk_io->async_check_files(tor, &atp, lt::aux::vector<std::string, lt::file_index_t>{}
, [&](lt::status_t, lt::storage_error const&) { --outstanding; });
int job_idx = 0;
in_flight.insert(job_idx);
++outstanding;
disk_io->async_check_files(tor, &atp, lt::aux::vector<std::string, lt::file_index_t>{}
, [&, job_idx](lt::status_t, lt::storage_error const&) {
TORRENT_ASSERT(in_flight.count(job_idx));
in_flight.erase(job_idx);
TORRENT_ASSERT(outstanding > 0);
--outstanding;
});
++job_idx;
disk_io->submit_jobs();

while (outstanding > 0)
Expand Down Expand Up @@ -266,8 +275,13 @@ int run_test(test_case const& t)
auto const req = blocks_to_read.back();
blocks_to_read.erase(blocks_to_read.end() - 1);

disk_io->async_read(tor, req, [&, req](lt::disk_buffer_holder h, lt::storage_error const& ec)
in_flight.insert(job_idx);
++outstanding;
disk_io->async_read(tor, req, [&, req, job_idx](lt::disk_buffer_holder h, lt::storage_error const& ec)
{
TORRENT_ASSERT(in_flight.count(job_idx));
in_flight.erase(job_idx);
TORRENT_ASSERT(outstanding > 0);
--outstanding;
++job_counter;
if (ec)
Expand All @@ -285,8 +299,7 @@ int run_test(test_case const& t)
throw std::runtime_error("read buffer mismatch!");
}
});

++outstanding;
++job_idx;
}
}

Expand All @@ -297,9 +310,14 @@ int run_test(test_case const& t)

generate_block_fill(req, {write_buffer.data(), lt::default_block_size});

in_flight.insert(job_idx);
++outstanding;
disk_io->async_write(tor, req, write_buffer.data()
, {}, [&](lt::storage_error const& ec)
, {}, [&, job_idx](lt::storage_error const& ec)
{
TORRENT_ASSERT(in_flight.count(job_idx));
in_flight.erase(job_idx);
TORRENT_ASSERT(outstanding > 0);
--outstanding;
++job_counter;
if (ec)
Expand All @@ -310,6 +328,7 @@ int run_test(test_case const& t)
throw std::runtime_error("async_write failed");
}
});
++job_idx;
if (t.flags & test_mode::read_random_order)
{
std::uniform_int_distribution<> d(0, blocks_to_read.end_index());
Expand All @@ -326,28 +345,37 @@ int run_test(test_case const& t)
std::uniform_int_distribution<> d(0, blocks_to_read.end_index());
blocks_to_read.insert(blocks_to_read.begin() + d(random_engine), req);
}

++outstanding;
}

if ((t.flags & test_mode::flush_files) && (job_counter % 500) == 499)
{
disk_io->async_release_files(tor, [&]()
in_flight.insert(job_idx);
++outstanding;
disk_io->async_release_files(tor, [&, job_idx]()
{
TORRENT_ASSERT(in_flight.count(job_idx));
in_flight.erase(job_idx);
TORRENT_ASSERT(outstanding > 0);
--outstanding;
++job_counter;
});
++job_idx;
}

if ((t.flags & test_mode::clear_pieces) && (job_counter % 300) == 299)
{
lt::piece_index_t const p = blocks_to_write.front().piece;
disk_io->async_clear_piece(tor, p, [&](lt::piece_index_t)
in_flight.insert(job_idx);
++outstanding;
disk_io->async_clear_piece(tor, p, [&, job_idx](lt::piece_index_t)
{
TORRENT_ASSERT(in_flight.count(job_idx));
in_flight.erase(job_idx);
TORRENT_ASSERT(outstanding > 0);
--outstanding;
++job_counter;
});
++outstanding;
++job_idx;
// TODO: technically all blocks for this piece should be added
// to blocks_to_write again here
}
Expand Down
Loading