From: Art Cancro Date: Sun, 27 Aug 2023 00:29:07 +0000 (-0400) Subject: loadtest.c: when deleting, always make sure we deleted 1 message. X-Git-Tag: v989~37 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=c39d3365fb22b731ac482e00a1af58128e0f6c4b;p=citadel.git loadtest.c: when deleting, always make sure we deleted 1 message. 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. --- diff --git a/citadel/utils/loadtest.c b/citadel/utils/loadtest.c index bb713ea3d..76b6c895b 100644 --- a/citadel/utils/loadtest.c +++ b/citadel/utils/loadtest.c @@ -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 } }