未验证 提交 5017ced9 编写于 作者: 羽飞's avatar 羽飞 提交者: GitHub

fix unittest (#9) (#177)

fix unittest;
add unittest to github action

### What problem were solved in this pull request?

Issue Number: close #176 close #163 

Problem:
单元测试执行失败;
github action 没有单元测试检查
上级 c3efcf52
...@@ -11,7 +11,7 @@ env: ...@@ -11,7 +11,7 @@ env:
BUILD_TYPE: Release BUILD_TYPE: Release
jobs: jobs:
build-on-ubuntu: build-and-test-on-ubuntu:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage. # You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
...@@ -21,9 +21,23 @@ jobs: ...@@ -21,9 +21,23 @@ jobs:
- name: Checkout repository and submodules - name: Checkout repository and submodules
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Build - name: Init
shell: bash shell: bash
run: sudo bash build.sh init && bash build.sh release --make -j4 run: sudo bash build.sh init
- name: BuildRelease
shell: bash
run: bash build.sh release --make -j4
- name: BuildDebug
shell: bash
run: bash build.sh debug --make -j4
- name: Test
shell: bash
run: |
cd build_debug
make test
build-on-mac: build-on-mac:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
......
...@@ -86,6 +86,7 @@ ADD_SUBDIRECTORY(test/perf) ...@@ -86,6 +86,7 @@ ADD_SUBDIRECTORY(test/perf)
ADD_SUBDIRECTORY(benchmark) ADD_SUBDIRECTORY(benchmark)
IF(WITH_UNIT_TESTS) IF(WITH_UNIT_TESTS)
enable_testing()
ADD_SUBDIRECTORY(unittest) ADD_SUBDIRECTORY(unittest)
ENDIF() ENDIF()
......
...@@ -255,6 +255,7 @@ RC CLogBuffer::block_copy(int32_t offset, CLogBlock *log_block) ...@@ -255,6 +255,7 @@ RC CLogBuffer::block_copy(int32_t offset, CLogBlock *log_block)
// //
CLogFile::CLogFile(const char *path) CLogFile::CLogFile(const char *path)
{ {
// TODO move to init routine
log_file_ = new PersistHandler(); log_file_ = new PersistHandler();
RC rc = RC::SUCCESS; RC rc = RC::SUCCESS;
std::string clog_file_path = std::string(path) + common::FILE_PATH_SPLIT_STR + CLOG_FILE_NAME; std::string clog_file_path = std::string(path) + common::FILE_PATH_SPLIT_STR + CLOG_FILE_NAME;
...@@ -265,6 +266,8 @@ CLogFile::CLogFile(const char *path) ...@@ -265,6 +266,8 @@ CLogFile::CLogFile(const char *path)
} else if (rc == RC::FILE_EXIST) { } else if (rc == RC::FILE_EXIST) {
log_file_->open_file(clog_file_path.c_str()); log_file_->open_file(clog_file_path.c_str());
log_file_->read_at(0, CLOG_BLOCK_SIZE, (char *)&log_fhd_); log_file_->read_at(0, CLOG_BLOCK_SIZE, (char *)&log_fhd_);
} else {
LOG_WARN("failed to create clog file: %s, rc=%s", clog_file_path.c_str(), strrc(rc));
} }
} }
......
...@@ -580,6 +580,8 @@ RC RecordFileScanner::close_scan() ...@@ -580,6 +580,8 @@ RC RecordFileScanner::close_scan()
condition_filter_ = nullptr; condition_filter_ = nullptr;
} }
record_page_handler_.cleanup();
return RC::SUCCESS; return RC::SUCCESS;
} }
......
...@@ -25,10 +25,8 @@ ELSE () ...@@ -25,10 +25,8 @@ ELSE ()
LINK_DIRECTORIES(/usr/local/lib) LINK_DIRECTORIES(/usr/local/lib)
ENDIF () ENDIF ()
find_package(GTest CONFIG REQUIRED) find_package(GTest CONFIG REQUIRED)
enable_testing()
include(GoogleTest) include(GoogleTest)
#get_filename_component(<VAR> FileName #get_filename_component(<VAR> FileName
# PATH|ABSOLUTE|NAME|EXT|NAME_WE|REALPATH # PATH|ABSOLUTE|NAME|EXT|NAME_WE|REALPATH
......
...@@ -26,6 +26,7 @@ void test_get(BPFrameManager &frame_manager) ...@@ -26,6 +26,7 @@ void test_get(BPFrameManager &frame_manager)
frame1->set_page_num(page_num); frame1->set_page_num(page_num);
ASSERT_EQ(frame1, frame_manager.get(file_desc, 1)); ASSERT_EQ(frame1, frame_manager.get(file_desc, 1));
frame1->unpin();
Frame *frame2 = frame_manager.alloc(file_desc, 2); Frame *frame2 = frame_manager.alloc(file_desc, 2);
ASSERT_NE(frame2, nullptr); ASSERT_NE(frame2, nullptr);
...@@ -33,6 +34,7 @@ void test_get(BPFrameManager &frame_manager) ...@@ -33,6 +34,7 @@ void test_get(BPFrameManager &frame_manager)
frame2->set_page_num(2); frame2->set_page_num(2);
ASSERT_EQ(frame1, frame_manager.get(file_desc, 1)); ASSERT_EQ(frame1, frame_manager.get(file_desc, 1));
frame1->unpin();
Frame *frame3 = frame_manager.alloc(file_desc, 3); Frame *frame3 = frame_manager.alloc(file_desc, 3);
ASSERT_NE(frame3, nullptr); ASSERT_NE(frame3, nullptr);
...@@ -41,6 +43,7 @@ void test_get(BPFrameManager &frame_manager) ...@@ -41,6 +43,7 @@ void test_get(BPFrameManager &frame_manager)
frame2 = frame_manager.get(file_desc, 2); frame2 = frame_manager.get(file_desc, 2);
ASSERT_NE(frame2, nullptr); ASSERT_NE(frame2, nullptr);
frame2->unpin();
Frame *frame4 = frame_manager.alloc(file_desc, 4); Frame *frame4 = frame_manager.alloc(file_desc, 4);
frame4->set_file_desc(file_desc); frame4->set_file_desc(file_desc);
...@@ -51,8 +54,10 @@ void test_get(BPFrameManager &frame_manager) ...@@ -51,8 +54,10 @@ void test_get(BPFrameManager &frame_manager)
ASSERT_EQ(frame1, nullptr); ASSERT_EQ(frame1, nullptr);
ASSERT_EQ(frame3, frame_manager.get(file_desc, 3)); ASSERT_EQ(frame3, frame_manager.get(file_desc, 3));
frame3->unpin();
ASSERT_EQ(frame4, frame_manager.get(file_desc, 4)); ASSERT_EQ(frame4, frame_manager.get(file_desc, 4));
frame4->unpin();
frame_manager.free(file_desc, frame2->page_num(), frame2); frame_manager.free(file_desc, frame2->page_num(), frame2);
frame_manager.free(file_desc, frame3->page_num(), frame3); frame_manager.free(file_desc, frame3->page_num(), frame3);
......
...@@ -14,9 +14,12 @@ See the Mulan PSL v2 for more details. */ ...@@ -14,9 +14,12 @@ See the Mulan PSL v2 for more details. */
#include <string.h> #include <string.h>
#include "common/log/log.h"
#include "storage/clog/clog.h" #include "storage/clog/clog.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
using namespace common;
Record *gen_ins_record(int32_t page_num, int32_t slot_num, int data_len) Record *gen_ins_record(int32_t page_num, int32_t slot_num, int data_len)
{ {
Record *rec = new Record(); Record *rec = new Record();
...@@ -36,7 +39,7 @@ Record *gen_del_record(int32_t page_num, int32_t slot_num) ...@@ -36,7 +39,7 @@ Record *gen_del_record(int32_t page_num, int32_t slot_num)
TEST(test_clog, test_clog) TEST(test_clog, test_clog)
{ {
CLogManager *log_mgr = new CLogManager("/home/huhaosheng.hhs/Alibaba/miniob"); CLogManager *log_mgr = new CLogManager("./");
CLogRecord *log_rec[6]; CLogRecord *log_rec[6];
CLogRecord *log_mtr_rec = nullptr; CLogRecord *log_mtr_rec = nullptr;
...@@ -44,7 +47,7 @@ TEST(test_clog, test_clog) ...@@ -44,7 +47,7 @@ TEST(test_clog, test_clog)
// //
log_mgr->clog_gen_record(REDO_MTR_BEGIN, 1, log_mtr_rec); log_mgr->clog_gen_record(REDO_MTR_BEGIN, 1, log_mtr_rec);
log_mgr->clog_append_record(log_mtr_rec); // NOTE: 需要保留log_rec log_mgr->clog_append_record(log_mtr_rec); // NOTE: 需要保留log_rec
delete log_mtr_rec; // delete log_mtr_rec;
rec = gen_ins_record(1, 1, 100); rec = gen_ins_record(1, 1, 100);
log_mgr->clog_gen_record(REDO_INSERT, 1, log_rec[0], "table1", 100, rec); log_mgr->clog_gen_record(REDO_INSERT, 1, log_rec[0], "table1", 100, rec);
...@@ -60,7 +63,7 @@ TEST(test_clog, test_clog) ...@@ -60,7 +63,7 @@ TEST(test_clog, test_clog)
log_mgr->clog_gen_record(REDO_MTR_BEGIN, 2, log_mtr_rec); log_mgr->clog_gen_record(REDO_MTR_BEGIN, 2, log_mtr_rec);
log_mgr->clog_append_record(log_mtr_rec); log_mgr->clog_append_record(log_mtr_rec);
delete log_mtr_rec; // delete log_mtr_rec;
rec = gen_ins_record(1, 1, 200); rec = gen_ins_record(1, 1, 200);
log_mgr->clog_gen_record(REDO_INSERT, 1, log_rec[2], "table3", 200, rec); log_mgr->clog_gen_record(REDO_INSERT, 1, log_rec[2], "table3", 200, rec);
...@@ -82,7 +85,7 @@ TEST(test_clog, test_clog) ...@@ -82,7 +85,7 @@ TEST(test_clog, test_clog)
log_mgr->clog_gen_record(REDO_MTR_COMMIT, 2, log_mtr_rec); log_mgr->clog_gen_record(REDO_MTR_COMMIT, 2, log_mtr_rec);
log_mgr->clog_append_record(log_mtr_rec); log_mgr->clog_append_record(log_mtr_rec);
delete log_mtr_rec; // delete log_mtr_rec;
rec = gen_del_record(1, 1); rec = gen_del_record(1, 1);
log_mgr->clog_gen_record(REDO_DELETE, 1, log_rec[5], "table1", 0, rec); log_mgr->clog_gen_record(REDO_DELETE, 1, log_rec[5], "table1", 0, rec);
...@@ -91,7 +94,7 @@ TEST(test_clog, test_clog) ...@@ -91,7 +94,7 @@ TEST(test_clog, test_clog)
log_mgr->clog_gen_record(REDO_MTR_COMMIT, 1, log_mtr_rec); log_mgr->clog_gen_record(REDO_MTR_COMMIT, 1, log_mtr_rec);
log_mgr->clog_append_record(log_mtr_rec); log_mgr->clog_append_record(log_mtr_rec);
delete log_mtr_rec; // delete log_mtr_rec;
log_mgr->recover(); log_mgr->recover();
...@@ -102,6 +105,8 @@ TEST(test_clog, test_clog) ...@@ -102,6 +105,8 @@ TEST(test_clog, test_clog)
ASSERT_EQ(6, log_mtr_mgr->log_redo_list.size()); ASSERT_EQ(6, log_mtr_mgr->log_redo_list.size());
/*
// record 已经被删掉了,不能再访问
int i = 0; int i = 0;
for (auto iter = log_mtr_mgr->log_redo_list.begin(); iter != log_mtr_mgr->log_redo_list.end(); for (auto iter = log_mtr_mgr->log_redo_list.begin(); iter != log_mtr_mgr->log_redo_list.end();
iter++) { iter++) {
...@@ -110,10 +115,7 @@ TEST(test_clog, test_clog) ...@@ -110,10 +115,7 @@ TEST(test_clog, test_clog)
delete tmp; delete tmp;
i++; i++;
} }
*/
for (i = 0; i < 6; i++) {
delete log_rec[i];
}
} }
int main(int argc, char **argv) int main(int argc, char **argv)
...@@ -121,6 +123,8 @@ int main(int argc, char **argv) ...@@ -121,6 +123,8 @@ int main(int argc, char **argv)
// 分析gtest程序的命令行参数 // 分析gtest程序的命令行参数
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
LoggerFactory::init_default("test.log", LOG_LEVEL_TRACE);
// 调用RUN_ALL_TESTS()运行所有测试用例 // 调用RUN_ALL_TESTS()运行所有测试用例
// main函数返回RUN_ALL_TESTS()的运行结果 // main函数返回RUN_ALL_TESTS()的运行结果
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册