Changeset 2237

Show
Ignore:
Timestamp:
10/08/2008 23:04:03 (5 months ago)
Author:
chris
Message:

Test that store-full error is not wrongly generated on aborted connections.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • box/trunk/test/bbackupd/testbbackupd.cpp

    r2220 r2237  
    3939#endif 
    4040 
     41#include "autogen_BackupProtocolServer.h" 
    4142#include "BackupClientCryptoKeys.h" 
    4243#include "BackupClientFileAttributes.h" 
     
    4647#include "BackupQueries.h" 
    4748#include "BackupStoreConstants.h" 
     49#include "BackupStoreContext.h" 
     50#include "BackupStoreDaemon.h" 
    4851#include "BackupStoreDirectory.h" 
    4952#include "BackupStoreException.h" 
     
    478481} 
    479482 
    480 int test_kill_bbstored() 
     483int test_kill_bbstored(bool wait_for_process = false) 
    481484{ 
    482         TEST_THAT(KillServer(bbstored_pid)); 
     485        TEST_THAT(KillServer(bbstored_pid, wait_for_process)); 
    483486        ::safe_sleep(1); 
    484487        TEST_THAT(!ServerIsAlive(bbstored_pid)); 
     488        if (!ServerIsAlive(bbstored_pid)) 
     489        { 
     490                bbstored_pid = 0; 
     491        } 
    485492 
    486493        #ifdef WIN32 
     
    733740bool stop_internal_daemon(int pid) 
    734741{ 
    735         bool killed_server = KillServer(pid); 
     742        bool killed_server = KillServer(pid, true); 
    736743        TEST_THAT(killed_server); 
    737744        return killed_server; 
    738  
    739         /* 
    740         int status; 
    741         TEST_THAT(waitpid(pid, &status, 0) == pid); 
    742         TEST_THAT(WIFEXITED(status)); 
    743          
    744         if (WIFEXITED(status)) 
    745         { 
    746                 TEST_THAT(WEXITSTATUS(status) == 0); 
    747         } 
    748         */ 
    749745} 
    750746 
     
    894890        #endif 
    895891         
    896 #ifdef PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE 
     892#if 1 
     893// #ifdef PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE 
    897894        printf("\n==== Skipping intercept-based KeepAlive tests " 
    898895                "on this platform.\n"); 
     
    16581655        } 
    16591656 
     1657        #ifndef WIN32 // requires fork 
     1658        printf("\n==== Testing that bbackupd responds correctly to " 
     1659                "connection failure\n"); 
     1660 
     1661        { 
     1662                // Kill the daemons 
     1663                terminate_bbackupd(bbackupd_pid); 
     1664                test_kill_bbstored(); 
     1665 
     1666                // create a new file to force an upload 
     1667 
     1668                char* new_file = "testfiles/TestDir1/force-upload-2"; 
     1669                int fd = open(new_file,  
     1670                        O_CREAT | O_EXCL | O_WRONLY, 0700); 
     1671                if (fd <= 0) 
     1672                { 
     1673                        perror(new_file); 
     1674                } 
     1675                TEST_THAT(fd > 0); 
     1676         
     1677                char* control_string = "whee!\n"; 
     1678                TEST_THAT(write(fd, control_string,  
     1679                        strlen(control_string)) == 
     1680                        (int)strlen(control_string)); 
     1681                close(fd); 
     1682 
     1683                // sleep to make it old enough to upload 
     1684                safe_sleep(4); 
     1685 
     1686                class MyHook : public BackupStoreContext::TestHook 
     1687                { 
     1688                        virtual std::auto_ptr<ProtocolObject> StartCommand( 
     1689                                BackupProtocolObject& rCommand) 
     1690                        { 
     1691                                if (rCommand.GetType() == 
     1692                                        BackupProtocolServerStoreFile::TypeID) 
     1693                                { 
     1694                                        // terminate badly 
     1695                                        THROW_EXCEPTION(CommonException, 
     1696                                                Internal); 
     1697                                } 
     1698                                return std::auto_ptr<ProtocolObject>(); 
     1699                        } 
     1700                }; 
     1701                MyHook hook; 
     1702 
     1703                bbstored_pid = fork(); 
     1704 
     1705                if (bbstored_pid < 0) 
     1706                { 
     1707                        BOX_LOG_SYS_ERROR("failed to fork()"); 
     1708                        return 1; 
     1709                } 
     1710 
     1711                if (bbstored_pid == 0) 
     1712                { 
     1713                        // in fork child 
     1714                        TEST_THAT(setsid() != -1); 
     1715 
     1716                        if (!Logging::IsEnabled(Log::TRACE)) 
     1717                        { 
     1718                                Logging::SetGlobalLevel(Log::NOTHING); 
     1719                        } 
     1720 
     1721                        // BackupStoreDaemon must be destroyed before exit(), 
     1722                        // to avoid memory leaks being reported. 
     1723                        { 
     1724                                BackupStoreDaemon bbstored; 
     1725                                bbstored.SetTestHook(hook); 
     1726                                bbstored.SetRunInForeground(true); 
     1727                                bbstored.Main("testfiles/bbstored.conf"); 
     1728                        } 
     1729 
     1730                        Timers::Cleanup(); // avoid memory leaks 
     1731                        exit(0); 
     1732                } 
     1733 
     1734                // in fork parent 
     1735                bbstored_pid = WaitForServerStartup("testfiles/bbstored.pid", 
     1736                        bbstored_pid); 
     1737 
     1738                TEST_THAT(::system("rm -f testfiles/notifyran.store-full.*") == 0); 
     1739 
     1740                // Ignore SIGPIPE so that when the connection is broken, 
     1741                // the daemon doesn't terminate. 
     1742                ::signal(SIGPIPE, SIG_IGN); 
     1743 
     1744                { 
     1745                        Log::Level newLevel = Logging::GetGlobalLevel(); 
     1746 
     1747                        if (!Logging::IsEnabled(Log::TRACE)) 
     1748                        { 
     1749                                newLevel = Log::NOTHING; 
     1750                        } 
     1751 
     1752                        Logging::Guard guard(newLevel); 
     1753 
     1754                        BackupDaemon bbackupd; 
     1755                        bbackupd.Configure("testfiles/bbackupd.conf"); 
     1756                        bbackupd.InitCrypto(); 
     1757                        bbackupd.RunSyncNowWithExceptionHandling(); 
     1758                } 
     1759 
     1760                ::signal(SIGPIPE, SIG_DFL); 
     1761 
     1762                TEST_THAT(TestFileExists("testfiles/notifyran.backup-error.1")); 
     1763                TEST_THAT(!TestFileExists("testfiles/notifyran.backup-error.2")); 
     1764                TEST_THAT(!TestFileExists("testfiles/notifyran.store-full.1")); 
     1765 
     1766                test_kill_bbstored(true); 
     1767 
     1768                if (failures > 0) 
     1769                { 
     1770                        // stop early to make debugging easier 
     1771                        return 1; 
     1772                } 
     1773 
     1774                test_run_bbstored(); 
     1775 
     1776                cmd = BBACKUPD " " + bbackupd_args + 
     1777                        " testfiles/bbackupd.conf"; 
     1778                bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid"); 
     1779                TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0); 
     1780                ::safe_sleep(1); 
     1781                TEST_THAT(ServerIsAlive(bbackupd_pid)); 
     1782                TEST_THAT(ServerIsAlive(bbstored_pid)); 
     1783                if (!ServerIsAlive(bbackupd_pid)) return 1; 
     1784                if (!ServerIsAlive(bbstored_pid)) return 1; 
     1785        } 
     1786        #endif // !WIN32 
     1787 
    16601788        #ifndef WIN32 
    16611789        printf("\n==== Testing that absolute symlinks are not followed " 
     
    24232551                // Check that store errors are reported neatly 
    24242552                printf("\n==== Create store error\n"); 
     2553                TEST_THAT(system("rm -f testfiles/notifyran.backup-error.*") 
     2554                        == 0); 
    24252555 
    24262556                // break the store 
     
    24622592 
    24632593                // Check that the error was reported once more 
    2464                 TEST_THAT(TestFileExists("testfiles/notifyran.backup-error.1")); 
    24652594                TEST_THAT(TestFileExists("testfiles/notifyran.backup-error.2")); 
    24662595                TEST_THAT(!TestFileExists("testfiles/notifyran.backup-error.3")); 
     2596 
    24672597                // Fix the store (so that bbackupquery compare works) 
    24682598                TEST_THAT(::rename("testfiles/0_0/backup/01234567/info.rf.bak", 
     
    38063936        if(r != 0) 
    38073937        { 
    3808                 KillServer(bbackupd_pid); 
    3809                 KillServer(bbstored_pid); 
     3938                if (bbackupd_pid) 
     3939                { 
     3940                        KillServer(bbackupd_pid); 
     3941                } 
     3942                if (bbstored_pid) 
     3943                { 
     3944                        KillServer(bbstored_pid); 
     3945                } 
    38103946                return r; 
    38113947        }