Skip to content

Commit

Permalink
Speed up tests by removing unnecessary delays in starting daemons
Browse files Browse the repository at this point in the history
  • Loading branch information
qris committed Apr 10, 2018
1 parent a84fd89 commit 1490299
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
30 changes: 11 additions & 19 deletions lib/common/Test.cpp
Expand Up @@ -452,42 +452,37 @@ int LaunchServer(const std::string& rCommandLine, const char *pidFile)

int WaitForServerStartup(const char *pidFile, int pidIfKnown)
{
#ifdef WIN32
if (pidFile == NULL)
#ifdef WIN32
if(pidFile == NULL)
{
return pidIfKnown;
}
#else
#else
// on other platforms there is no other way to get
// the PID, so a NULL pidFile doesn't make sense.
ASSERT(pidFile != NULL);
#endif
#endif

// time for it to start up
BOX_TRACE("Waiting for server to start");

for (int i = 0; i < 15; i++)
for (int i = 0; i < 150; i++)
{
if (TestFileNotEmpty(pidFile))
{
break;
}

// on Win32 we can check whether the process is alive
// without even checking the PID file

if (pidIfKnown && !ServerIsAlive(pidIfKnown))
{
break;
TEST_FAIL_WITH_MESSAGE("Server died!");
return -1;
}

::sleep(1);
}

// on Win32 we can check whether the process is alive
// without even checking the PID file

if (pidIfKnown && !ServerIsAlive(pidIfKnown))
{
TEST_FAIL_WITH_MESSAGE("Server died!");
return -1;
ShortSleep(MilliSecondsToBoxTime(100), false);
}

if (!TestFileNotEmpty(pidFile))
Expand All @@ -498,9 +493,6 @@ int WaitForServerStartup(const char *pidFile, int pidIfKnown)

BOX_TRACE("Server started");

// wait a second for the pid to be written to the file
::sleep(1);

// read pid file
int pid = ReadPidFile(pidFile);

Expand Down
24 changes: 10 additions & 14 deletions lib/server/ServerControl.cpp
Expand Up @@ -302,8 +302,6 @@ int StartDaemon(int current_pid, const std::string& cmd_line, const char* pid_fi
int new_pid = LaunchServer(cmd_line, pid_file);
TEST_THAT_OR(new_pid != -1 && new_pid != 0, return 0);

::sleep(1);
TEST_THAT_OR(ServerIsAlive(new_pid), return 0);
return new_pid;
}

Expand All @@ -313,20 +311,18 @@ bool StopDaemon(int current_pid, const std::string& pid_file,
TEST_THAT_OR(current_pid != 0, return false);
TEST_THAT_OR(ServerIsAlive(current_pid), return false);
TEST_THAT_OR(KillServer(current_pid, wait_for_process), return false);
::sleep(1);

TEST_THAT_OR(!ServerIsAlive(current_pid), return false);

#ifdef WIN32
int unlink_result = EMU_UNLINK(pid_file.c_str());
TEST_EQUAL_LINE(0, unlink_result, std::string("unlink ") + pid_file);
if(unlink_result != 0)
{
return false;
}
#else
TestRemoteProcessMemLeaks(memleaks_file.c_str());
#endif
#ifdef WIN32
int unlink_result = EMU_UNLINK(pid_file.c_str());
TEST_EQUAL_LINE(0, unlink_result, std::string("unlink ") + pid_file);
if(unlink_result != 0)
{
return false;
}
#else
TestRemoteProcessMemLeaks(memleaks_file.c_str());
#endif

return true;
}
Expand Down

0 comments on commit 1490299

Please sign in to comment.