]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: ncbuf/test: remove unnecessary delay in random insert
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 19 Nov 2026 13:35:34 +0000 (14:35 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 19 Nov 2026 14:08:36 +0000 (15:08 +0100)
A delay is used for better readability when the buffer content is
displayed on each iteration during the random insert test.

However, this delay also applied when nothing was printed. This renders
the test artificially long. Thus, removes the delay when print is not
requested so that the test can run as fast as possible.

This should be backported up to 2.6.

src/ncbuf.c

index 0a94c4b46c93a8c310db73106b8833189ce12f8a..4b62ef453e7f773589dcc8e84b99728093a52b45 100644 (file)
@@ -773,6 +773,15 @@ static void ncbuf_print_buf(struct ncbuf *b, ncb_sz_t len,
                getchar();
 }
 
+static void ncbuf_print_buf_delay(struct ncbuf *b, ncb_sz_t len,
+                                  unsigned char *area, int line, int delay)
+{
+       if (ncb_print) {
+               ncbuf_print_buf(b, len, area, line);
+               usleep(delay);
+       }
+}
+
 static struct ncbuf b;
 static unsigned char *bufarea = NULL;
 static ncb_sz_t bufsize = 16384;
@@ -909,8 +918,7 @@ static int ncbuf_test(ncb_sz_t head, int reset, int print_delay)
 
                ret = ncb_add(&b, roff->off, data0, roff->len, NCB_ADD_COMPARE);
                BUG_ON(ret == NCB_RET_DATA_REJ);
-               ncbuf_print_buf(&b, bufsize, bufarea, __LINE__);
-               usleep(print_delay);
+               ncbuf_print_buf_delay(&b, bufsize, bufarea, __LINE__, print_delay);
        }
 
        fprintf(stderr, "buf full, prepare for reverse random\n");
@@ -925,8 +933,7 @@ static int ncbuf_test(ncb_sz_t head, int reset, int print_delay)
                if (!full) {
                        ret = ncb_add(&b, roff->off, data0, roff->len, NCB_ADD_COMPARE);
                        BUG_ON(ret == NCB_RET_DATA_REJ);
-                       ncbuf_print_buf(&b, bufsize, bufarea, __LINE__);
-                       usleep(print_delay);
+                       ncbuf_print_buf_delay(&b, bufsize, bufarea, __LINE__, print_delay);
                }
 
                roff_tmp = roff->next;