Skip to content

Commit

Permalink
extend the disk-io stress test to ensure more invariants
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Oct 20, 2024
1 parent 1d644d1 commit 8011f10
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions tools/disk_io_stress_test.cpp
Original file line number Diff line number Diff line change
@@ -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)
@@ -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)
@@ -285,8 +299,7 @@ int run_test(test_case const& t)
throw std::runtime_error("read buffer mismatch!");
}
});

++outstanding;
++job_idx;
}
}

@@ -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)
@@ -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());
@@ -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
}

0 comments on commit 8011f10

Please sign in to comment.