aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@yahoo-inc.com>2017-05-03 11:49:42 +0000
committerTor Egge <Tor.Egge@yahoo-inc.com>2017-05-03 13:05:28 +0000
commitbc1cc38ea080a21e9f0745b919988e0b84be8f99 (patch)
tree5c9a063540b7a5363a4c4cfcb3c84a595c818e3b /searchlib/src/tests
parentba01c1cacf6789a9e9cfbce6393131e4736d9711 (diff)
Extend unit test to test new methods.
Diffstat (limited to 'searchlib/src/tests')
-rw-r--r--searchlib/src/tests/common/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp63
1 files changed, 56 insertions, 7 deletions
diff --git a/searchlib/src/tests/common/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp b/searchlib/src/tests/common/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp
index 98436364ea0..e8183319fd4 100644
--- a/searchlib/src/tests/common/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp
+++ b/searchlib/src/tests/common/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp
@@ -82,7 +82,7 @@ TEST_F("testExecute", Fixture) {
}
-TEST_F("require that task with same id are serialized", Fixture)
+TEST_F("require that task with same component id are serialized", Fixture)
{
std::shared_ptr<TestObj> tv(std::make_shared<TestObj>());
EXPECT_EQUAL(0, tv->_val);
@@ -96,7 +96,7 @@ TEST_F("require that task with same id are serialized", Fixture)
EXPECT_EQUAL(42, tv->_val);
}
-TEST_F("require that task with different ids are not serialized", Fixture)
+TEST_F("require that task with different component ids are not serialized", Fixture)
{
int tryCnt = 0;
for (tryCnt = 0; tryCnt < 100; ++tryCnt) {
@@ -119,7 +119,7 @@ TEST_F("require that task with different ids are not serialized", Fixture)
}
-TEST_F("require that task with same string id are serialized", Fixture)
+TEST_F("require that task with same string component id are serialized", Fixture)
{
std::shared_ptr<TestObj> tv(std::make_shared<TestObj>());
EXPECT_EQUAL(0, tv->_val);
@@ -134,15 +134,17 @@ TEST_F("require that task with same string id are serialized", Fixture)
EXPECT_EQUAL(42, tv->_val);
}
-TEST_F("require that task with different string ids are not serialized",
- Fixture)
+namespace
+{
+
+int detectSerializeFailure(Fixture &f, vespalib::stringref altComponentId, int tryLimit)
{
int tryCnt = 0;
- for (tryCnt = 0; tryCnt < 100; ++tryCnt) {
+ for (tryCnt = 0; tryCnt < tryLimit; ++tryCnt) {
std::shared_ptr<TestObj> tv(std::make_shared<TestObj>());
EXPECT_EQUAL(0, tv->_val);
f._threads.execute("0", [=]() { usleep(2000); tv->modify(0, 14); });
- f._threads.execute("2", [=]() { tv->modify(14, 42); });
+ f._threads.execute(altComponentId, [=]() { tv->modify(14, 42); });
tv->wait(2);
if (tv->_fail != 1) {
continue;
@@ -154,10 +156,44 @@ TEST_F("require that task with different string ids are not serialized",
EXPECT_EQUAL(14, tv->_val);
break;
}
+ return tryCnt;
+}
+
+vespalib::string makeAltComponentId(Fixture &f)
+{
+ int tryCnt = 0;
+ char altComponentId[20];
+ uint32_t executorId0 = f._threads.getExecutorId("0");
+ for (tryCnt = 1; tryCnt < 100; ++tryCnt) {
+ sprintf(altComponentId, "%d", tryCnt);
+ if (f._threads.getExecutorId(altComponentId) == executorId0) {
+ break;
+ }
+ }
+ EXPECT_TRUE(tryCnt < 100);
+ return altComponentId;
+}
+
+}
+
+TEST_F("require that task with different string component ids are not serialized",
+ Fixture)
+{
+ int tryCnt = detectSerializeFailure(f, "2", 100);
EXPECT_TRUE(tryCnt < 100);
}
+TEST_F("require that task with different string component ids mapping to the same executor id are serialized",
+ Fixture)
+{
+ vespalib::string altComponentId = makeAltComponentId(f);
+ LOG(info, "second string component id is \"%s\"", altComponentId.c_str());
+ int tryCnt = detectSerializeFailure(f, altComponentId, 100);
+ EXPECT_TRUE(tryCnt == 100);
+}
+
+
TEST_F("require that execute works with const lambda", Fixture)
{
int i = 5;
@@ -187,6 +223,19 @@ TEST_F("require that execute works with reference to lambda", Fixture)
EXPECT_EQUAL(5, i);
}
+TEST_F("require that executeLambda works", Fixture)
+{
+ int i = 5;
+ std::vector<int> res;
+ const auto lambda = [i, &res]() mutable
+ { res.push_back(i--); res.push_back(i--); };
+ f._threads.executeLambda(0, lambda);
+ f._threads.sync();
+ std::vector<int> exp({5, 4});
+ EXPECT_EQUAL(exp, res);
+ EXPECT_EQUAL(5, i);
+}
+
} // namespace common
} // namespace search