From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>,
Sergey Bronnikov <estetus@gmail.com>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 1/3] test: add unit tests for the write buffer
Date: Tue, 1 Dec 2026 18:11:35 +0300 [thread overview]
Message-ID: <615aec10-fde7-4782-aa63-f3a075d08b71@tarantool.org> (raw)
In-Reply-To: <auzNchEuFrlP5R2y@root>
Hi, Sergey,
thanks for review! Please see my comments below.
Sergey
On 11/5/26 21:39, Sergey Kaplun wrote:
> Hi, Sergey!
> Thanks for the patch and painstaking work with coverage of wbuf module!
> Generally LGTM with minor suggestions below.
>
> On 02.11.26, Sergey Bronnikov wrote:
>> From: Sergey Bronnikov <sergeyb@tarantool.org>
>>
>> The write buffer accumulates the profilers' output and passes it
>> to the writer on flush. It has no unit tests, so cover writing of
>> the data of all kinds, flushing of a full buffer, the explicit
>> flush and the error reporting.
>>
>> Part of tarantool/tarantool#11620
> Minor: I'm not sure that this is the part of this issue. Maybe
> | Relates to
> is more appropriate.
Fixed.
>
>> ---
>> test/tarantool-c-tests/unit-wbuf.test.c | 388 ++++++++++++++++++++++++
>> 1 file changed, 388 insertions(+)
>> create mode 100644 test/tarantool-c-tests/unit-wbuf.test.c
>>
>> diff --git a/test/tarantool-c-tests/unit-wbuf.test.c b/test/tarantool-c-tests/unit-wbuf.test.c
>> new file mode 100644
>> index 00000000..4bee6243
>> --- /dev/null
>> +++ b/test/tarantool-c-tests/unit-wbuf.test.c
>> @@ -0,0 +1,388 @@
>> +/*
>> +** Testing of the write buffer.
>> +**
>> +** The write buffer accumulates the profilers' output and passes
>> +** it to the writer on flush. The tests below cover writing of the
>> +** data of all kinds, flushing on overflow, the explicit flush and
>> +** the error reporting.
> Minor: It is better to use
> | /*
> | *
> | */
>
> Comments here as in the most C/C++ code in the tests.
> The inconsistent comment style in the <unit-leb128.test.c> is my fault
> and should be fixed.
Updated:
--- a/test/tarantool-c-tests/unit-wbuf.test.c
+++ b/test/tarantool-c-tests/unit-wbuf.test.c
@@ -1,11 +1,11 @@
/*
-** Testing of the write buffer.
-**
-** The write buffer accumulates the profilers' output and passes
-** it to the writer on flush. The tests below cover writing of the
-** data of all kinds, flushing on overflow, the explicit flush and
-** the error reporting.
-*/
+ * Testing of the write buffer.
+ *
+ * The write buffer accumulates the profilers' output and passes
+ * it to the writer on flush. The tests below cover writing of the
+ * data of all kinds, flushing on overflow, the explicit flush and
+ * the error reporting.
+ */
#include <errno.h>
>
>> +*/
>> +
>> +#include <errno.h>
>> +
>> +#include <stddef.h>
>> +#include <stdint.h>
>> +#include <string.h>
>> +
>> +#include "lj_wbuf.h"
>> +#include "test.h"
>> +
>> +/* Size of the write buffer used in the tests. */
>> +#define BUFFER_SIZE 10
>> +
>> +/* Size of the payload that does not fit into the write buffer. */
>> +#define PAYLOAD_SIZE (2 * BUFFER_SIZE + 5)
>> +
>> +/* What the writer does on flush. */
>> +enum writer_mode {
>> + /* Report all the data as written. */
>> + WMODE_OK,
>> + /* Report a half of the data as written and keep the buffer. */
> Nit: Comment length is more than 66 symbols.
> Here and in:
> * `test_flush_partial_write()`
> * `test_addbyte_failed_flush()`
> * `test_addu64_failed_flush()`
> * `test_addn_failed_flush()`
> * `test_addn_failed_flush_in_loop()`
Fixed.
>
>> + WMODE_PARTIAL,
>> + /* Imitate an unrecoverable write error, e.g. ENOSPC. */
>> + WMODE_FAIL,
>> +};
>> +
>> +/* Writer context for simulating different write outcomes. */
>> +struct writer_ctx {
>> + /* What the writer does on flush. */
>> + enum writer_mode mode;
>> + /* Number of performed flushes. */
>> + size_t flushes;
>> + /* Number of bytes reported as written. */
>> + size_t written;
>> + /* Everything reported as written, in order of writing. */
>> + uint8_t out[2 * PAYLOAD_SIZE];
> Why do we need 2x size from the PAYLOAD here? Please add the comment.
Updated:
--- a/test/tarantool-c-tests/unit-wbuf.test.c
+++ b/test/tarantool-c-tests/unit-wbuf.test.c
@@ -44,7 +44,15 @@ struct writer_ctx {
size_t flushes;
/* Number of bytes reported as written. */
size_t written;
- /* Everything reported as written, in order of writing. */
+ /*
+ * Everything reported as written, in order of writing.
+ *
+ * Must hold the bytes reported over a whole test. The
+ * largest amount is produced by test_flush_on_overflow(),
+ * which reports 3 * BUFFER_SIZE bytes. 2 * PAYLOAD_SIZE
+ * (4 * BUFFER_SIZE + 10) is a conservative upper bound
+ * that leaves some headroom.
+ */
uint8_t out[2 * PAYLOAD_SIZE];
};
>
>> +};
>> +
>> +static size_t test_writer(const void **buf_addr, size_t len, void *opt)
>> +{
>> + struct writer_ctx *ctx = opt;
>> + size_t n = len;
>> +
>> + ctx->flushes++;
> Minor: Please add the comment that writer function is called only by
> `lj_wbuf_flush()` before this increment.
--- a/test/tarantool-c-tests/unit-wbuf.test.c
+++ b/test/tarantool-c-tests/unit-wbuf.test.c
@@ -63,6 +63,7 @@ static size_t test_writer(const void **buf_addr,
size_t len, void *opt)
n = len / 2;
}
memcpy(ctx->out + ctx->written, *buf_addr, n);
+ /* The function is called only by lj_wbuf_flush(). */
ctx->written += n;
return n;
}
>
>> + if (ctx->mode == WMODE_FAIL) {
>> + errno = ENOSPC;
>> + *buf_addr = NULL;
>> + return 0;
>> + }
>> + if (ctx->mode == WMODE_PARTIAL) {
> Minor: s/if/else if/
--- a/test/tarantool-c-tests/unit-wbuf.test.c
+++ b/test/tarantool-c-tests/unit-wbuf.test.c
@@ -58,11 +58,12 @@ static size_t test_writer(const void **buf_addr,
size_t len, void *opt)
*buf_addr = NULL;
return 0;
}
- if (ctx->mode == WMODE_PARTIAL) {
+ else if (ctx->mode == WMODE_PARTIAL) {
errno = EIO;
n = len / 2;
}
>> + errno = EIO;
>> + n = len / 2;
>> + }
>> + memcpy(ctx->out + ctx->written, *buf_addr, n);
>> + ctx->written += n;
>> + return n;
>> +}
>> +
> <snipped>
>
>> +
>> +static void assert_stream_stopped_with_error(const struct lj_wbuf *buf)
> I suggest using macro instead for such helpers to preserve the line of
> original assertion check:
>
> So instead of:
> | not ok 9 - test_flush_stopped_stream
> | ---
> | location: test/tarantool-c-tests/unit-wbuf.test.c:80
> | condition_failed: 'lj_wbuf_test_flag(buf, STREAM_STOP)'
>
> We have:
> | not ok 9 - test_flush_stopped_stream
> | ---
> | location: test/tarantool-c-tests/unit-wbuf.test.c:304
> | condition_failed: 'lj_wbuf_test_flag((&buf), STREAM_STOP)'
Added:
--- a/test/tarantool-c-tests/unit-wbuf.test.c
+++ b/test/tarantool-c-tests/unit-wbuf.test.c
@@ -112,14 +112,13 @@ static size_t wbuf_len(const struct lj_wbuf *buf)
return (size_t)(buf->pos - buf->buf);
}
-static void assert_stream_stopped_with_error(const struct lj_wbuf *buf)
-{
- assert_true(lj_wbuf_test_flag(buf, STREAM_STOP));
- assert_true(lj_wbuf_test_flag(buf, STREAM_ERRIO));
- assert_int_equal(lj_wbuf_errno(buf), ENOSPC);
- assert_ptr_equal(buf->buf, NULL);
- assert_ptr_equal(buf->pos, NULL);
-}
+#define assert_stream_stopped_with_error(wbuf) do { \
+ assert_true(lj_wbuf_test_flag((wbuf), STREAM_STOP)); \
+ assert_true(lj_wbuf_test_flag((wbuf), STREAM_ERRIO)); \
+ assert_int_equal(lj_wbuf_errno((wbuf)), ENOSPC); \
+ assert_ptr_equal((wbuf)->buf, NULL); \
+ assert_ptr_equal((wbuf)->pos, NULL); \
+} while (0)
static int test_addbyte(void *state)
{
>> +{
>> + assert_true(lj_wbuf_test_flag(buf, STREAM_STOP));
>> + assert_true(lj_wbuf_test_flag(buf, STREAM_ERRIO));
>> + assert_int_equal(lj_wbuf_errno(buf), ENOSPC);
> Since this precise assertion, I suggest naming the helper function/macro
> something like `assert_wbuf_stopped_enospc()`.
>
Added:
+#define assert_wbuf_stopped_enospc(wbuf) do { \
+ assert_true(lj_wbuf_test_flag((wbuf), STREAM_STOP)); \
+ assert_true(lj_wbuf_test_flag((wbuf), STREAM_ERRIO)); \
+ assert_int_equal(lj_wbuf_errno((wbuf)), ENOSPC); \
+ assert_ptr_equal((wbuf)->buf, NULL); \
+ assert_ptr_equal((wbuf)->pos, NULL); \
+} while (0)
+
>> + assert_ptr_equal(buf->buf, NULL);
>> + assert_ptr_equal(buf->pos, NULL);
>> +}
>> +
>> +static int test_addbyte(void *state)
> <snipped>
>
>
>> +static int test_addstring(void *state)
>> +{
> <snipped>
>
>> +}
>> +
>> +static int test_addn_pumped_through_buffer(void *state)
>> +{
>> + uint8_t mem[BUFFER_SIZE];
>> + uint8_t payload[PAYLOAD_SIZE];
>> + struct lj_wbuf buf;
>> + struct writer_ctx ctx;
>> +
>> + UNUSED(state);
>> +
>> + memset(payload, 'a', sizeof(payload));
>> + writer_ctx_init(&ctx, WMODE_OK);
>> + lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem));
>> +
>> + /*
>> + * The payload does not fit into the buffer, so it is
>> + * pumped through it. Two full buffers are flushed, the
>> + * rest stays in the buffer.
>> + */
>> + lj_wbuf_addn(&buf, payload, sizeof(payload));
>> + assert_sizet_equal(ctx.flushes, 2);
> This `2` may be not very obvious.
> We may declare constant in this function before the comment above:
>
> | const int writes = PAYLOAD_SIZE / BUFFER_SIZE;
Fixed:
@@ -181,6 +182,7 @@ static int test_addn_pumped_through_buffer(void *state)
writer_ctx_init(&ctx, WMODE_OK);
lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem));
+ const int writes = PAYLOAD_SIZE / BUFFER_SIZE;
/*
* The payload does not fit into the buffer, so it is
* pumped through it. Two full buffers are flushed, the
>
>> + assert_sizet_equal(ctx.written, 2 * BUFFER_SIZE);
>> + assert_true(memcmp(ctx.out, payload, 2 * BUFFER_SIZE) == 0);
>> + assert_sizet_equal(buf_len(&buf), PAYLOAD_SIZE - 2 * BUFFER_SIZE);
> It is better to add the variable:
>
> | const int remains = PAYLOAD_SIZE - writes * BUFFER_SIZE;
Updated:
@@ -190,9 +192,9 @@ static int test_addn_pumped_through_buffer(void *state)
assert_sizet_equal(ctx.flushes, 2);
assert_sizet_equal(ctx.written, 2 * BUFFER_SIZE);
assert_true(memcmp(ctx.out, payload, 2 * BUFFER_SIZE) == 0);
- assert_sizet_equal(buf_len(&buf), PAYLOAD_SIZE - 2 * BUFFER_SIZE);
- assert_true(memcmp(mem, payload + 2 * BUFFER_SIZE,
- PAYLOAD_SIZE - 2 * BUFFER_SIZE) == 0);
+ const int remains = PAYLOAD_SIZE - writes * BUFFER_SIZE;
+ assert_sizet_equal(buf_len(&buf), remains);
+ assert_true(memcmp(mem, payload + 2 * BUFFER_SIZE, remains) == 0);
return TEST_EXIT_SUCCESS;
}
>
>> + assert_true(memcmp(mem, payload + 2 * BUFFER_SIZE,
>> + PAYLOAD_SIZE - 2 * BUFFER_SIZE) == 0);
>> +
>> + return TEST_EXIT_SUCCESS;
>> +}
>> +
>> +static int test_flush_on_overflow(void *state)
>> +{
>> + uint8_t mem[BUFFER_SIZE];
>> + uint8_t payload[BUFFER_SIZE];
>> + struct lj_wbuf buf;
>> + struct writer_ctx ctx;
>> +
>> + UNUSED(state);
>> +
>> + memset(payload, 'a', sizeof(payload));
>> + writer_ctx_init(&ctx, WMODE_OK);
>> + lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem));
>> +
>> + /* A byte written to a full buffer is preceded by a flush. */
>> + lj_wbuf_addn(&buf, payload, sizeof(payload));
>> + assert_sizet_equal(buf_len(&buf), sizeof(mem));
>> + lj_wbuf_addbyte(&buf, 0xaa);
>> + assert_sizet_equal(ctx.flushes, 1);
>> + assert_sizet_equal(ctx.written, sizeof(mem));
>> + assert_sizet_equal(buf_len(&buf), 1);
>> + assert_int_equal(mem[0], 0xaa);
> I suggest splitting this 1 test into 3 subtests, since they have the
> similar logic:
> 1) Init buffer.
> 2) Write something without flushes.
> 3) Write something with a flush.
>
> It helps to avoid the specific `ctx.out` size and makes checks for
> `flushes`, `written` and `buf_len()` similar.
Splitted:
diff --git a/test/tarantool-c-tests/unit-wbuf.test.c
b/test/tarantool-c-tests/unit-wbuf.test.c
index 27d75ad0..9574d42b 100644
--- a/test/tarantool-c-tests/unit-wbuf.test.c
+++ b/test/tarantool-c-tests/unit-wbuf.test.c
@@ -48,10 +48,10 @@ struct writer_ctx {
* Everything reported as written, in order of writing.
*
* Must hold the bytes reported over a whole test. The
- * largest amount is produced by test_flush_on_overflow(),
- * which reports 3 * BUFFER_SIZE bytes. 2 * PAYLOAD_SIZE
- * (4 * BUFFER_SIZE + 10) is a conservative upper bound
- * that leaves some headroom.
+ * largest amount is produced by
+ * test_addn_pumped_through_buffer(), which reports
+ * 2 * BUFFER_SIZE bytes. 2 * PAYLOAD_SIZE is a conservative
+ * upper bound that leaves some headroom.
*/
uint8_t out[2 * PAYLOAD_SIZE];
};
@@ -251,7 +251,7 @@ static int
test_addn_pumped_through_buffer_partial(void *state)
return TEST_EXIT_SUCCESS;
}
-static int test_flush_on_overflow(void *state)
+static int test_flush_on_overflow_addbyte(void *state)
{
uint8_t payload[BUFFER_SIZE];
@@ -259,29 +259,57 @@ static int test_flush_on_overflow(void *state)
UNUSED(state);
memset(payload, 'a', sizeof(payload));
- /* A byte written to a full buffer is preceded by a flush. */
+ /* Fill the buffer without a flush. */
lj_wbuf_addn(&buf, payload, sizeof(payload));
assert_sizet_equal(wbuf_len(&buf), sizeof(mem));
+
+ /* A byte written to a full buffer is preceded by a flush. */
lj_wbuf_addbyte(&buf, 0xaa);
assert_sizet_equal(ctx.flushes, 1);
assert_sizet_equal(ctx.written, sizeof(mem));
assert_sizet_equal(wbuf_len(&buf), 1);
assert_int_equal(mem[0], 0xaa);
- /* The same for an ULEB128 value written to a full buffer. */
- lj_wbuf_addn(&buf, payload, sizeof(payload) - 1);
+ return TEST_EXIT_SUCCESS;
+}
+
+static int test_flush_on_overflow_addu64(void *state)
+{
+ uint8_t payload[BUFFER_SIZE];
+
+ WBUF_TEST_SETUP(WMODE_OK);
+ UNUSED(state);
+ memset(payload, 'a', sizeof(payload));
+
+ /* Fill the buffer without a flush. */
+ lj_wbuf_addn(&buf, payload, sizeof(payload));
assert_sizet_equal(wbuf_len(&buf), sizeof(mem));
+
+ /* An ULEB128 value written to a full buffer is preceded by a flush. */
lj_wbuf_addu64(&buf, 0);
- assert_sizet_equal(ctx.flushes, 2);
- assert_sizet_equal(ctx.written, 2 * sizeof(mem));
+ assert_sizet_equal(ctx.flushes, 1);
+ assert_sizet_equal(ctx.written, sizeof(mem));
assert_sizet_equal(wbuf_len(&buf), 1);
- /* And for a data block written to a full buffer. */
- lj_wbuf_addn(&buf, payload, sizeof(payload) - 1);
+ return TEST_EXIT_SUCCESS;
+}
+
+static int test_flush_on_overflow_addn(void *state)
+{
+ uint8_t payload[BUFFER_SIZE];
+
+ WBUF_TEST_SETUP(WMODE_OK);
+ UNUSED(state);
+ memset(payload, 'a', sizeof(payload));
+
+ /* Fill the buffer without a flush. */
+ lj_wbuf_addn(&buf, payload, sizeof(payload));
assert_sizet_equal(wbuf_len(&buf), sizeof(mem));
+
+ /* A data block written to a full buffer is preceded by a flush. */
lj_wbuf_addn(&buf, payload, 1);
- assert_sizet_equal(ctx.flushes, 3);
- assert_sizet_equal(ctx.written, 3 * sizeof(mem));
+ assert_sizet_equal(ctx.flushes, 1);
+ assert_sizet_equal(ctx.written, sizeof(mem));
assert_sizet_equal(wbuf_len(&buf), 1);
return TEST_EXIT_SUCCESS;
@@ -496,7 +524,9 @@ int main(void)
test_unit_def(test_addstring),
test_unit_def(test_addn_pumped_through_buffer),
test_unit_def(test_addn_pumped_through_buffer_partial),
- test_unit_def(test_flush_on_overflow),
+ test_unit_def(test_flush_on_overflow_addbyte),
+ test_unit_def(test_flush_on_overflow_addu64),
+ test_unit_def(test_flush_on_overflow_addn),
test_unit_def(test_flush),
test_unit_def(test_flush_partial_write),
test_unit_def(test_flush_stopped_stream),
>> +
>> + /* The same for an ULEB128 value written to a full buffer. */
>> + lj_wbuf_addn(&buf, payload, sizeof(payload) - 1);
>> + assert_sizet_equal(buf_len(&buf), sizeof(mem));
>> + lj_wbuf_addu64(&buf, 0);
>> + assert_sizet_equal(ctx.flushes, 2);
>> + assert_sizet_equal(ctx.written, 2 * sizeof(mem));
>> + assert_sizet_equal(buf_len(&buf), 1);
> Looks like there should be a check for the content as for the 0xaa
> byte.
Added:
--- a/test/tarantool-c-tests/unit-wbuf.test.c
+++ b/test/tarantool-c-tests/unit-wbuf.test.c
@@ -290,6 +290,8 @@ static int test_flush_on_overflow_addu64(void *state)
assert_sizet_equal(ctx.flushes, 1);
assert_sizet_equal(ctx.written, sizeof(mem));
assert_sizet_equal(wbuf_len(&buf), 1);
+ /* 0 is encoded as a single 0x00 byte. */
+ assert_int_equal(mem[0], 0x00);
return TEST_EXIT_SUCCESS;
}
@@ -311,6 +313,7 @@ static int test_flush_on_overflow_addn(void *state)
assert_sizet_equal(ctx.flushes, 1);
assert_sizet_equal(ctx.written, sizeof(mem));
assert_sizet_equal(wbuf_len(&buf), 1);
+ assert_int_equal(mem[0], payload[0]);
return TEST_EXIT_SUCCESS;
}
>> +
>> + /* And for a data block written to a full buffer. */
>> + lj_wbuf_addn(&buf, payload, sizeof(payload) - 1);
>> + assert_sizet_equal(buf_len(&buf), sizeof(mem));
>> + lj_wbuf_addn(&buf, payload, 1);
>> + assert_sizet_equal(ctx.flushes, 3);
>> + assert_sizet_equal(ctx.written, 3 * sizeof(mem));
>> + assert_sizet_equal(buf_len(&buf), 1);
> Looks like there should be a check for the content as for the 0xaa
> byte.
Added.
>> +
>> + return TEST_EXIT_SUCCESS;
>> +}
>> +
>> +static int test_flush(void *state)
> I suggest renaming this as `test_flush_and_write()` or something similar.
> Otherwise, the difference between this test and the test above is
> unclear.
renamed:
--- a/test/tarantool-c-tests/unit-wbuf.test.c
+++ b/test/tarantool-c-tests/unit-wbuf.test.c
@@ -318,7 +318,7 @@ static int test_flush_on_overflow_addn(void *state)
return TEST_EXIT_SUCCESS;
}
-static int test_flush(void *state)
+static int test_flush_and_write(void *state)
{
WBUF_TEST_SETUP(WMODE_OK);
@@ -530,7 +530,7 @@ int main(void)
test_unit_def(test_flush_on_overflow_addbyte),
test_unit_def(test_flush_on_overflow_addu64),
test_unit_def(test_flush_on_overflow_addn),
- test_unit_def(test_flush),
+ test_unit_def(test_flush_and_write),
test_unit_def(test_flush_partial_write),
test_unit_def(test_flush_stopped_stream),
test_unit_def(test_write_to_stopped_stream),
>> +{
>> + uint8_t mem[BUFFER_SIZE];
>> + struct lj_wbuf buf;
>> + struct writer_ctx ctx;
>> +
>> + UNUSED(state);
>> +
>> + writer_ctx_init(&ctx, WMODE_OK);
>> + lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem));
>> +
>> + lj_wbuf_addn(&buf, "xyz", 3);
>> + lj_wbuf_flush(&buf);
>> + assert_sizet_equal(ctx.flushes, 1);
>> + assert_sizet_equal(ctx.written, 3);
>> + assert_true(memcmp(ctx.out, "xyz", 3) == 0);
>> + /* The buffer is empty after a successful flush. */
>> + assert_sizet_equal(buf_len(&buf), 0);
>> + assert_false(lj_wbuf_test_flag(&buf, STREAM_ERRIO | STREAM_STOP));
>> +
>> + /* The buffer is usable after the flush. */
>> + lj_wbuf_addbyte(&buf, 0x7f);
>> + assert_sizet_equal(buf_len(&buf), 1);
>> + assert_int_equal(mem[0], 0x7f);
>> +
>> + return TEST_EXIT_SUCCESS;
>> +}
>> +
>> +static int test_flush_partial_write(void *state)
>> +{
>> + uint8_t mem[BUFFER_SIZE];
>> + struct lj_wbuf buf;
>> + struct writer_ctx ctx;
>> +
>> + UNUSED(state);
>> +
>> + writer_ctx_init(&ctx, WMODE_PARTIAL);
>> + lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem));
>> +
>> + lj_wbuf_addn(&buf, "xyz", 3);
>> + lj_wbuf_flush(&buf);
>> + /* A partial write is reported as an error. */
>> + assert_true(lj_wbuf_test_flag(&buf, STREAM_ERRIO));
>> + assert_int_equal(lj_wbuf_errno(&buf), EIO);
>> + /* The writer keeps the buffer, so the stream is not stopped. */
>> + assert_false(lj_wbuf_test_flag(&buf, STREAM_STOP));
>> + assert_ptr_equal(buf.buf, mem);
>> + /* The unwritten data is dropped. */
>> + assert_sizet_equal(buf_len(&buf), 0);
> I'm not sure that we should fixate this policy. Generally there is no
> guarantee what has happened with data. Except that it is not written
> successfully.
> Feel free to ignore.
Updated:
--- a/test/tarantool-c-tests/unit-wbuf.test.c
+++ b/test/tarantool-c-tests/unit-wbuf.test.c
@@ -359,7 +359,7 @@ static int test_flush_partial_write(void *state)
*/
assert_false(lj_wbuf_test_flag(&buf, STREAM_STOP));
assert_ptr_equal(buf.buf, mem);
- /* The unwritten data is dropped. */
+ /* The buffer is reset after the flush. */
assert_sizet_equal(wbuf_len(&buf), 0);
return TEST_EXIT_SUCCESS;
>
>> +
>> + return TEST_EXIT_SUCCESS;
>> +}
> <snipped>
>
>> +/*
>> +** A writer may release the buffer and set *data to NULL on an
>> +** unrecoverable error (e.g. ENOSPC). The stream is stopped in
>> +** this case, so the write functions must not touch the released
>> +** buffer.
>> +*/
> Minor: It is better to use
> | /*
> | *
> | */
>
> Comments here as in the most C/C++ code in the tests.
> The inconsistent comment style in the <unit-leb128.test.c> is my fault
> and should be fixed.
Fixed:
@@ -370,11 +372,11 @@ static int test_terminate(void *state)
}
/*
-** A writer may release the buffer and set *data to NULL on an
-** unrecoverable error (e.g. ENOSPC). The stream is stopped in
-** this case, so the write functions must not touch the released
-** buffer.
-*/
+ * A writer may release the buffer and set *data to NULL on an
+ * unrecoverable error (e.g. ENOSPC). The stream is stopped in
+ * this case, so the write functions must not touch the released
+ * buffer.
+ */
int main(void)
{
const struct test_unit tgroup[] = {
>> +int main(void)
>> +{
>> + const struct test_unit tgroup[] = {
>> + test_unit_def(test_addbyte),
>> + test_unit_def(test_addu64),
>> + test_unit_def(test_addn),
>> + test_unit_def(test_addstring),
>> + test_unit_def(test_addn_pumped_through_buffer),
>> + test_unit_def(test_flush_on_overflow),
>> + test_unit_def(test_flush),
>> + test_unit_def(test_flush_partial_write),
>> + test_unit_def(test_flush_stopped_stream),
>> + test_unit_def(test_write_to_stopped_stream),
>> + test_unit_def(test_terminate),
>> + };
>> + const int test_result = test_run_group(tgroup, NULL);
> Minor: Why do we need this additional variable?
I don't like when `return` returns an expression. I would leave as is.
The same in leb128 test:
$ grep test_run_group test/tarantool-c-tests/unit-*.c
test/tarantool-c-tests/unit-leb128.test.c: const int test_result =
test_run_group(tgroup, NULL);
test/tarantool-c-tests/unit-tap.test.c: return test_run_group(tgroup, NULL);
test/tarantool-c-tests/unit-wbuf.test.c: const int test_result =
test_run_group(tgroup, NULL);
>
>> +
>> + return test_result;
>> +}
>> --
>> 2.56.0
>>
next prev parent reply other threads:[~2026-12-01 15:11 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 13:11 [Tarantool-patches] [PATCH luajit 0/3] Fix sysprof crash due to insufficient free disk space Sergey Bronnikov via Tarantool-patches
2026-11-02 13:12 ` [Tarantool-patches] [PATCH luajit 1/3] test: add unit tests for the write buffer Sergey Bronnikov via Tarantool-patches
2026-11-05 18:39 ` Sergey Kaplun via Tarantool-patches
2026-12-01 15:11 ` Sergey Bronnikov via Tarantool-patches [this message]
2026-11-11 15:24 ` Evgeniy Temirgaleev via Tarantool-patches
2026-12-01 14:33 ` Sergey Bronnikov via Tarantool-patches
2026-11-02 13:12 ` [Tarantool-patches] [PATCH luajit 2/3] sysprof: fix crash on a failed stream flush Sergey Bronnikov via Tarantool-patches
2026-11-06 10:59 ` Sergey Kaplun via Tarantool-patches
2026-12-01 14:41 ` Sergey Bronnikov via Tarantool-patches
2026-11-11 16:34 ` Evgeniy Temirgaleev via Tarantool-patches
2026-12-01 15:33 ` Sergey Bronnikov via Tarantool-patches
2026-11-15 15:12 ` Evgeniy Temirgaleev via Tarantool-patches
2026-12-01 16:09 ` Sergey Bronnikov via Tarantool-patches
2026-11-02 13:12 ` [Tarantool-patches] [PATCH luajit 3/3] sysprof: release resources on a halted profiler Sergey Bronnikov via Tarantool-patches
2026-11-06 11:06 ` Sergey Kaplun via Tarantool-patches
2026-11-11 23:29 ` Evgeniy Temirgaleev via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=615aec10-fde7-4782-aa63-f3a075d08b71@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=estetus@gmail.com \
--cc=sergeyb@tarantool.org \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH luajit 1/3] test: add unit tests for the write buffer' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox