Changeset 2225

Show
Ignore:
Timestamp:
07/08/2008 17:32:15 (5 months ago)
Author:
chris
Message:

Separate LaunchServer? and WaitForServerStartup?.

Location:
box/trunk/lib/common
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • box/trunk/lib/common/Test.cpp

    r2205 r2225  
    155155int LaunchServer(const std::string& rCommandLine, const char *pidFile) 
    156156{ 
     157        ::fprintf(stdout, "Starting server: %s\n", rCommandLine.c_str()); 
     158 
    157159#ifdef WIN32 
    158160 
     
    192194                printf("Launch failed: %s: error %d\n", rCommandLine.c_str(), 
    193195                        (int)err); 
     196                TEST_FAIL_WITH_MESSAGE("Couldn't start server"); 
    194197                return -1; 
    195198        } 
     
    198201        CloseHandle(procInfo.hThread); 
    199202 
     203        return WaitForServerStart(pidFile, (int)procInfo.dwProcessId); 
     204 
    200205#else // !WIN32 
    201206 
    202207        if(RunCommand(rCommandLine) != 0) 
    203208        { 
    204                 printf("Server: %s\n", rCommandLine.c_str()); 
    205209                TEST_FAIL_WITH_MESSAGE("Couldn't start server"); 
    206210                return -1; 
    207211        } 
    208212 
     213        return WaitForServerStartup(pidFile, 0); 
     214 
    209215#endif // WIN32 
    210  
     216} 
     217 
     218int WaitForServerStartup(const char *pidFile, int pidIfKnown) 
     219{ 
    211220        #ifdef WIN32 
    212221        if (pidFile == NULL) 
    213222        { 
    214                 return (int)procInfo.dwProcessId; 
     223                return pidIfKnown; 
    215224        } 
    216225        #else 
    217226        // on other platforms there is no other way to get  
    218227        // the PID, so a NULL pidFile doesn't make sense. 
     228        ASSERT(pidFile != NULL); 
    219229        #endif 
    220230 
    221231        // time for it to start up 
    222         ::fprintf(stdout, "Starting server: %s\n", rCommandLine.c_str()); 
    223232        ::fprintf(stdout, "Waiting for server to start: "); 
    224233 
     
    230239                } 
    231240 
    232                 #ifdef WIN32 
    233                 if (!ServerIsAlive((int)procInfo.dwProcessId)) 
     241                if (pidIfKnown && !ServerIsAlive(pidIfKnown)) 
    234242                { 
    235243                        break; 
    236244                } 
    237                 #endif 
    238245 
    239246                ::fprintf(stdout, "."); 
     
    242249        } 
    243250 
    244         #ifdef WIN32 
    245251        // on Win32 we can check whether the process is alive 
    246252        // without even checking the PID file 
    247253 
    248         if (!ServerIsAlive((int)procInfo.dwProcessId)) 
     254        if (pidIfKnown && !ServerIsAlive(pidIfKnown)) 
    249255        { 
    250256                ::fprintf(stdout, " server died!\n"); 
     
    252258                return -1; 
    253259        } 
    254         #endif 
    255260 
    256261        if (!TestFileNotEmpty(pidFile)) 
     
    269274        int pid = ReadPidFile(pidFile); 
    270275 
    271         #ifdef WIN32 
    272276        // On Win32 we can check whether the PID in the pidFile matches 
    273277        // the one returned by the system, which it always should. 
    274278 
    275         if (pid != (int)procInfo.dwProcessId) 
     279        if (pidIfKnown && pid != pidIfKnown) 
    276280        { 
    277281                printf("Server wrote wrong pid to file (%s): expected %d " 
    278                         "but found %d\n", pidFile,  
    279                         (int)procInfo.dwProcessId, pid); 
     282                        "but found %d\n", pidFile, pidIfKnown, pid); 
    280283                TEST_FAIL_WITH_MESSAGE("Server wrote wrong pid to file");        
    281284                return -1; 
    282285        } 
    283         #endif 
    284286 
    285287        return pid; 
  • box/trunk/lib/common/Test.h

    r2218 r2225  
    8787int ReadPidFile(const char *pidFile); 
    8888int LaunchServer(const std::string& rCommandLine, const char *pidFile); 
     89int WaitForServerStartup(const char *pidFile, int pidIfKnown); 
    8990 
    9091#define TestRemoteProcessMemLeaks(filename) \