Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Abingcbc committed Dec 18, 2024
1 parent 4204183 commit f168c5b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
3 changes: 3 additions & 0 deletions core/unittest/config/PipelineManagerMock.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class PipelineMock : public Pipeline {
mContext.SetCreateTime(config.mCreateTime);
return (*mConfig)["valid"].asBool();
}

bool Start() { return true; }
void Stop(bool isRemoving) {}
};

class PipelineManagerMock : public PipelineManager {
Expand Down
45 changes: 23 additions & 22 deletions core/unittest/pipeline/PipelineUpdateUnittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "common/JsonUtil.h"
#include "config/PipelineConfig.h"
#include "file_server/FileServer.h"
#include "file_server/event_handler/LogInput.h"
#include "pipeline/plugin/PluginRegistry.h"
#include "unittest/Unittest.h"
Expand All @@ -31,12 +32,15 @@ namespace logtail {

class PipelineUpdateUnittest : public testing::Test {
public:
void TestRunner() const;
void TestFileServerStart() const;

protected:
static void SetUpTestCase() { PluginRegistry::GetInstance()->LoadPlugins(); }

static void TearDownTestCase() { PluginRegistry::GetInstance()->UnloadPlugins(); }
static void TearDownTestCase() {
PluginRegistry::GetInstance()->UnloadPlugins();
FileServer::GetInstance()->Stop();
}

void SetUp() override {}

Expand Down Expand Up @@ -88,29 +92,26 @@ class PipelineUpdateUnittest : public testing::Test {
})";
};

void PipelineUpdateUnittest::TestRunner() const {
{ // input_file
Json::Value nativePipelineConfigJson
= GeneratePipelineConfigJson(nativeInputConfig, nativeProcessorConfig, nativeFlusherConfig);
Json::Value goPipelineConfigJson
= GeneratePipelineConfigJson(goInputConfig, goProcessorConfig, goFlusherConfig);
auto pipelineManager = PipelineManagerMock::GetInstance();
PipelineConfigDiff diff;
PipelineConfig nativePipelineConfigObj
= PipelineConfig("test1", make_unique<Json::Value>(nativePipelineConfigJson));
nativePipelineConfigObj.Parse();
diff.mAdded.push_back(std::move(nativePipelineConfigObj));
PipelineConfig goPipelineConfigObj = PipelineConfig("test2", make_unique<Json::Value>(goPipelineConfigJson));
goPipelineConfigObj.Parse();
diff.mAdded.push_back(std::move(goPipelineConfigObj));
void PipelineUpdateUnittest::TestFileServerStart() const {
Json::Value nativePipelineConfigJson
= GeneratePipelineConfigJson(nativeInputConfig, nativeProcessorConfig, nativeFlusherConfig);
Json::Value goPipelineConfigJson = GeneratePipelineConfigJson(goInputConfig, goProcessorConfig, goFlusherConfig);
auto pipelineManager = PipelineManagerMock::GetInstance();
PipelineConfigDiff diff;
PipelineConfig nativePipelineConfigObj
= PipelineConfig("test1", make_unique<Json::Value>(nativePipelineConfigJson));
nativePipelineConfigObj.Parse();
diff.mAdded.push_back(std::move(nativePipelineConfigObj));
PipelineConfig goPipelineConfigObj = PipelineConfig("test2", make_unique<Json::Value>(goPipelineConfigJson));
goPipelineConfigObj.Parse();
diff.mAdded.push_back(std::move(goPipelineConfigObj));

pipelineManager->UpdatePipelines(diff);
APSARA_TEST_EQUAL_FATAL(2U, pipelineManager->GetAllPipelines().size());
APSARA_TEST_EQUAL_FATAL(false, LogInput::GetInstance()->mInteruptFlag);
}
pipelineManager->UpdatePipelines(diff);
APSARA_TEST_EQUAL_FATAL(2U, pipelineManager->GetAllPipelines().size());
APSARA_TEST_EQUAL_FATAL(false, LogInput::GetInstance()->mInteruptFlag);
}

UNIT_TEST_CASE(PipelineUpdateUnittest, TestRunner)
UNIT_TEST_CASE(PipelineUpdateUnittest, TestFileServerStart)

} // namespace logtail

Expand Down

0 comments on commit f168c5b

Please sign in to comment.