Skip to content

Commit

Permalink
fix test hang issue on Jenkins Linux (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Xi authored Nov 29, 2023
1 parent c42a23b commit 2f27a5c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
4 changes: 2 additions & 2 deletions cpp/FileTransferAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void Snowflake::Client::FileTransferAgent::upload(string *command)

if (!m_failedTransfers.empty())
{
CXX_LOG_DEBUG("%s command FAILED.", command);
CXX_LOG_DEBUG("%s command FAILED.", command->c_str());
if (isPutFastFailEnabled())
{
throw SnowflakeTransferException(TransferError::FAST_FAIL_ENABLED_SKIP_UPLOADS, m_failedTransfers.c_str());
Expand Down Expand Up @@ -704,7 +704,7 @@ void Snowflake::Client::FileTransferAgent::download(string *command)

if (!m_failedTransfers.empty())
{
CXX_LOG_DEBUG("%s command FAILED.", command);
CXX_LOG_DEBUG("%s command FAILED.", command->c_str());
if (isGetFastFailEnabled())
{
throw SnowflakeTransferException(TransferError::FAST_FAIL_ENABLED_SKIP_DOWNLOADS, m_failedTransfers.c_str());
Expand Down
21 changes: 10 additions & 11 deletions tests/test_unit_cred_renew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ void test_token_renew_core(std::string fileName)
MockedStatementPut mockedStatementPut(fileName);

Snowflake::Client::FileTransferAgent agent(&mockedStatementPut);

// use urandom to avoid blocking
agent.setRandomDeviceAsUrand(true);
ITransferResult * result = agent.execute(&cmd);

std::string put_status;
Expand Down Expand Up @@ -355,7 +356,8 @@ void test_token_renew_get_remote_meta(void **unused)
MockedStatementGet mockedStatementGet;

Snowflake::Client::FileTransferAgent agent(&mockedStatementGet);

// use urandom to avoid blocking
agent.setRandomDeviceAsUrand(true);
ITransferResult * result = agent.execute(&cmd);

std::string get_status;
Expand All @@ -377,6 +379,8 @@ void test_parse_exception(void **unused)
MockedFailedParseStmt failedParseStmt;

Snowflake::Client::FileTransferAgent agent(&failedParseStmt);
// use urandom to avoid blocking
agent.setRandomDeviceAsUrand(true);

try
{
Expand Down Expand Up @@ -404,6 +408,8 @@ void test_transfer_exception_upload(void **unused)
MockedStatementPut mockedStatementPut("small*");

Snowflake::Client::FileTransferAgent agent(&mockedStatementPut);
// use urandom to avoid blocking
agent.setRandomDeviceAsUrand(true);

try
{
Expand All @@ -426,7 +432,8 @@ void test_transfer_exception_download(void **unused)
MockedStatementGetSmall mockedStatementGetSmall;

Snowflake::Client::FileTransferAgent agent(&mockedStatementGetSmall);

// use urandom to avoid blocking
agent.setRandomDeviceAsUrand(true);
ITransferResult * result = agent.execute(&cmd);

std::string get_status;
Expand All @@ -453,14 +460,6 @@ static int gr_setup(void **unused)
}

int main(void) {
// temporarily comment out test case could hang on Linux Jenkins run
// sdk issue 658, 340 to follow up
char *genv = getenv("GITHUB_ACTIONS");
if ((!genv) || (strlen(genv) == 0)) {
#ifdef __linux__
return 0;
#endif
}
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_parse_exception),
cmocka_unit_test(test_token_renew_small_files),
Expand Down
42 changes: 24 additions & 18 deletions tests/test_unit_put_fast_fail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class MockedStatementPut : public Snowflake::Client::IStatementPutGet
class MockedStorageClient : public Snowflake::Client::IStorageClient
{
public:
MockedStorageClient() : m_failedTimes(0)
MockedStorageClient(bool sleepAfterSuccess) : m_failedTimes(0), m_sleepAfterSuccess(sleepAfterSuccess)
{
}

Expand Down Expand Up @@ -186,11 +186,14 @@ class MockedStorageClient : public Snowflake::Client::IStorageClient
}
//Lets make succesful files wait
//So the failed ones can catch up with retries and set fastFail.
if (m_sleepAfterSuccess)
{
#ifdef _WIN32
Sleep(5000); // Sleep for sleepTime milli seconds (Sleep(<time in milliseconds>) in windows)
Sleep(5000); // Sleep for sleepTime milli seconds (Sleep(<time in milliseconds>) in windows)
#else
std::this_thread::sleep_for(std::chrono::milliseconds(std::chrono::milliseconds(5000)));
std::this_thread::sleep_for(std::chrono::milliseconds(std::chrono::milliseconds(5000)));
#endif
}
return SUCCESS;
}

Expand Down Expand Up @@ -221,31 +224,39 @@ class MockedStorageClient : public Snowflake::Client::IStorageClient
}
//Lets make succesful files wait
//So the failed ones can catch up with retries and set fastFail.
if (m_sleepAfterSuccess)
{
#ifdef _WIN32
Sleep(5000); // Sleep for sleepTime milli seconds (Sleep(<time in milliseconds>) in windows)
Sleep(5000); // Sleep for sleepTime milli seconds (Sleep(<time in milliseconds>) in windows)
#else
std::this_thread::sleep_for(std::chrono::milliseconds(std::chrono::milliseconds(5000)));
std::this_thread::sleep_for(std::chrono::milliseconds(std::chrono::milliseconds(5000)));
#endif
}
return SUCCESS;
}

private:
int m_failedTimes;
bool m_sleepAfterSuccess;
};

void test_put_fast_fail_core(bool successWithRetry)
{
std::string matchDir = getTestFileMatchDir();
matchDir += "*.csv";
IStorageClient * client = new MockedStorageClient();
// no need to wait for failed ones when all success (successWithRetry=true)
// or run in sequence (parallel = 1)
bool sleepAfterSuccess = !successWithRetry && (parallelThreads != 1);
IStorageClient * client = new MockedStorageClient(sleepAfterSuccess);
StorageClientFactory::injectMockedClient(client);

std::string cmd = std::string("put file://") + matchDir + std::string("@odbctestStage AUTO_COMPRESS=false OVERWRITE=true");

MockedStatementPut mockedStatementPut("*.csv");

Snowflake::Client::FileTransferAgent agent(&mockedStatementPut);

// use urandom to avoid blocking
agent.setRandomDeviceAsUrand(true);
agent.setPutFastFail(true);

if (successWithRetry)
Expand Down Expand Up @@ -292,15 +303,19 @@ void test_put_fast_fail_core(bool successWithRetry)
void test_get_fast_fail_core(bool successWithRetry)
{
std::string matchDir = getTestFileMatchDir();
IStorageClient * client = new MockedStorageClient();
// no need to wait for failed ones when all success (successWithRetry=true)
// or run in sequence (parallel = 1)
bool sleepAfterSuccess = !successWithRetry && (parallelThreads != 1);
IStorageClient * client = new MockedStorageClient(sleepAfterSuccess);
StorageClientFactory::injectMockedClient(client);

std::string cmd = std::string("get @odbctestStage file://") + matchDir;

MockedStatementGet mockedStatementget;

Snowflake::Client::FileTransferAgent agent(&mockedStatementget);

// use urandom to avoid blocking
agent.setRandomDeviceAsUrand(true);
agent.setGetFastFail(true);

if (successWithRetry)
Expand Down Expand Up @@ -420,15 +435,6 @@ static int gr_setup(void **unused)
}

int main(void) {
// temporarily comment out test case could hang on Linux Jenkins run
// sdk issue 658, 340 to follow up
char *genv = getenv("GITHUB_ACTIONS");
if ((!genv) || (strlen(genv) == 0)) {
#ifdef __linux__
return 0;
#endif
}

void **unused;
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_put_fast_fail_sequential),
Expand Down

0 comments on commit 2f27a5c

Please sign in to comment.