Skip to content

Commit 6cbe9d9

Browse files
siyingfacebook-github-bot
authored andcommitted
Make StringAppendOperatorTest a parameterized test (facebook#6930)
Summary: StringAppendOperatorTest right now runs in a mode where RUN_ALL_TESTS() is executed twice for the same test but different settings. This creates a problem with a tool that expects every test to run once. Fix it by using a parameterized test instead. Pull Request resolved: facebook#6930 Test Plan: Run the test and see it passed. Reviewed By: ltamasi Differential Revision: D21874145 fbshipit-source-id: 55520b2d7f1ba9f3cba1e2d087fe86f43fb06145
1 parent 31bd2d7 commit 6cbe9d9

File tree

1 file changed

+40
-33
lines changed

1 file changed

+40
-33
lines changed

utilities/merge_operators/string_append/stringappend_test.cc

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under both the GPLv2 (found in the
3+
// COPYING file in the root directory) and Apache 2.0 License
4+
// (found in the LICENSE.Apache file in the root directory).
5+
//
6+
17
/**
28
* An persistent map : key -> (list of strings), using rocksdb merge.
39
* This file is a test-harness / use-case for the StringAppendOperator.
@@ -6,16 +12,19 @@
612
* Copyright 2013 Facebook, Inc.
713
*/
814

15+
#include "utilities/merge_operators/string_append/stringappend.h"
16+
917
#include <iostream>
1018
#include <map>
19+
#include <tuple>
1120

21+
#include "port/stack_trace.h"
1222
#include "rocksdb/db.h"
1323
#include "rocksdb/merge_operator.h"
1424
#include "rocksdb/utilities/db_ttl.h"
1525
#include "test_util/testharness.h"
1626
#include "util/random.h"
1727
#include "utilities/merge_operators.h"
18-
#include "utilities/merge_operators/string_append/stringappend.h"
1928
#include "utilities/merge_operators/string_append/stringappend2.h"
2029

2130
using namespace ROCKSDB_NAMESPACE;
@@ -108,12 +117,26 @@ class StringLists {
108117

109118

110119
// The class for unit-testing
111-
class StringAppendOperatorTest : public testing::Test {
120+
class StringAppendOperatorTest : public testing::Test,
121+
public ::testing::WithParamInterface<bool> {
112122
public:
113123
StringAppendOperatorTest() {
114124
DestroyDB(kDbName, Options()); // Start each test with a fresh DB
115125
}
116126

127+
void SetUp() override {
128+
#ifndef ROCKSDB_LITE // TtlDb is not supported in Lite
129+
bool if_use_ttl = GetParam();
130+
if (if_use_ttl) {
131+
fprintf(stderr, "Running tests with ttl db and generic operator.\n");
132+
StringAppendOperatorTest::SetOpenDbFunction(&OpenTtlDb);
133+
return;
134+
}
135+
#endif // !ROCKSDB_LITE
136+
fprintf(stderr, "Running tests with regular db and operator.\n");
137+
StringAppendOperatorTest::SetOpenDbFunction(&OpenNormalDb);
138+
}
139+
117140
typedef std::shared_ptr<DB> (* OpenFuncPtr)(char);
118141

119142
// Allows user to open databases with different configurations.
@@ -129,7 +152,7 @@ StringAppendOperatorTest::OpenFuncPtr StringAppendOperatorTest::OpenDb = nullptr
129152

130153
// THE TEST CASES BEGIN HERE
131154

132-
TEST_F(StringAppendOperatorTest, IteratorTest) {
155+
TEST_P(StringAppendOperatorTest, IteratorTest) {
133156
auto db_ = OpenDb(',');
134157
StringLists slists(db_);
135158

@@ -220,10 +243,9 @@ TEST_F(StringAppendOperatorTest, IteratorTest) {
220243
ASSERT_EQ(res, "g1");
221244
}
222245
}
223-
224246
}
225247

226-
TEST_F(StringAppendOperatorTest, SimpleTest) {
248+
TEST_P(StringAppendOperatorTest, SimpleTest) {
227249
auto db = OpenDb(',');
228250
StringLists slists(db);
229251

@@ -238,7 +260,7 @@ TEST_F(StringAppendOperatorTest, SimpleTest) {
238260
ASSERT_EQ(res, "v1,v2,v3");
239261
}
240262

241-
TEST_F(StringAppendOperatorTest, SimpleDelimiterTest) {
263+
TEST_P(StringAppendOperatorTest, SimpleDelimiterTest) {
242264
auto db = OpenDb('|');
243265
StringLists slists(db);
244266

@@ -251,7 +273,7 @@ TEST_F(StringAppendOperatorTest, SimpleDelimiterTest) {
251273
ASSERT_EQ(res, "v1|v2|v3");
252274
}
253275

254-
TEST_F(StringAppendOperatorTest, OneValueNoDelimiterTest) {
276+
TEST_P(StringAppendOperatorTest, OneValueNoDelimiterTest) {
255277
auto db = OpenDb('!');
256278
StringLists slists(db);
257279

@@ -262,7 +284,7 @@ TEST_F(StringAppendOperatorTest, OneValueNoDelimiterTest) {
262284
ASSERT_EQ(res, "single_val");
263285
}
264286

265-
TEST_F(StringAppendOperatorTest, VariousKeys) {
287+
TEST_P(StringAppendOperatorTest, VariousKeys) {
266288
auto db = OpenDb('\n');
267289
StringLists slists(db);
268290

@@ -288,7 +310,7 @@ TEST_F(StringAppendOperatorTest, VariousKeys) {
288310
}
289311

290312
// Generate semi random keys/words from a small distribution.
291-
TEST_F(StringAppendOperatorTest, RandomMixGetAppend) {
313+
TEST_P(StringAppendOperatorTest, RandomMixGetAppend) {
292314
auto db = OpenDb(' ');
293315
StringLists slists(db);
294316

@@ -336,10 +358,9 @@ TEST_F(StringAppendOperatorTest, RandomMixGetAppend) {
336358
}
337359

338360
}
339-
340361
}
341362

342-
TEST_F(StringAppendOperatorTest, BIGRandomMixGetAppend) {
363+
TEST_P(StringAppendOperatorTest, BIGRandomMixGetAppend) {
343364
auto db = OpenDb(' ');
344365
StringLists slists(db);
345366

@@ -387,10 +408,9 @@ TEST_F(StringAppendOperatorTest, BIGRandomMixGetAppend) {
387408
}
388409

389410
}
390-
391411
}
392412

393-
TEST_F(StringAppendOperatorTest, PersistentVariousKeys) {
413+
TEST_P(StringAppendOperatorTest, PersistentVariousKeys) {
394414
// Perform the following operations in limited scope
395415
{
396416
auto db = OpenDb('\n');
@@ -457,7 +477,7 @@ TEST_F(StringAppendOperatorTest, PersistentVariousKeys) {
457477
}
458478
}
459479

460-
TEST_F(StringAppendOperatorTest, PersistentFlushAndCompaction) {
480+
TEST_P(StringAppendOperatorTest, PersistentFlushAndCompaction) {
461481
// Perform the following operations in limited scope
462482
{
463483
auto db = OpenDb('\n');
@@ -553,7 +573,7 @@ TEST_F(StringAppendOperatorTest, PersistentFlushAndCompaction) {
553573
}
554574
}
555575

556-
TEST_F(StringAppendOperatorTest, SimpleTestNullDelimiter) {
576+
TEST_P(StringAppendOperatorTest, SimpleTestNullDelimiter) {
557577
auto db = OpenDb('\0');
558578
StringLists slists(db);
559579

@@ -576,26 +596,13 @@ TEST_F(StringAppendOperatorTest, SimpleTestNullDelimiter) {
576596
ASSERT_EQ(res, checker);
577597
}
578598

599+
INSTANTIATE_TEST_CASE_P(StringAppendOperatorTest, StringAppendOperatorTest,
600+
testing::Bool());
601+
579602
} // namespace ROCKSDB_NAMESPACE
580603

581604
int main(int argc, char** argv) {
605+
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
582606
::testing::InitGoogleTest(&argc, argv);
583-
// Run with regular database
584-
int result;
585-
{
586-
fprintf(stderr, "Running tests with regular db and operator.\n");
587-
StringAppendOperatorTest::SetOpenDbFunction(&OpenNormalDb);
588-
result = RUN_ALL_TESTS();
589-
}
590-
591-
#ifndef ROCKSDB_LITE // TtlDb is not supported in Lite
592-
// Run with TTL
593-
{
594-
fprintf(stderr, "Running tests with ttl db and generic operator.\n");
595-
StringAppendOperatorTest::SetOpenDbFunction(&OpenTtlDb);
596-
result |= RUN_ALL_TESTS();
597-
}
598-
#endif // !ROCKSDB_LITE
599-
600-
return result;
607+
return RUN_ALL_TESTS();
601608
}

0 commit comments

Comments
 (0)