Mvcc - unit test infrastructure setup
Summary:
Gradicek's Mvcc test have seen the following changes:
- provided a test infrastructure (fixture and macros) to facilitate testing and increase readability
- split tests into multi-transaction update, VersionList::find and general Mvcc testing
- multi-transaction update tests have been refactored (i *think* nothing got deleted, but it was a mess so I don't guarantee)
- changed all multithreaded tests to be single-threaded because multiple threads were not necessary
- changed transaction naming from T5, T8, T10 to T1, T2... for consistency with actual transaction indices
What still needs to be done:
- Gleich and Gradicek need to review the infrastructure (possible improvements)
- multi-transaction update tests need to be addressed by Gradicek (see "TODO gradicek" in code, discuss with Flor)
- the wiki/draw.io documentation needs to be updated. it is not imperative that all the tests be drawn in draw.io, only the general infrastructure explained. perhaps only a few examples drawn. Gradicek discuss with Flor
- Gleich see the "TODO Gleich" lines in the diff and discuss with flor
Suggested workflow:
- review this diff, hopefully land (before resolving all the TODOs)
- discard D169
- Gradicek and Gleich address the TODOs
- Flor reviews the results (in following diffs)
Reviewers: dgleich, matej.gradicek, buda
Reviewed By: matej.gradicek, buda
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D348
2017-05-05 17:05:56 +08:00
|
|
|
#include <vector>
|
2017-03-24 16:52:25 +08:00
|
|
|
|
2018-10-04 21:23:07 +08:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "mvcc/common/version.hpp"
|
|
|
|
#include "mvcc/single_node/record.hpp"
|
|
|
|
#include "mvcc/single_node/version_list.hpp"
|
2018-10-09 17:09:10 +08:00
|
|
|
#include "transactions/single_node/engine.hpp"
|
2017-11-29 23:03:42 +08:00
|
|
|
#include "transactions/transaction.hpp"
|
2018-05-30 19:00:25 +08:00
|
|
|
#include "utils/thread/sync.hpp"
|
2017-03-24 16:52:25 +08:00
|
|
|
|
2017-06-12 16:21:19 +08:00
|
|
|
#include "mvcc_gc_common.hpp"
|
|
|
|
|
Mvcc - unit test infrastructure setup
Summary:
Gradicek's Mvcc test have seen the following changes:
- provided a test infrastructure (fixture and macros) to facilitate testing and increase readability
- split tests into multi-transaction update, VersionList::find and general Mvcc testing
- multi-transaction update tests have been refactored (i *think* nothing got deleted, but it was a mess so I don't guarantee)
- changed all multithreaded tests to be single-threaded because multiple threads were not necessary
- changed transaction naming from T5, T8, T10 to T1, T2... for consistency with actual transaction indices
What still needs to be done:
- Gleich and Gradicek need to review the infrastructure (possible improvements)
- multi-transaction update tests need to be addressed by Gradicek (see "TODO gradicek" in code, discuss with Flor)
- the wiki/draw.io documentation needs to be updated. it is not imperative that all the tests be drawn in draw.io, only the general infrastructure explained. perhaps only a few examples drawn. Gradicek discuss with Flor
- Gleich see the "TODO Gleich" lines in the diff and discuss with flor
Suggested workflow:
- review this diff, hopefully land (before resolving all the TODOs)
- discard D169
- Gradicek and Gleich address the TODOs
- Flor reviews the results (in following diffs)
Reviewers: dgleich, matej.gradicek, buda
Reviewed By: matej.gradicek, buda
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D348
2017-05-05 17:05:56 +08:00
|
|
|
TEST(MVCC, Deadlock) {
|
2018-10-09 17:09:10 +08:00
|
|
|
tx::Engine engine;
|
2017-03-24 16:52:25 +08:00
|
|
|
|
2017-06-12 16:21:19 +08:00
|
|
|
auto t0 = engine.Begin();
|
2018-10-11 17:37:59 +08:00
|
|
|
mvcc::VersionList<Prop> version_list1(*t0, 0);
|
|
|
|
mvcc::VersionList<Prop> version_list2(*t0, 1);
|
2017-11-29 23:03:42 +08:00
|
|
|
engine.Commit(*t0);
|
2017-03-24 16:52:25 +08:00
|
|
|
|
2017-06-12 16:21:19 +08:00
|
|
|
auto t1 = engine.Begin();
|
|
|
|
auto t2 = engine.Begin();
|
2017-03-29 18:37:58 +08:00
|
|
|
|
Mvcc - unit test infrastructure setup
Summary:
Gradicek's Mvcc test have seen the following changes:
- provided a test infrastructure (fixture and macros) to facilitate testing and increase readability
- split tests into multi-transaction update, VersionList::find and general Mvcc testing
- multi-transaction update tests have been refactored (i *think* nothing got deleted, but it was a mess so I don't guarantee)
- changed all multithreaded tests to be single-threaded because multiple threads were not necessary
- changed transaction naming from T5, T8, T10 to T1, T2... for consistency with actual transaction indices
What still needs to be done:
- Gleich and Gradicek need to review the infrastructure (possible improvements)
- multi-transaction update tests need to be addressed by Gradicek (see "TODO gradicek" in code, discuss with Flor)
- the wiki/draw.io documentation needs to be updated. it is not imperative that all the tests be drawn in draw.io, only the general infrastructure explained. perhaps only a few examples drawn. Gradicek discuss with Flor
- Gleich see the "TODO Gleich" lines in the diff and discuss with flor
Suggested workflow:
- review this diff, hopefully land (before resolving all the TODOs)
- discard D169
- Gradicek and Gleich address the TODOs
- Flor reviews the results (in following diffs)
Reviewers: dgleich, matej.gradicek, buda
Reviewed By: matej.gradicek, buda
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D348
2017-05-05 17:05:56 +08:00
|
|
|
version_list1.update(*t1);
|
|
|
|
version_list2.update(*t2);
|
2018-05-30 19:00:25 +08:00
|
|
|
EXPECT_THROW(version_list1.update(*t2), utils::LockTimeoutException);
|
2017-04-10 18:12:40 +08:00
|
|
|
}
|
|
|
|
|
Mvcc - unit test infrastructure setup
Summary:
Gradicek's Mvcc test have seen the following changes:
- provided a test infrastructure (fixture and macros) to facilitate testing and increase readability
- split tests into multi-transaction update, VersionList::find and general Mvcc testing
- multi-transaction update tests have been refactored (i *think* nothing got deleted, but it was a mess so I don't guarantee)
- changed all multithreaded tests to be single-threaded because multiple threads were not necessary
- changed transaction naming from T5, T8, T10 to T1, T2... for consistency with actual transaction indices
What still needs to be done:
- Gleich and Gradicek need to review the infrastructure (possible improvements)
- multi-transaction update tests need to be addressed by Gradicek (see "TODO gradicek" in code, discuss with Flor)
- the wiki/draw.io documentation needs to be updated. it is not imperative that all the tests be drawn in draw.io, only the general infrastructure explained. perhaps only a few examples drawn. Gradicek discuss with Flor
- Gleich see the "TODO Gleich" lines in the diff and discuss with flor
Suggested workflow:
- review this diff, hopefully land (before resolving all the TODOs)
- discard D169
- Gradicek and Gleich address the TODOs
- Flor reviews the results (in following diffs)
Reviewers: dgleich, matej.gradicek, buda
Reviewed By: matej.gradicek, buda
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D348
2017-05-05 17:05:56 +08:00
|
|
|
// TODO Gleich: move this test to mvcc_gc???
|
|
|
|
// check that we don't delete records when we re-link
|
2017-04-10 18:12:40 +08:00
|
|
|
TEST(MVCC, UpdateDontDelete) {
|
|
|
|
std::atomic<int> count{0};
|
|
|
|
{
|
2018-10-09 17:09:10 +08:00
|
|
|
tx::Engine engine;
|
2017-06-12 16:21:19 +08:00
|
|
|
auto t1 = engine.Begin();
|
2018-10-11 17:37:59 +08:00
|
|
|
mvcc::VersionList<DestrCountRec> version_list(*t1, 0, count);
|
2017-11-29 23:03:42 +08:00
|
|
|
engine.Commit(*t1);
|
2017-04-10 18:12:40 +08:00
|
|
|
|
2017-06-12 16:21:19 +08:00
|
|
|
auto t2 = engine.Begin();
|
2017-04-10 18:12:40 +08:00
|
|
|
version_list.update(*t2);
|
2017-11-29 23:03:42 +08:00
|
|
|
engine.Abort(*t2);
|
2017-04-10 18:12:40 +08:00
|
|
|
EXPECT_EQ(count, 0);
|
|
|
|
|
2017-06-12 16:21:19 +08:00
|
|
|
auto t3 = engine.Begin();
|
2017-04-10 18:12:40 +08:00
|
|
|
|
|
|
|
// Update re-links the node and shouldn't clear it yet.
|
|
|
|
version_list.update(*t3);
|
|
|
|
EXPECT_EQ(count, 0);
|
|
|
|
|
Mvcc - unit test infrastructure setup
Summary:
Gradicek's Mvcc test have seen the following changes:
- provided a test infrastructure (fixture and macros) to facilitate testing and increase readability
- split tests into multi-transaction update, VersionList::find and general Mvcc testing
- multi-transaction update tests have been refactored (i *think* nothing got deleted, but it was a mess so I don't guarantee)
- changed all multithreaded tests to be single-threaded because multiple threads were not necessary
- changed transaction naming from T5, T8, T10 to T1, T2... for consistency with actual transaction indices
What still needs to be done:
- Gleich and Gradicek need to review the infrastructure (possible improvements)
- multi-transaction update tests need to be addressed by Gradicek (see "TODO gradicek" in code, discuss with Flor)
- the wiki/draw.io documentation needs to be updated. it is not imperative that all the tests be drawn in draw.io, only the general infrastructure explained. perhaps only a few examples drawn. Gradicek discuss with Flor
- Gleich see the "TODO Gleich" lines in the diff and discuss with flor
Suggested workflow:
- review this diff, hopefully land (before resolving all the TODOs)
- discard D169
- Gradicek and Gleich address the TODOs
- Flor reviews the results (in following diffs)
Reviewers: dgleich, matej.gradicek, buda
Reviewed By: matej.gradicek, buda
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D348
2017-05-05 17:05:56 +08:00
|
|
|
// TODO Gleich: why don't we also test that remove doesn't delete?
|
2017-11-29 23:03:42 +08:00
|
|
|
engine.Commit(*t3);
|
2017-04-10 18:12:40 +08:00
|
|
|
}
|
|
|
|
EXPECT_EQ(count, 3);
|
2017-03-24 16:52:25 +08:00
|
|
|
}
|
|
|
|
|
2017-04-14 23:32:59 +08:00
|
|
|
// Check that we get the oldest record.
|
|
|
|
TEST(MVCC, Oldest) {
|
2018-10-09 17:09:10 +08:00
|
|
|
tx::Engine engine;
|
2017-06-12 16:21:19 +08:00
|
|
|
auto t1 = engine.Begin();
|
2018-10-11 17:37:59 +08:00
|
|
|
mvcc::VersionList<Prop> version_list(*t1, 0);
|
2017-04-14 23:32:59 +08:00
|
|
|
auto first = version_list.Oldest();
|
|
|
|
EXPECT_NE(first, nullptr);
|
Mvcc - unit test infrastructure setup
Summary:
Gradicek's Mvcc test have seen the following changes:
- provided a test infrastructure (fixture and macros) to facilitate testing and increase readability
- split tests into multi-transaction update, VersionList::find and general Mvcc testing
- multi-transaction update tests have been refactored (i *think* nothing got deleted, but it was a mess so I don't guarantee)
- changed all multithreaded tests to be single-threaded because multiple threads were not necessary
- changed transaction naming from T5, T8, T10 to T1, T2... for consistency with actual transaction indices
What still needs to be done:
- Gleich and Gradicek need to review the infrastructure (possible improvements)
- multi-transaction update tests need to be addressed by Gradicek (see "TODO gradicek" in code, discuss with Flor)
- the wiki/draw.io documentation needs to be updated. it is not imperative that all the tests be drawn in draw.io, only the general infrastructure explained. perhaps only a few examples drawn. Gradicek discuss with Flor
- Gleich see the "TODO Gleich" lines in the diff and discuss with flor
Suggested workflow:
- review this diff, hopefully land (before resolving all the TODOs)
- discard D169
- Gradicek and Gleich address the TODOs
- Flor reviews the results (in following diffs)
Reviewers: dgleich, matej.gradicek, buda
Reviewed By: matej.gradicek, buda
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D348
2017-05-05 17:05:56 +08:00
|
|
|
// TODO Gleich: no need to do 10 checks of the same thing
|
2017-04-14 23:32:59 +08:00
|
|
|
for (int i = 0; i < 10; ++i) {
|
2017-06-12 16:21:19 +08:00
|
|
|
engine.Advance(t1->id_);
|
2017-04-14 23:32:59 +08:00
|
|
|
version_list.update(*t1);
|
|
|
|
EXPECT_EQ(version_list.Oldest(), first);
|
|
|
|
}
|
Mvcc - unit test infrastructure setup
Summary:
Gradicek's Mvcc test have seen the following changes:
- provided a test infrastructure (fixture and macros) to facilitate testing and increase readability
- split tests into multi-transaction update, VersionList::find and general Mvcc testing
- multi-transaction update tests have been refactored (i *think* nothing got deleted, but it was a mess so I don't guarantee)
- changed all multithreaded tests to be single-threaded because multiple threads were not necessary
- changed transaction naming from T5, T8, T10 to T1, T2... for consistency with actual transaction indices
What still needs to be done:
- Gleich and Gradicek need to review the infrastructure (possible improvements)
- multi-transaction update tests need to be addressed by Gradicek (see "TODO gradicek" in code, discuss with Flor)
- the wiki/draw.io documentation needs to be updated. it is not imperative that all the tests be drawn in draw.io, only the general infrastructure explained. perhaps only a few examples drawn. Gradicek discuss with Flor
- Gleich see the "TODO Gleich" lines in the diff and discuss with flor
Suggested workflow:
- review this diff, hopefully land (before resolving all the TODOs)
- discard D169
- Gradicek and Gleich address the TODOs
- Flor reviews the results (in following diffs)
Reviewers: dgleich, matej.gradicek, buda
Reviewed By: matej.gradicek, buda
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D348
2017-05-05 17:05:56 +08:00
|
|
|
// TODO Gleich: what about remove?
|
|
|
|
// TODO Gleich: here it might make sense to write a concurrent test
|
|
|
|
// since these ops rely heavily on linkage atomicity?
|
2017-04-14 23:32:59 +08:00
|
|
|
}
|
|
|
|
|
Mvcc - unit test infrastructure setup
Summary:
Gradicek's Mvcc test have seen the following changes:
- provided a test infrastructure (fixture and macros) to facilitate testing and increase readability
- split tests into multi-transaction update, VersionList::find and general Mvcc testing
- multi-transaction update tests have been refactored (i *think* nothing got deleted, but it was a mess so I don't guarantee)
- changed all multithreaded tests to be single-threaded because multiple threads were not necessary
- changed transaction naming from T5, T8, T10 to T1, T2... for consistency with actual transaction indices
What still needs to be done:
- Gleich and Gradicek need to review the infrastructure (possible improvements)
- multi-transaction update tests need to be addressed by Gradicek (see "TODO gradicek" in code, discuss with Flor)
- the wiki/draw.io documentation needs to be updated. it is not imperative that all the tests be drawn in draw.io, only the general infrastructure explained. perhaps only a few examples drawn. Gradicek discuss with Flor
- Gleich see the "TODO Gleich" lines in the diff and discuss with flor
Suggested workflow:
- review this diff, hopefully land (before resolving all the TODOs)
- discard D169
- Gradicek and Gleich address the TODOs
- Flor reviews the results (in following diffs)
Reviewers: dgleich, matej.gradicek, buda
Reviewed By: matej.gradicek, buda
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D348
2017-05-05 17:05:56 +08:00
|
|
|
// TODO Gleich: perhaps some concurrent VersionList::find tests?
|