rocksdb/utilities/agg_merge/agg_merge_test.cc
Peter Dillinger e466173d5c Print stack traces on frozen tests in CI (#10828)
Summary:
Instead of existing calls to ps from gnu_parallel, call a new wrapper that does ps, looks for unit test like processes, and uses pstack or gdb to print thread stack traces. Also, using `ps -wwf` instead of `ps -wf` ensures output is not cut off.

For security, CircleCI runs with security restrictions on ptrace (/proc/sys/kernel/yama/ptrace_scope = 1), and this change adds a work-around to `InstallStackTraceHandler()` (only used by testing tools) to allow any process from the same user to debug it. (I've also touched >100 files to ensure all the unit tests call this function.)

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10828

Test Plan: local manual + temporary infinite loop in a unit test to observe in CircleCI

Reviewed By: hx235

Differential Revision: D40447634

Pulled By: pdillinger

fbshipit-source-id: 718a4c4a5b54fa0f9af2d01a446162b45e5e84e1
2022-10-18 00:35:35 -07:00

136 lines
4.8 KiB
C++

// Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
#include "rocksdb/utilities/agg_merge.h"
#include <gtest/gtest.h>
#include <memory>
#include "db/db_test_util.h"
#include "rocksdb/options.h"
#include "test_util/testharness.h"
#include "utilities/agg_merge/agg_merge.h"
#include "utilities/agg_merge/test_agg_merge.h"
namespace ROCKSDB_NAMESPACE {
class AggMergeTest : public DBTestBase {
public:
AggMergeTest() : DBTestBase("agg_merge_db_test", /*env_do_fsync=*/true) {}
};
TEST_F(AggMergeTest, TestUsingMergeOperator) {
ASSERT_OK(AddAggregator("sum", std::make_unique<SumAggregator>()));
ASSERT_OK(AddAggregator("last3", std::make_unique<Last3Aggregator>()));
ASSERT_OK(AddAggregator("mul", std::make_unique<MultipleAggregator>()));
Options options = CurrentOptions();
options.merge_operator = GetAggMergeOperator();
Reopen(options);
std::string v = EncodeHelper::EncodeFuncAndInt("sum", 10);
ASSERT_OK(Merge("foo", v));
v = EncodeHelper::EncodeFuncAndInt("sum", 20);
ASSERT_OK(Merge("foo", v));
v = EncodeHelper::EncodeFuncAndInt("sum", 15);
ASSERT_OK(Merge("foo", v));
v = EncodeHelper::EncodeFuncAndList("last3", {"a", "b"});
ASSERT_OK(Merge("bar", v));
v = EncodeHelper::EncodeFuncAndList("last3", {"c", "d", "e"});
ASSERT_OK(Merge("bar", v));
ASSERT_OK(Flush());
v = EncodeHelper::EncodeFuncAndList("last3", {"f"});
ASSERT_OK(Merge("bar", v));
// Test Put() without aggregation type.
v = EncodeHelper::EncodeFuncAndInt(kUnnamedFuncName, 30);
ASSERT_OK(Put("foo2", v));
v = EncodeHelper::EncodeFuncAndInt("sum", 10);
ASSERT_OK(Merge("foo2", v));
v = EncodeHelper::EncodeFuncAndInt("sum", 20);
ASSERT_OK(Merge("foo2", v));
EXPECT_EQ(EncodeHelper::EncodeFuncAndInt("sum", 45), Get("foo"));
EXPECT_EQ(EncodeHelper::EncodeFuncAndList("last3", {"f", "c", "d"}),
Get("bar"));
EXPECT_EQ(EncodeHelper::EncodeFuncAndInt("sum", 60), Get("foo2"));
// Test changing aggregation type
v = EncodeHelper::EncodeFuncAndInt("mul", 10);
ASSERT_OK(Put("bar2", v));
v = EncodeHelper::EncodeFuncAndInt("mul", 20);
ASSERT_OK(Merge("bar2", v));
v = EncodeHelper::EncodeFuncAndInt("sum", 30);
ASSERT_OK(Merge("bar2", v));
v = EncodeHelper::EncodeFuncAndInt("sum", 40);
ASSERT_OK(Merge("bar2", v));
EXPECT_EQ(EncodeHelper::EncodeFuncAndInt("sum", 10 * 20 + 30 + 40),
Get("bar2"));
// Changing aggregation type with partial merge
v = EncodeHelper::EncodeFuncAndInt("mul", 10);
ASSERT_OK(Merge("foo3", v));
ASSERT_OK(Flush());
v = EncodeHelper::EncodeFuncAndInt("mul", 10);
ASSERT_OK(Merge("foo3", v));
v = EncodeHelper::EncodeFuncAndInt("mul", 10);
ASSERT_OK(Merge("foo3", v));
v = EncodeHelper::EncodeFuncAndInt("sum", 10);
ASSERT_OK(Merge("foo3", v));
ASSERT_OK(Flush());
EXPECT_EQ(EncodeHelper::EncodeFuncAndInt("sum", 10 * 10 * 10 + 10),
Get("foo3"));
// Merge after full merge
v = EncodeHelper::EncodeFuncAndInt("sum", 1);
ASSERT_OK(Merge("foo4", v));
v = EncodeHelper::EncodeFuncAndInt("sum", 2);
ASSERT_OK(Merge("foo4", v));
ASSERT_OK(Flush());
v = EncodeHelper::EncodeFuncAndInt("sum", 3);
ASSERT_OK(Merge("foo4", v));
v = EncodeHelper::EncodeFuncAndInt("sum", 4);
ASSERT_OK(Merge("foo4", v));
ASSERT_OK(Flush());
ASSERT_OK(db_->CompactRange(CompactRangeOptions(), nullptr, nullptr));
v = EncodeHelper::EncodeFuncAndInt("sum", 5);
ASSERT_OK(Merge("foo4", v));
EXPECT_EQ(EncodeHelper::EncodeFuncAndInt("sum", 15), Get("foo4"));
// Test unregistered function name
v = EncodeAggFuncAndPayloadNoCheck("non_existing", "1");
ASSERT_OK(Merge("bar3", v));
std::string v1;
v1 = EncodeAggFuncAndPayloadNoCheck("non_existing", "invalid");
;
ASSERT_OK(Merge("bar3", v1));
EXPECT_EQ(EncodeAggFuncAndPayloadNoCheck(kErrorFuncName,
EncodeHelper::EncodeList({v, v1})),
Get("bar3"));
// invalidate input
ASSERT_OK(EncodeAggFuncAndPayload("sum", "invalid", v));
ASSERT_OK(Merge("bar4", v));
v1 = EncodeHelper::EncodeFuncAndInt("sum", 20);
ASSERT_OK(Merge("bar4", v1));
std::string aggregated_value = Get("bar4");
Slice func, payload;
ASSERT_TRUE(ExtractAggFuncAndValue(aggregated_value, func, payload));
EXPECT_EQ(kErrorFuncName, func);
std::vector<Slice> decoded_list;
ASSERT_TRUE(ExtractList(payload, decoded_list));
ASSERT_EQ(2, decoded_list.size());
ASSERT_EQ(v, decoded_list[0]);
ASSERT_EQ(v1, decoded_list[1]);
}
} // namespace ROCKSDB_NAMESPACE
int main(int argc, char** argv) {
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}