loadtest.c: when deleting, always make sure we deleted 1 message.
authorArt Cancro <ajc@citadel.org>
Sun, 27 Aug 2023 00:29:07 +0000 (20:29 -0400)
committerArt Cancro <ajc@citadel.org>
Sun, 27 Aug 2023 00:29:07 +0000 (20:29 -0400)
If there are multiple loadtest processes running -- and that's really
the whole idea -- we will often try to delete a message that was already
deleted by another process.  That's not an error condition, but it would
cause posts to outnumber deletes and the rooms would grow endlessly.  So
if we didn't successfully delete something, we go back and try deleting
another one.

Fun fact: the algorithm used to decide which message to delete is the same
algorithm used in the 'fortune' program.

citadel/utils/loadtest.c

index bb713ea3da4a9a94e855ff1db61f5c5929cb3718..76b6c895baab7f9eb094f3ad7db5fc27736e5f1d 100644 (file)
@@ -253,19 +253,21 @@ void perform_random_thing(void) {
                total_msgs = 0;
                selected_msg = 0;
 
-               serv_puts("MSGS ALL");
-               serv_gets(buf);
-               if (buf[0] == '1') {
-                       while (serv_gets(buf), strcmp(buf, "000")) {
-                               ++total_msgs;
-                               if ((random() % total_msgs) == 0) {
-                                       selected_msg = atol(buf);
+               do {
+                       serv_puts("MSGS ALL");
+                       serv_gets(buf);
+                       if (buf[0] == '1') {
+                               while (serv_gets(buf), strcmp(buf, "000")) {
+                                       ++total_msgs;
+                                       if ((random() % total_msgs) == 0) {
+                                               selected_msg = atol(buf);
+                                       }
                                }
                        }
-               }
-               snprintf(buf, sizeof buf, "DELE %ld", selected_msg);
-               serv_puts(buf);
-               serv_gets(buf);
+                       snprintf(buf, sizeof buf, "DELE %ld", selected_msg);
+                       serv_puts(buf);
+                       serv_gets(buf);
+               } while(buf[0] != '2');         // make sure we always delete exactly one message
        }
 
 }