Changeset 2237
- Timestamp:
- 10/08/2008 23:04:03 (4 years ago)
- File:
-
- 1 edited
-
box/trunk/test/bbackupd/testbbackupd.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/test/bbackupd/testbbackupd.cpp
r2220 r2237 39 39 #endif 40 40 41 #include "autogen_BackupProtocolServer.h" 41 42 #include "BackupClientCryptoKeys.h" 42 43 #include "BackupClientFileAttributes.h" … … 46 47 #include "BackupQueries.h" 47 48 #include "BackupStoreConstants.h" 49 #include "BackupStoreContext.h" 50 #include "BackupStoreDaemon.h" 48 51 #include "BackupStoreDirectory.h" 49 52 #include "BackupStoreException.h" … … 478 481 } 479 482 480 int test_kill_bbstored( )483 int test_kill_bbstored(bool wait_for_process = false) 481 484 { 482 TEST_THAT(KillServer(bbstored_pid ));485 TEST_THAT(KillServer(bbstored_pid, wait_for_process)); 483 486 ::safe_sleep(1); 484 487 TEST_THAT(!ServerIsAlive(bbstored_pid)); 488 if (!ServerIsAlive(bbstored_pid)) 489 { 490 bbstored_pid = 0; 491 } 485 492 486 493 #ifdef WIN32 … … 733 740 bool stop_internal_daemon(int pid) 734 741 { 735 bool killed_server = KillServer(pid );742 bool killed_server = KillServer(pid, true); 736 743 TEST_THAT(killed_server); 737 744 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 */749 745 } 750 746 … … 894 890 #endif 895 891 896 #ifdef PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE 892 #if 1 893 // #ifdef PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE 897 894 printf("\n==== Skipping intercept-based KeepAlive tests " 898 895 "on this platform.\n"); … … 1658 1655 } 1659 1656 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 1660 1788 #ifndef WIN32 1661 1789 printf("\n==== Testing that absolute symlinks are not followed " … … 2423 2551 // Check that store errors are reported neatly 2424 2552 printf("\n==== Create store error\n"); 2553 TEST_THAT(system("rm -f testfiles/notifyran.backup-error.*") 2554 == 0); 2425 2555 2426 2556 // break the store … … 2462 2592 2463 2593 // Check that the error was reported once more 2464 TEST_THAT(TestFileExists("testfiles/notifyran.backup-error.1"));2465 2594 TEST_THAT(TestFileExists("testfiles/notifyran.backup-error.2")); 2466 2595 TEST_THAT(!TestFileExists("testfiles/notifyran.backup-error.3")); 2596 2467 2597 // Fix the store (so that bbackupquery compare works) 2468 2598 TEST_THAT(::rename("testfiles/0_0/backup/01234567/info.rf.bak", … … 3806 3936 if(r != 0) 3807 3937 { 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 } 3810 3946 return r; 3811 3947 }
Note: See TracChangeset
for help on using the changeset viewer.
