Skip to content

Commit

Permalink
change bruteforce for scripting (#10246)
Browse files Browse the repository at this point in the history
  • Loading branch information
gridnevvvit authored Oct 10, 2024
1 parent ebdb387 commit 3e8a344
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions ydb/core/kqp/ut/yql/kqp_scripting_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,10 @@ Y_UNIT_TEST_SUITE(KqpScripting) {
auto expected = TString("[") + EXPECTED_EIGHTSHARD_VALUE1 + "]";

int unsuccessStatus = 0;
int successResults = 0;
constexpr int delta = NSan::PlainOrUnderSanitizer(1, 3);

for (int i = 1; i < maxTimeoutMs; i++) {
for (int i = 1; i < maxTimeoutMs; i += delta) {
auto it = client.StreamExecuteYqlScript(R"(
SELECT * FROM `/Root/EightShard` WHERE Text = "Value1" ORDER BY Key;
)", getExecuteYqlRequestSettings(i)).GetValueSync();
Expand All @@ -708,6 +710,11 @@ Y_UNIT_TEST_SUITE(KqpScripting) {
try {
auto yson = StreamResultToYson(it, true);
CompareYson(expected, yson);
++successResults;
if (successResults == 3) {
break;
}

} catch (const TStreamReadError& ex) {
unsuccessStatus++;
if (ex.Status != NYdb::EStatus::CLIENT_DEADLINE_EXCEEDED && ex.Status != NYdb::EStatus::TIMEOUT) {
Expand Down Expand Up @@ -736,14 +743,22 @@ Y_UNIT_TEST_SUITE(KqpScripting) {
int maxTimeoutMs = 1000;

auto getExecuteYqlRequestSettings = GetExecuteYqlRequestSettingsFn(clientTimeout, operationTimeout);
int successResults = 0;

for (int i = 1; i < maxTimeoutMs; i++) {
constexpr int delta = NSan::PlainOrUnderSanitizer(1, 3);

for (int i = 1; i < maxTimeoutMs; i += delta) {
auto result = client.ExecuteYqlScript(R"(
SELECT * FROM `/Root/EightShard` WHERE Text = "Value1" ORDER BY Key;
)", getExecuteYqlRequestSettings(i)).GetValueSync();

if (result.IsSuccess()) {
CompareYson(EXPECTED_EIGHTSHARD_VALUE1, FormatResultSetYson(result.GetResultSet(0)));
successResults++;
if (successResults == 3) {
break;
}

} else {
switch (result.GetStatus()) {
case NYdb::EStatus::CLIENT_DEADLINE_EXCEEDED:
Expand Down Expand Up @@ -771,7 +786,10 @@ Y_UNIT_TEST_SUITE(KqpScripting) {

auto expected = TString("[") + EXPECTED_EIGHTSHARD_VALUE1 + "]";

for (int i = 1; i < maxTimeoutMs; i++) {
constexpr int delta = NSan::PlainOrUnderSanitizer(1, 5);
int successResults = 0;

for (int i = 1; i < maxTimeoutMs; i += delta) {
auto it = client.StreamExecuteYqlScript(R"(
SELECT * FROM `/Root/EightShard` WHERE Text = "Value1" ORDER BY Key;
)", TExecuteYqlRequestSettings().CancelAfter(TDuration::MilliSeconds(i))).GetValueSync();
Expand All @@ -780,6 +798,11 @@ Y_UNIT_TEST_SUITE(KqpScripting) {
try {
auto yson = StreamResultToYson(it, true);
CompareYson(expected, yson);
++successResults;
if (successResults == 3) {
break;
}

} catch (const TStreamReadError& ex) {
if (ex.Status != NYdb::EStatus::CANCELLED) {
TStringStream msg;
Expand Down Expand Up @@ -813,8 +836,9 @@ Y_UNIT_TEST_SUITE(KqpScripting) {
};

TString expected;
const int delta = NSan::PlainOrUnderSanitizer(1, 5);

for (int i = 1; i <= maxTimeoutMs; i++) {
for (int i = 1; i <= maxTimeoutMs; i += delta) {
auto it = client.StreamExecuteYqlScript(Sprintf(R"(
UPSERT INTO `/Root/EightShard` (Key, Data, Text) VALUES (%lu, 100500, "newrecords");
COMMIT;
Expand Down Expand Up @@ -860,9 +884,10 @@ Y_UNIT_TEST_SUITE(KqpScripting) {
return Sprintf(R"([[100500];[%luu];["newrecords"]])", key);
};

constexpr int delta = NSan::PlainOrUnderSanitizer(1, 5);
TString expected;

for (int i = 1; i <= maxTimeoutMs; i++) {
for (int i = 1; i <= maxTimeoutMs; i += delta) {
auto result = client.ExecuteYqlScript(Sprintf(R"(
UPSERT INTO `/Root/EightShard` (Key, Data, Text) VALUES (%lu, 100500, "newrecords");
COMMIT;
Expand Down

0 comments on commit 3e8a344

Please sign in to comment.