test_index_move: extend unit test
Double-check the changed values are seen in a newly opened store.
This commit is contained in:
@ -344,50 +344,70 @@ Yes, that would be excellent.
|
|||||||
|
|
||||||
// Index it into a store.
|
// Index it into a store.
|
||||||
TempDir tempdir;
|
TempDir tempdir;
|
||||||
auto store{Store::make_new(tempdir.path(), tempdir2.path() + "/Maildir")};
|
::time_t msg3changed{};
|
||||||
assert_valid_result(store);
|
Store::Id msg3id;
|
||||||
|
|
||||||
store->indexer().start({});
|
{
|
||||||
size_t n{};
|
auto store{Store::make_new(tempdir.path(), tempdir2.path() + "/Maildir")};
|
||||||
while (store->indexer().is_running()) {
|
assert_valid_result(store);
|
||||||
std::this_thread::sleep_for(100ms);
|
|
||||||
g_assert_cmpuint(n++,<=,25);
|
store->indexer().start({});
|
||||||
|
size_t n{};
|
||||||
|
while (store->indexer().is_running()) {
|
||||||
|
std::this_thread::sleep_for(100ms);
|
||||||
|
g_assert_cmpuint(n++,<=,25);
|
||||||
|
}
|
||||||
|
g_assert_true(!store->indexer().is_running());
|
||||||
|
const auto& prog{store->indexer().progress()};
|
||||||
|
g_assert_cmpuint(prog.updated,==,1);
|
||||||
|
g_assert_cmpuint(store->size(), ==, 1);
|
||||||
|
g_assert_false(store->empty());
|
||||||
|
|
||||||
|
// Find the message
|
||||||
|
auto qr = store->run_query("path:" + tempdir2.path() + "/Maildir/a/new/msg");
|
||||||
|
assert_valid_result(qr);
|
||||||
|
g_assert_cmpuint(qr->size(),==,1);
|
||||||
|
|
||||||
|
const auto msg = qr->begin().message();
|
||||||
|
g_assert_true(!!msg);
|
||||||
|
|
||||||
|
// Check the message
|
||||||
|
const auto oldpath{msg->path()};
|
||||||
|
assert_equal(msg->subject(), "Re: multi-eq hash tables");
|
||||||
|
g_assert_true(msg->docid() != 0);
|
||||||
|
g_debug("%s", msg->sexp().to_string().c_str());
|
||||||
|
|
||||||
|
// Move the message from new->cur
|
||||||
|
const auto oldchanged{msg->changed()};
|
||||||
|
std::this_thread::sleep_for(1s); /* ctime should change */
|
||||||
|
const auto msgs3 = store->move_message(msg->docid(), {}, Flags::Seen);
|
||||||
|
assert_valid_result(msgs3);
|
||||||
|
g_assert_true(msgs3->size() == 1);
|
||||||
|
auto&& msg3_opt{store->find_message(msgs3->at(0).first/*id*/)};
|
||||||
|
g_assert_true(!!msg3_opt);
|
||||||
|
auto&& msg3{std::move(*msg3_opt)};
|
||||||
|
msg3id = msg3.docid();
|
||||||
|
assert_equal(msg3.maildir(), "/a");
|
||||||
|
assert_equal(msg3.path(), tempdir2.path() + "/Maildir/a/cur/msg:2,S");
|
||||||
|
g_assert_true(::access(msg3.path().c_str(), R_OK)==0);
|
||||||
|
g_assert_false(::access(oldpath.c_str(), R_OK)==0);
|
||||||
|
|
||||||
|
// ensure that the changed value was updated properly.
|
||||||
|
msg3changed = msg->changed();
|
||||||
|
const auto changeddiff(msg3changed - oldchanged);
|
||||||
|
g_assert_true(changeddiff > 0 && changeddiff <= 2);
|
||||||
|
g_assert_cmpuint(store->size(), ==, 1);
|
||||||
}
|
}
|
||||||
g_assert_true(!store->indexer().is_running());
|
|
||||||
const auto& prog{store->indexer().progress()};
|
|
||||||
g_assert_cmpuint(prog.updated,==,1);
|
|
||||||
g_assert_cmpuint(store->size(), ==, 1);
|
|
||||||
g_assert_false(store->empty());
|
|
||||||
|
|
||||||
// Find the message
|
// ensure the values are properly stored.
|
||||||
auto qr = store->run_query("path:" + tempdir2.path() + "/Maildir/a/new/msg");
|
{
|
||||||
assert_valid_result(qr);
|
const auto store2{Store::make(tempdir.path())};
|
||||||
g_assert_cmpuint(qr->size(),==,1);
|
assert_valid_result(store2);
|
||||||
|
const auto msg4 = store2->find_message(msg3id);
|
||||||
const auto msg = qr->begin().message();
|
g_assert_true(!!msg4);
|
||||||
g_assert_true(!!msg);
|
assert_equal(msg4->path(), tempdir2.path() + "/Maildir/a/cur/msg:2,S");
|
||||||
|
g_assert_cmpuint(msg4->changed(), ==, msg3changed);
|
||||||
// Check the message
|
}
|
||||||
const auto oldpath{msg->path()};
|
|
||||||
assert_equal(msg->subject(), "Re: multi-eq hash tables");
|
|
||||||
g_assert_true(msg->docid() != 0);
|
|
||||||
g_debug("%s", msg->sexp().to_string().c_str());
|
|
||||||
|
|
||||||
// Move the message from new->cur
|
|
||||||
std::this_thread::sleep_for(1s); /* ctime should change */
|
|
||||||
const auto msgs3 = store->move_message(msg->docid(), {}, Flags::Seen);
|
|
||||||
assert_valid_result(msgs3);
|
|
||||||
g_assert_true(msgs3->size() == 1);
|
|
||||||
auto&& msg3_opt{store->find_message(msgs3->at(0).first/*id*/)};
|
|
||||||
g_assert_true(!!msg3_opt);
|
|
||||||
auto&& msg3{std::move(*msg3_opt)};
|
|
||||||
|
|
||||||
assert_equal(msg3.maildir(), "/a");
|
|
||||||
assert_equal(msg3.path(), tempdir2.path() + "/Maildir/a/cur/msg:2,S");
|
|
||||||
g_assert_true(::access(msg3.path().c_str(), R_OK)==0);
|
|
||||||
g_assert_false(::access(oldpath.c_str(), R_OK)==0);
|
|
||||||
|
|
||||||
g_debug("%s", msg3.sexp().to_string().c_str()); g_assert_cmpuint(store->size(), ==, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user