Reduce flake SnapshotFallback test (#1237)
Fixed the wait period, this should ensure at least one snapshot was made. Also cleaned up the checking around this. And also better corruption.
This commit is contained in:
parent
9c51dbbb01
commit
bd1852f407
@ -736,34 +736,49 @@ TEST_P(DurabilityTest, SnapshotPeriodic) {
|
|||||||
// NOLINTNEXTLINE(hicpp-special-member-functions)
|
// NOLINTNEXTLINE(hicpp-special-member-functions)
|
||||||
TEST_P(DurabilityTest, SnapshotFallback) {
|
TEST_P(DurabilityTest, SnapshotFallback) {
|
||||||
// Create snapshot.
|
// Create snapshot.
|
||||||
std::size_t current_number_of_snapshots = 0;
|
std::size_t number_to_save;
|
||||||
{
|
{
|
||||||
|
// DEVNOTE_1: assumes that snapshot disk write takes less than this
|
||||||
|
auto const expected_write_time = std::chrono::milliseconds(750);
|
||||||
|
auto const snapshot_interval = std::chrono::milliseconds(3000);
|
||||||
|
|
||||||
std::unique_ptr<memgraph::storage::Storage> store(new memgraph::storage::InMemoryStorage(
|
std::unique_ptr<memgraph::storage::Storage> store(new memgraph::storage::InMemoryStorage(
|
||||||
{.items = {.properties_on_edges = GetParam()},
|
{.items = {.properties_on_edges = GetParam()},
|
||||||
.durability = {.storage_directory = storage_directory,
|
.durability = {
|
||||||
.snapshot_wal_mode = memgraph::storage::Config::Durability::SnapshotWalMode::PERIODIC_SNAPSHOT,
|
.storage_directory = storage_directory,
|
||||||
.snapshot_interval = std::chrono::milliseconds(3000)}}));
|
.snapshot_wal_mode = memgraph::storage::Config::Durability::SnapshotWalMode::PERIODIC_SNAPSHOT,
|
||||||
CreateBaseDataset(store.get(), GetParam());
|
.snapshot_interval = snapshot_interval,
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(3500));
|
.snapshot_retention_count = 10, // We don't anticipate that we make this many
|
||||||
current_number_of_snapshots = GetSnapshotsList().size();
|
}}));
|
||||||
ASSERT_GE(current_number_of_snapshots, 1);
|
|
||||||
CreateExtendedDataset(store.get());
|
auto const ensure_snapshot_is_written = [&](auto &&func) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
|
auto const pre_count = GetSnapshotsList().size();
|
||||||
|
func();
|
||||||
|
// wait long enough to ensure at least one CreateSnapshot has been invoked
|
||||||
|
// DEVNOTE_2: no guarantee that it completed, see DEVNOTE_1
|
||||||
|
std::this_thread::sleep_for(snapshot_interval + expected_write_time);
|
||||||
|
auto const post_count = GetSnapshotsList().size();
|
||||||
|
// validate at least one snapshot has happened...hence must have written the writes from func
|
||||||
|
ASSERT_GT(post_count, pre_count) << "No snapshot exists to capture the last transaction";
|
||||||
|
// TODO: maybe double check by looking at InMemoryStorage's commit log,
|
||||||
|
// its oldest active should be newer than the transaction used when running `func`
|
||||||
|
};
|
||||||
|
|
||||||
|
ensure_snapshot_is_written([&]() { CreateBaseDataset(store.get(), GetParam()); });
|
||||||
|
number_to_save = GetSnapshotsList().size();
|
||||||
|
ensure_snapshot_is_written([&]() { CreateExtendedDataset(store.get()); });
|
||||||
}
|
}
|
||||||
|
|
||||||
auto prev_number_of_snapshots = current_number_of_snapshots;
|
|
||||||
auto snapshots = GetSnapshotsList();
|
|
||||||
current_number_of_snapshots = snapshots.size();
|
|
||||||
ASSERT_GE(current_number_of_snapshots, prev_number_of_snapshots + 1);
|
|
||||||
ASSERT_EQ(GetBackupSnapshotsList().size(), 0);
|
ASSERT_EQ(GetBackupSnapshotsList().size(), 0);
|
||||||
ASSERT_EQ(GetWalsList().size(), 0);
|
ASSERT_EQ(GetWalsList().size(), 0);
|
||||||
ASSERT_EQ(GetBackupWalsList().size(), 0);
|
ASSERT_EQ(GetBackupWalsList().size(), 0);
|
||||||
|
|
||||||
// Destroy snapshots.
|
// Destroy snapshots.
|
||||||
{
|
{
|
||||||
// protect the last, destroy the rest
|
auto snapshots = GetSnapshotsList();
|
||||||
|
// snapshots order newest first, destroy the newest, preserve number_to_save so that we ONLY_BASE
|
||||||
auto it = snapshots.begin();
|
auto it = snapshots.begin();
|
||||||
auto const e = snapshots.end() - 1;
|
auto const e = snapshots.end() - number_to_save;
|
||||||
for (; it != e; ++it) {
|
for (; it != e; ++it) {
|
||||||
CorruptSnapshot(*it);
|
CorruptSnapshot(*it);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user