]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: test-istream-concat - add simultanious limit streams back into the mix
authorPhil Carmody <phil@dovecot.fi>
Thu, 10 Jul 2014 12:59:53 +0000 (15:59 +0300)
committerPhil Carmody <phil@dovecot.fi>
Thu, 10 Jul 2014 12:59:53 +0000 (15:59 +0300)
Return to the previous complex nested stream-type case.

1 time in 10, it tests the simple case of:

test_stream \
test_stream -}- concat_stream
test_stream /
(2-11 of these)

9 times in 10, it tests this configuration instead:

test_stream \                  / limit_stream
test_stream -}- concat_stream {- limit_stream
test_stream /                  \ limit_stream
(2-11 of these)                 (1-9 of these)

Since 31efe2d04793 lib: istream-concat read() returned -2 too early., all tests
pass every time.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/lib/test-istream-concat.c

index 261d2b6f21a944e2627c7c0942edf947cea41ee1..8f0d001ce4fbfde96bc97e52f90aa45fa5e5d78d 100644 (file)
@@ -51,11 +51,11 @@ static void test_istream_concat_one(unsigned int buffer_size)
 
 static bool test_istream_concat_random(void)
 {
-       struct istream **streams, *input;
+       struct istream **streams, *concat, **limits = NULL;
        const unsigned char *data;
        unsigned char *w_data;
        size_t size = 0;
-       unsigned int i, j, offset, stream_count, data_len;
+       unsigned int i, j, offset, stream_count, data_len, simult;
 
        stream_count = (rand() % TEST_MAX_ISTREAM_COUNT) + 2;
        streams = t_new(struct istream *, stream_count + 1);
@@ -70,10 +70,18 @@ static bool test_istream_concat_random(void)
        streams[i] = NULL;
        i_assert(offset > 0);
 
-       input = i_stream_create_concat(streams);
-       i_stream_set_max_buffer_size(input, TEST_MAX_BUFFER_SIZE);
+       concat = i_stream_create_concat(streams);
+       i_stream_set_max_buffer_size(concat, TEST_MAX_BUFFER_SIZE);
+
+       simult = rand() % TEST_MAX_ISTREAM_COUNT;
+       if (simult > 0) {
+               limits = t_new(struct istream *, simult);
+               for (i = 0; i < simult; i++)
+                       limits[i] = i_stream_create_limit(concat, (uoff_t)-1);
+       }
 
        for (i = 0; i < 1000; i++) {
+               struct istream *input = (simult == 0) ? concat : limits[rand() % simult];
                if (rand() % 3 == 0) {
                        i_stream_seek(input, rand() % offset);
                } else {
@@ -97,7 +105,9 @@ static bool test_istream_concat_random(void)
        }
        for (i = 0; i < stream_count; i++)
                i_stream_unref(&streams[i]);
-       i_stream_unref(&input);
+       for (i = 0; i < simult; i++)
+               i_stream_unref(&limits[i]);
+       i_stream_unref(&concat);
        return !test_has_failed();
 }