Changeset 1941


Ignore:
Timestamp:
06/12/2007 08:52:33 (4 years ago)
Author:
chris
Message:

Fix keepalive test failure:

  • zero memory buffer before use to keep consistent behaviour.
  • expect a diff even if the maximum diffing time expires
  • really check when we have a diff and when we don't
File:
1 edited

Legend:

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

    r1936 r1941  
    7979// two cycles and a bit 
    8080#define TIME_TO_WAIT_FOR_BACKUP_OPERATION       12 
     81 
     82// utility macro for comparing two strings in a line 
     83#define TEST_EQUAL(expected, found, line) \ 
     84{ \ 
     85        std::string exp_str = expected; \ 
     86        std::string found_str = found; \ 
     87        TEST_THAT(exp_str == found_str); \ 
     88        if(exp_str != found_str) \ 
     89        { \ 
     90                printf("Expected <%s> but found <%s> in <%s>\n", \ 
     91                        exp_str.c_str(), found_str.c_str(), line.c_str()); \ 
     92        } \ 
     93} 
     94 
     95// utility macro for testing a line 
     96#define TEST_LINE(condition, line) \ 
     97        TEST_THAT(condition); \ 
     98        if (!(condition)) \ 
     99        { \ 
     100                printf("Test failed on <%s>\n", line.c_str()); \ 
     101        } 
    81102 
    82103void wait_for_backup_operation(int seconds = TIME_TO_WAIT_FOR_BACKUP_OPERATION) 
     
    814835                int fd = open("testfiles/TestDir1/spacetest/f1", O_WRONLY); 
    815836                TEST_THAT(fd > 0); 
     837 
    816838                char buffer[10000]; 
     839                memset(buffer, 0, sizeof(buffer)); 
     840 
    817841                TEST_THAT(write(fd, buffer, sizeof(buffer)) == sizeof(buffer)); 
    818842                TEST_THAT(close(fd) == 0); 
     
    822846                stop_internal_daemon(pid); 
    823847 
     848                // two-second delay on the first read() of f1 
     849                // should mean that a single keepalive is sent, 
     850                // and diff does not abort. 
    824851                intercept_setup_delay("testfiles/TestDir1/spacetest/f1",  
    825852                        0, 2000, SYS_read, 1); 
     
    863890                        TEST_THAT(reader.GetLine(line)); 
    864891                        std::string comp = "Receive Success(0x"; 
    865                         TEST_THAT(line.substr(0, comp.size()) == comp); 
     892                        TEST_EQUAL(comp, line.substr(0, comp.size()), line); 
    866893                        TEST_THAT(reader.GetLine(line)); 
    867                         TEST_THAT(line == "Receiving stream, size 124"); 
     894                        TEST_EQUAL("Receiving stream, size 124", line, line); 
    868895                        TEST_THAT(reader.GetLine(line)); 
    869                         TEST_THAT(line == "Send GetIsAlive()"); 
     896                        TEST_EQUAL("Send GetIsAlive()", line, line); 
    870897                        TEST_THAT(reader.GetLine(line)); 
    871                         TEST_THAT(line == "Receive IsAlive()"); 
     898                        TEST_EQUAL("Receive IsAlive()", line, line); 
    872899 
    873900                        TEST_THAT(reader.GetLine(line)); 
    874901                        comp = "Send StoreFile(0x3,"; 
    875                         TEST_THAT(line.substr(0, comp.size()) == comp); 
     902                        TEST_EQUAL(comp, line.substr(0, comp.size()), line); 
    876903                        comp = ",\"f1\")"; 
    877904                        std::string sub = line.substr(line.size() - comp.size()); 
    878  
    879                         TEST_THAT(sub == comp); 
    880                         if (sub != comp) 
    881                         { 
    882                                 printf("Expected <%s> but found <%s> in <%s>\n", 
    883                                         comp.c_str(), sub.c_str(), line.c_str()); 
    884                         } 
     905                        TEST_EQUAL(comp, sub, line); 
     906                        std::string comp2 = ",0x0,"; 
     907                        sub = line.substr(line.size() - comp.size() - 
     908                                comp2.size() + 1, comp2.size()); 
     909                        TEST_LINE(comp2 != sub, line); 
    885910                } 
    886911                 
     
    892917                } 
    893918 
     919                // four-second delay on first read() of f1 
     920                // should mean that no keepalives were sent, 
     921                // because diff was immediately aborted 
     922                // before any matching blocks could be found. 
    894923                intercept_setup_delay("testfiles/TestDir1/spacetest/f1",  
    895924                        0, 4000, SYS_read, 1); 
     
    939968                        TEST_THAT(reader.GetLine(line)); 
    940969                        comp = "Send StoreFile(0x3,"; 
    941                         TEST_THAT(line.substr(0, comp.size()) == comp); 
     970                        TEST_EQUAL(comp, line.substr(0, comp.size()), line); 
    942971                        comp = ",0x0,\"f1\")"; 
    943972                        std::string sub = line.substr(line.size() - comp.size()); 
    944  
    945                         TEST_THAT(sub == comp); 
    946                         if (sub != comp) 
    947                         { 
    948                                 printf("Expected <%s> but found <%s> in <%s>\n", 
    949                                         comp.c_str(), sub.c_str(), line.c_str()); 
    950                         } 
     973                        TEST_EQUAL(comp, sub, line); 
    951974                } 
    952975 
     
    10131036                        TEST_THAT(line == "Receive IsAlive()"); 
    10141037 
    1015                         // should not be a diff, so previous version 
    1016                         // should be 0x0 
     1038                        // but two matching blocks should have been found 
     1039                        // already, so the upload should be a diff. 
    10171040 
    10181041                        TEST_THAT(reader.GetLine(line)); 
    10191042                        comp = "Send StoreFile(0x3,"; 
    1020                         TEST_THAT(line.substr(0, comp.size()) == comp); 
    1021                         comp = ",0x0,\"f1\")"; 
     1043                        TEST_EQUAL(comp, line.substr(0, comp.size()), line); 
     1044                        comp = ",\"f1\")"; 
    10221045                        std::string sub = line.substr(line.size() - comp.size()); 
    1023  
    1024                         TEST_THAT(sub == comp); 
    1025                         if (sub != comp) 
    1026                         { 
    1027                                 printf("Expected <%s> but found <%s> in <%s>\n", 
    1028                                         comp.c_str(), sub.c_str(), line.c_str()); 
    1029                         } 
     1046                        TEST_EQUAL(comp, sub, line); 
     1047                        std::string comp2 = ",0x0,"; 
     1048                        sub = line.substr(line.size() - comp.size() - 
     1049                                comp2.size() + 1, comp2.size()); 
     1050                        TEST_LINE(comp2 != sub, line); 
    10301051                } 
    10311052 
     
    10961117                        std::string line; 
    10971118                        TEST_THAT(reader.GetLine(line)); 
    1098                         TEST_THAT(line == "Receive Success(0x3)"); 
     1119                        TEST_EQUAL("Receive Success(0x3)", line, line); 
    10991120                        TEST_THAT(reader.GetLine(line)); 
    1100                         TEST_THAT(line == "Receiving stream, size 425"); 
     1121                        TEST_EQUAL("Receiving stream, size 425", line, line); 
    11011122                        TEST_THAT(reader.GetLine(line)); 
    1102                         TEST_THAT(line == "Send GetIsAlive()"); 
     1123                        TEST_EQUAL("Send GetIsAlive()", line, line); 
    11031124                        TEST_THAT(reader.GetLine(line)); 
    1104                         TEST_THAT(line == "Receive IsAlive()"); 
     1125                        TEST_EQUAL("Receive IsAlive()", line, line); 
    11051126                        TEST_THAT(reader.GetLine(line)); 
    1106                         TEST_THAT(line == "Send GetIsAlive()"); 
     1127                        TEST_EQUAL("Send GetIsAlive()", line, line); 
    11071128                        TEST_THAT(reader.GetLine(line)); 
    1108                         TEST_THAT(line == "Receive IsAlive()"); 
     1129                        TEST_EQUAL("Receive IsAlive()", line, line); 
    11091130                } 
    11101131 
Note: See TracChangeset for help on using the changeset viewer.