diff options
author | abcdef <[email protected]> | 2023-09-29 14:17:27 +0300 |
---|---|---|
committer | abcdef <[email protected]> | 2023-09-29 15:01:08 +0300 |
commit | 958dddf914ab334e16df1d0f5d12c0eec7b96943 (patch) | |
tree | 6208b0fe67dce69d65b8395ce45d5c8706f69378 | |
parent | e4e626b5f3b1c421690223f466d7034f659b2774 (diff) |
tests for a list of statistics columns
тесты для списка столбцов статистики
-rw-r--r-- | ydb/apps/ydb/ut/run_ydb.cpp | 30 | ||||
-rw-r--r-- | ydb/apps/ydb/ut/run_ydb.h | 9 | ||||
-rw-r--r-- | ydb/apps/ydb/ut/workload-topic.cpp | 44 | ||||
-rw-r--r-- | ydb/apps/ydb/ut/workload-transfer-topic-to-table.cpp | 33 |
4 files changed, 107 insertions, 9 deletions
diff --git a/ydb/apps/ydb/ut/run_ydb.cpp b/ydb/apps/ydb/ut/run_ydb.cpp index 61d8177f890..5dc8d421a0c 100644 --- a/ydb/apps/ydb/ut/run_ydb.cpp +++ b/ydb/apps/ydb/ut/run_ydb.cpp @@ -4,9 +4,11 @@ #include <util/system/shellcommand.h> #include <util/system/env.h> #include <util/string/cast.h> +#include <util/string/printf.h> #include <util/string/split.h> #include <library/cpp/testing/common/env.h> +#include <library/cpp/testing/unittest/registar.h> TString GetYdbEndpoint() { @@ -18,7 +20,7 @@ TString GetYdbDatabase() return GetEnv("YDB_DATABASE"); } -TString RunYdb(const TList<TString>& args1, const TList<TString>& args2) +TString RunYdb(const TList<TString>& args1, const TList<TString>& args2, bool checkExitCode) { TShellCommand command(BinaryPath(GetEnv("YDB_CLI_BINARY"))); @@ -35,7 +37,7 @@ TString RunYdb(const TList<TString>& args1, const TList<TString>& args2) command.Run().Wait(); - if (command.GetExitCode() != 0) { + if (checkExitCode && (command.GetExitCode() != 0)) { ythrow yexception() << Endl << "command: " << command.GetQuotedCommand() << Endl << "exitcode: " << command.GetExitCode() << Endl << @@ -55,3 +57,27 @@ ui64 GetFullTimeValue(const TString& output) return FromString<ui64>(columns.back()); } + +void UnitAssertColumnsOrder(TString line, + const TVector<TString>& columns) +{ + for (size_t i = 0; i < columns.size(); ++i) { + auto& column = columns[i]; + + UNIT_ASSERT_C(line.StartsWith(column), + Sprintf("In column %" PRISZT ", '%s' was expected, but '%s' was received", + i, column.data(), line.data())); + + line = line.substr(column.length()); + + size_t pos = line.find_first_not_of(" \t"); + if (pos != TString::npos) { + line = line.substr(pos); + } else { + line = ""; + } + } + + UNIT_ASSERT_C(line.empty(), + Sprintf("Unexpected columns '%s'", line.data())); +} diff --git a/ydb/apps/ydb/ut/run_ydb.h b/ydb/apps/ydb/ut/run_ydb.h index cd32581fe81..cb0b7fb829b 100644 --- a/ydb/apps/ydb/ut/run_ydb.h +++ b/ydb/apps/ydb/ut/run_ydb.h @@ -6,6 +6,13 @@ TString GetYdbEndpoint(); TString GetYdbDatabase(); -TString RunYdb(const TList<TString>& args1, const TList<TString>& args2); +TString RunYdb(const TList<TString>& args1, const TList<TString>& args2, bool checkExitCode = true); ui64 GetFullTimeValue(const TString& output); + +void EnsureStatisticsColumns(const TList<TString>& args, + const TVector<TString>& columns1, + const TVector<TString>& columns2); + +void UnitAssertColumnsOrder(TString line, + const TVector<TString>& columns); diff --git a/ydb/apps/ydb/ut/workload-topic.cpp b/ydb/apps/ydb/ut/workload-topic.cpp index 2ffb1dff544..a8566476e39 100644 --- a/ydb/apps/ydb/ut/workload-topic.cpp +++ b/ydb/apps/ydb/ut/workload-topic.cpp @@ -12,12 +12,12 @@ Y_UNIT_TEST_SUITE(YdbWorkloadTopic) { -TString ExecYdb(const TList<TString>& args) +TString ExecYdb(const TList<TString>& args, bool checkExitCode = true) { // // ydb -e grpc://${YDB_ENDPOINT} -d /${YDB_DATABASE} workload topic ${args} // - return RunYdb({"workload", "topic"}, args); + return RunYdb({"workload", "topic"}, args, checkExitCode); } struct TTopicConfigurationMatcher { @@ -48,8 +48,6 @@ Y_UNIT_TEST(Default_RunFull) { auto output = ExecYdb({"run", "full", "-s", "10"}); ExecYdb({"clean"}); - TVector<TString> lines, columns; - ui64 fullTime = GetFullTimeValue(output); UNIT_ASSERT_GE(fullTime, 0); @@ -88,6 +86,44 @@ Y_UNIT_TEST(Double_Init) { ExecYdb({"init"}); UNIT_ASSERT_EXCEPTION(ExecYdb({"init"}), yexception); + ExecYdb({"clean"}); +} + +void EnsureStatisticsColumns(const TList<TString>& args, + const TVector<TString>& columns1, + const TVector<TString>& columns2) +{ + ExecYdb({"init"}); + auto output = ExecYdb(args, false); + + TVector<TString> lines; + Split(output, "\n", lines); + + UnitAssertColumnsOrder(lines[0], columns1); + UnitAssertColumnsOrder(lines[1], columns2); + + ExecYdb({"clean"}); +} + +Y_UNIT_TEST(Read_Statistics) +{ + EnsureStatisticsColumns({"run", "read", "-s", "1", "--warmup", "0"}, + {"Window", "Lag", "Lag time", "Read speed", "Full time"}, + {"#", "percentile,msg", "percentile,ms", "msg/s", "MB/s", "percentile,ms"}); +} + +Y_UNIT_TEST(Write_Statistics) +{ + EnsureStatisticsColumns({"run", "write", "-s", "1", "--warmup", "0"}, + {"Window", "Write speed", "Write time", "Inflight"}, + {"#", "msg/s", "MB/s", "percentile,ms", "percentile,msg"}); +} + +Y_UNIT_TEST(ReadWrite_Statistics) +{ + EnsureStatisticsColumns({"run", "full", "-s", "1", "--warmup", "0"}, + {"Window", "Write speed", "Write time", "Inflight", "Lag", "Lag time", "Read speed", "Full time"}, + {"#", "msg/s", "MB/s", "percentile,ms", "percentile,msg", "percentile,msg", "percentile,ms", "msg/s", "MB/s", "percentile,ms"}); } } diff --git a/ydb/apps/ydb/ut/workload-transfer-topic-to-table.cpp b/ydb/apps/ydb/ut/workload-transfer-topic-to-table.cpp index 35509e3b442..50fd485a47e 100644 --- a/ydb/apps/ydb/ut/workload-transfer-topic-to-table.cpp +++ b/ydb/apps/ydb/ut/workload-transfer-topic-to-table.cpp @@ -1,5 +1,7 @@ #include "run_ydb.h" +#include <util/string/split.h> + #include <library/cpp/testing/common/env.h> #include <library/cpp/testing/unittest/registar.h> @@ -74,12 +76,13 @@ void ExpectTable(const TTableConfigMatcher& matcher) } } -TString ExecYdb(const TList<TString>& args) +TString ExecYdb(const TList<TString>& args, bool checkExitCode = true) { // // ydb -e grpc://${YDB_ENDPOINT} -d /${YDB_DATABASE} workload transfer topic-to-table ${args} // - return RunYdb({"-v", "--user", "root", "--no-password", "workload", "transfer", "topic-to-table"}, args); + return RunYdb({"--user", "root", "--no-password", "workload", "transfer", "topic-to-table"}, args, + checkExitCode); } void RunYdb(const TList<TString>& args, @@ -139,6 +142,32 @@ Y_UNIT_TEST(Double_Init) { ExecYdb({"init"}); UNIT_ASSERT_EXCEPTION(ExecYdb({"init"}), yexception); + ExecYdb({"clean"}); +} + +void EnsureStatisticsColumns(const TList<TString>& args, + const TVector<TString>& columns1, + const TVector<TString>& columns2) +{ + RunYdb({"-v", "yql", "-s", R"(ALTER USER root PASSWORD "")"}, TList<TString>()); + + ExecYdb({"init"}); + auto output = ExecYdb(args, false); + + TVector<TString> lines; + Split(output, "\n", lines); + + UnitAssertColumnsOrder(lines[0], columns1); + UnitAssertColumnsOrder(lines[1], columns2); + + ExecYdb({"clean"}); +} + +Y_UNIT_TEST(Statistics) +{ + EnsureStatisticsColumns({"run", "-s", "1", "--warmup", "0"}, + {"Window", "Write speed", "Write time", "Inflight", "Read speed", "Topic time", "Select time", "Upsert time", "Commit time"}, + {"#", "msg/s", "MB/s", "percentile,ms", "percentile,msg", "msg/s", "MB/s", "percentile,ms", "percentile,ms", "percentile,ms", "percentile,ms"}); } } |