Skip to content

Commit

Permalink
fix ut
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Oct 11, 2023
1 parent e9f0dfd commit 8acab38
Show file tree
Hide file tree
Showing 6 changed files with 642 additions and 629 deletions.
2 changes: 1 addition & 1 deletion src/replica/test/mutation_log_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ TEST_P(mutation_log_test, reset_from_while_writing)
ASSERT_EQ(actual.size(), expected.size());
}

TEST_F(mutation_log_test, gc_slog)
TEST_P(mutation_log_test, gc_slog)
{
// Remove the slog dir and create a new one.
const std::string slog_dir("./slog_test");
Expand Down
10 changes: 5 additions & 5 deletions src/test_util/test_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "test_util.h"

#include <gtest/gtest-spi.h>
#include <stdint.h>
#include <chrono>
#include <ostream>
#include <thread>
Expand All @@ -42,10 +41,11 @@ namespace pegasus {
void create_local_test_file(const std::string &full_name, dsn::replication::file_meta *fm)
{
ASSERT_NE(fm, nullptr);
auto s = rocksdb::WriteStringToFile(rocksdb::Env::Default(),
rocksdb::Slice("write some data."),
full_name,
/* should_sync */ true);
auto s =
rocksdb::WriteStringToFile(dsn::utils::PegasusEnv(dsn::utils::FileDataType::kSensitive),
rocksdb::Slice("write some data."),
full_name,
/* should_sync */ true);
ASSERT_TRUE(s.ok()) << s.ToString();
fm->name = full_name;
ASSERT_EQ(dsn::ERR_OK, dsn::utils::filesystem::md5sum(full_name, fm->md5));
Expand Down
17 changes: 16 additions & 1 deletion src/test_util/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

#pragma once

#include <cstdint>
#include <gtest/gtest.h>
#include <functional>
#include <string>

#include "utils/env.h"
#include "utils/flags.h"
#include "utils/test_macros.h"

Expand All @@ -40,7 +42,20 @@ namespace pegasus {
class encrypt_data_test_base : public testing::TestWithParam<bool>
{
public:
encrypt_data_test_base() { FLAGS_encrypt_data_at_rest = GetParam(); }
encrypt_data_test_base()
{
FLAGS_encrypt_data_at_rest = GetParam();
// The size of an actual encrypted file should plus kEncryptionHeaderkSize bytes if consider
// it as kNonSensitive.
if (FLAGS_encrypt_data_at_rest) {
_extra_encrypted_file_size = dsn::utils::kEncryptionHeaderkSize;
}
}

uint64_t extra_encrypted_file_size() const { return _extra_encrypted_file_size; }

private:
uint64_t _extra_encrypted_file_size = 0;
};

void create_local_test_file(const std::string &full_name, dsn::replication::file_meta *fm);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#pragma once

#include <algorithm>
#include <algorithm> // IWYU pragma: keep
#include <cstddef>
#include <functional>
#include <memory>
Expand Down
23 changes: 6 additions & 17 deletions src/utils/test/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include <string>

#include "test_util/test_util.h"
#include "utils/enum_helper.h"
#include "utils/env.h"
#include "utils/filesystem.h"
#include "utils/flags.h"
Expand Down Expand Up @@ -87,16 +86,6 @@ TEST(env_test, get_env)

class env_file_test : public pegasus::encrypt_data_test_base
{
public:
env_file_test() : pegasus::encrypt_data_test_base()
{
// The size of an actual encrypted file should plus kEncryptionHeaderkSize bytes if consider
// it as kNonSensitive.
if (FLAGS_encrypt_data_at_rest) {
_extra_size = dsn::utils::kEncryptionHeaderkSize;
}
}
uint64_t _extra_size = 0;
};

INSTANTIATE_TEST_CASE_P(, env_file_test, ::testing::Values(false, true));
Expand Down Expand Up @@ -134,7 +123,7 @@ TEST_P(env_file_test, encrypt_file_2_files)
ASSERT_EQ(kFileContentSize, wfile_size);
ASSERT_TRUE(dsn::utils::filesystem::file_size(
kEncryptedFileName, dsn::utils::FileDataType::kNonSensitive, wfile_size));
ASSERT_EQ(kFileContentSize + _extra_size, wfile_size);
ASSERT_EQ(kFileContentSize + extra_encrypted_file_size(), wfile_size);
// Check file content.
std::string data;
s = rocksdb::ReadFileToString(dsn::utils::PegasusEnv(dsn::utils::FileDataType::kSensitive),
Expand Down Expand Up @@ -174,7 +163,7 @@ TEST_P(env_file_test, encrypt_file_1_file)
ASSERT_EQ(kFileContentSize, wfile_size);
ASSERT_TRUE(dsn::utils::filesystem::file_size(
kFileName, dsn::utils::FileDataType::kNonSensitive, wfile_size));
ASSERT_EQ(kFileContentSize + _extra_size, wfile_size);
ASSERT_EQ(kFileContentSize + extra_encrypted_file_size(), wfile_size);
// Check file content.
std::string data;
s = rocksdb::ReadFileToString(
Expand Down Expand Up @@ -204,7 +193,7 @@ TEST_P(env_file_test, copy_file)
ASSERT_EQ(kFileContentSize, wfile_size);
ASSERT_TRUE(dsn::utils::filesystem::file_size(
kFileName, dsn::utils::FileDataType::kNonSensitive, wfile_size));
ASSERT_EQ(kFileContentSize + _extra_size, wfile_size);
ASSERT_EQ(kFileContentSize + extra_encrypted_file_size(), wfile_size);

// Check copy_file(src_fname, dst_fname, total_size).
// Loop twice to check overwrite.
Expand All @@ -218,7 +207,7 @@ TEST_P(env_file_test, copy_file)
ASSERT_EQ(kFileContentSize, wfile_size);
ASSERT_TRUE(dsn::utils::filesystem::file_size(
kCopyFileName, dsn::utils::FileDataType::kNonSensitive, wfile_size));
ASSERT_EQ(kFileContentSize + _extra_size, wfile_size);
ASSERT_EQ(kFileContentSize + extra_encrypted_file_size(), wfile_size);
// Check file content.
std::string data;
s = rocksdb::ReadFileToString(
Expand Down Expand Up @@ -249,7 +238,7 @@ TEST_P(env_file_test, copy_file_by_size)
ASSERT_EQ(kFileContentSize, wfile_size);
ASSERT_TRUE(dsn::utils::filesystem::file_size(
kFileName, dsn::utils::FileDataType::kNonSensitive, wfile_size));
ASSERT_EQ(kFileContentSize + _extra_size, wfile_size);
ASSERT_EQ(kFileContentSize + extra_encrypted_file_size(), wfile_size);

// Check copy_file_by_size(src_fname, dst_fname, limit_size).
struct test_case
Expand All @@ -271,7 +260,7 @@ TEST_P(env_file_test, copy_file_by_size)
ASSERT_EQ(test.expect_size, actual_size);
ASSERT_TRUE(dsn::utils::filesystem::file_size(
kCopyFileName, dsn::utils::FileDataType::kNonSensitive, wfile_size));
ASSERT_EQ(test.expect_size + _extra_size, wfile_size);
ASSERT_EQ(test.expect_size + extra_encrypted_file_size(), wfile_size);
// Check file content.
std::string data;
s = rocksdb::ReadFileToString(
Expand Down
Loading

0 comments on commit 8acab38

Please sign in to comment.