optimized storage test

This commit is contained in:
Arvid Norberg 2010-08-08 07:53:47 +00:00
parent ceb5700588
commit 897e615a86
2 changed files with 78 additions and 49 deletions

View File

@ -494,7 +494,7 @@ void stop_web_server()
{
if (web_server && web_ios)
{
web_ios->stop();
web_ios->post(boost::bind(&io_service::stop, web_ios));
web_server->join();
web_server.reset();
web_ios = 0;

View File

@ -57,6 +57,12 @@ char* piece0 = page_aligned_allocator::malloc(piece_size);
char* piece1 = page_aligned_allocator::malloc(piece_size);
char* piece2 = page_aligned_allocator::malloc(piece_size);
void signal_bool(bool* b, char const* string)
{
*b = true;
std::cerr << string << std::endl;
}
void on_read_piece(int ret, disk_io_job const& j, char const* data, int size)
{
std::cerr << "on_read_piece piece: " << j.piece << std::endl;
@ -69,11 +75,19 @@ void on_check_resume_data(int ret, disk_io_job const& j, bool* done)
std::cerr << "on_check_resume_data ret: " << ret;
switch (ret)
{
case 0: std::cerr << " success" << std::endl; break;
case -1: std::cerr << " need full check" << std::endl; break;
case -2: std::cerr << " disk error: " << j.str
<< " file: " << j.error_file << std::endl; break;
case -3: std::cerr << " aborted" << std::endl; break;
case piece_manager::no_error:
std::cerr << " success" << std::endl;
break;
case piece_manager::fatal_disk_error:
std::cerr << " disk error: " << j.str
<< " file: " << j.error_file << std::endl;
break;
case piece_manager::need_full_check:
std::cerr << " need full check" << std::endl;
break;
case piece_manager::disk_check_aborted:
std::cerr << " aborted" << std::endl;
break;
}
*done = true;
}
@ -84,11 +98,23 @@ void on_check_files(int ret, disk_io_job const& j, bool* done)
switch (ret)
{
case 0: std::cerr << " done" << std::endl; *done = true; break;
case -1: std::cerr << " current slot: " << j.piece << " have: " << j.offset << std::endl; break;
case -2: std::cerr << " disk error: " << j.str
<< " file: " << j.error_file << std::endl; *done = true; break;
case -3: std::cerr << " aborted" << std::endl; *done = true; break;
case piece_manager::no_error:
std::cerr << " done" << std::endl;
*done = true;
break;
case piece_manager::fatal_disk_error:
std::cerr << " disk error: " << j.str
<< " file: " << j.error_file << std::endl;
*done = true;
break;
case piece_manager::need_full_check:
std::cerr << " current slot: " << j.piece
<< " have: " << j.offset << std::endl;
break;
case piece_manager::disk_check_aborted:
std::cerr << " aborted" << std::endl;
*done = true;
break;
}
}
@ -105,11 +131,12 @@ void on_read(int ret, disk_io_job const& j, bool* done)
}
}
void on_move_storage(int ret, disk_io_job const& j, std::string path)
void on_move_storage(int ret, bool* done, disk_io_job const& j, std::string path)
{
std::cerr << "on_move_storage ret: " << ret << " path: " << j.str << std::endl;
TEST_EQUAL(ret, 0);
TEST_EQUAL(j.str, path);
*done = true;
}
void print_error(int ret, boost::scoped_ptr<storage_interface> const& s)
@ -390,6 +417,22 @@ void run_elevator_test()
}
}
void run_until(io_service& ios, bool const& done)
{
while (!done)
{
ios.reset();
error_code ec;
ios.run_one(ec);
if (ec)
{
std::cerr << "run_one: " << ec.message() << std::endl;
return;
}
std::cerr << "done: " << done << std::endl;
}
}
void run_storage_tests(boost::intrusive_ptr<torrent_info> info
, file_storage& fs
, std::string const& test_path
@ -514,12 +557,9 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
TEST_CHECK(exists(combine_path(test_path, "temp_storage/test1.tmp")));
TEST_CHECK(!exists(combine_path(test_path, "part0")));
boost::function<void(int, disk_io_job const&)> none;
pm->async_rename_file(0, "part0", none);
test_sleep(1000);
ios.reset();
ios.poll(ec);
if (ec) std::cerr << "poll: " << ec.message() << std::endl;
done = false;
pm->async_rename_file(0, "part0", boost::bind(&signal_bool, &done, "rename_file"));
run_until(ios, done);
TEST_CHECK(!exists(combine_path(test_path, "temp_storage/test1.tmp")));
TEST_CHECK(!exists(combine_path(test_path, "temp_storage2")));
@ -527,13 +567,11 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
// test move_storage with two files in the root directory
TEST_CHECK(exists(combine_path(test_path, "temp_storage")));
pm->async_move_storage(combine_path(test_path, "temp_storage2")
, boost::bind(on_move_storage, _1, _2, combine_path(test_path, "temp_storage2")));
test_sleep(2000);
ios.reset();
ios.poll(ec);
if (ec) std::cerr << "poll: " << ec.message() << std::endl;
done = false;
pm->async_move_storage(combine_path(test_path, "temp_storage2")
, boost::bind(on_move_storage, _1, &done, _2, combine_path(test_path, "temp_storage2")));
run_until(ios, done);
if (fs.num_files() > 1)
{
@ -542,12 +580,9 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
}
TEST_CHECK(exists(combine_path(test_path, "temp_storage2/part0")));
pm->async_move_storage(test_path, boost::bind(on_move_storage, _1, _2, test_path));
test_sleep(2000);
ios.reset();
ios.poll(ec);
if (ec) std::cerr << "poll: " << ec.message() << std::endl;
done = false;
pm->async_move_storage(test_path, boost::bind(on_move_storage, _1, &done, _2, test_path));
run_until(ios, done);
TEST_CHECK(exists(combine_path(test_path, "part0")));
TEST_CHECK(!exists(combine_path(test_path, "temp_storage2/temp_storage")));
@ -561,21 +596,19 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
pm->async_read(r, boost::bind(&on_read_piece, _1, _2, piece1, block_size));
r.piece = 2;
pm->async_read(r, boost::bind(&on_read_piece, _1, _2, piece2, block_size));
pm->async_release_files(none);
std::cerr << "async_release_files" << std::endl;
done = false;
pm->async_release_files(boost::bind(&signal_bool, &done, "async_release_files"));
run_until(ios, done);
pm->async_rename_file(0, "temp_storage/test1.tmp", none);
test_sleep(2000);
ios.reset();
ios.poll(ec);
if (ec) std::cerr << "poll: " << ec.message() << std::endl;
std::cerr << "async_rename_file" << std::endl;
done = false;
pm->async_rename_file(0, "temp_storage/test1.tmp", boost::bind(&signal_bool, &done, "rename_file"));
run_until(ios, done);
TEST_CHECK(!exists(combine_path(test_path, "part0")));
TEST_CHECK(exists(combine_path(test_path, "temp_storage/test1.tmp")));
ios.reset();
ios.poll(ec);
if (ec) std::cerr << "poll: " << ec.message() << std::endl;
io.abort();
io.join();
remove_all(combine_path(test_path, "temp_storage2"), ec);
@ -637,14 +670,15 @@ namespace
{
std::cerr << "check_files_fill_array ret: " << ret
<< " piece: " << j.piece
<< " have: " << j.offset
<< " str: " << j.str
<< " e: " << j.error.message()
<< std::endl;
if (j.offset >= 0) array[j.offset] = true;
if (ret != -1)
if (ret != piece_manager::need_full_check)
{
*done = true;
return;
}
}
}
@ -714,14 +748,9 @@ void test_check_files(std::string const& test_path
bool pieces[4] = {false, false, false, false};
done = false;
pm->async_check_files(boost::bind(&check_files_fill_array, _1, _2, pieces, &done));
while (!done)
{
ios.reset();
ios.run_one(ec);
if (ec) std::cerr << "run_one: " << ec.message() << std::endl;
}
run_until(ios, done);
TEST_EQUAL(pieces[0], true);
TEST_EQUAL(pieces[1], false);
TEST_EQUAL(pieces[2], false);