Mercurial > dovecot > core-2.2
changeset 22785:bfb8e1924e75
lib-program-client: local: Add test for big data I/O.
author | Stephan Bosch <stephan.bosch@dovecot.fi> |
---|---|
date | Sat, 20 Jan 2018 21:32:07 +0100 |
parents | 99acd6d25ad2 |
children | 7b6f77272538 |
files | src/lib-program-client/test-program-client-local.c |
diffstat | 1 files changed, 53 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-program-client/test-program-client-local.c Wed Jan 24 01:09:16 2018 +0100 +++ b/src/lib-program-client/test-program-client-local.c Sat Jan 20 21:32:07 2018 +0100 @@ -6,6 +6,7 @@ #include "buffer.h" #include "str.h" #include "istream.h" +#include "istream-concat.h" #include "ostream.h" #include "lib-signals.h" #include "program-client.h" @@ -168,6 +169,57 @@ test_end(); } +static +void test_program_io_big(void) { + test_begin("test_program_io (big)"); + + /* nasty program that reads data in bits with intermittent delays + and then finally reads the rest in one go. */ + const char *const args[] = { + "-c", + "(head -c 10240; sleep 0.1; " + "head -c 10240; sleep 0.1; " + "head -c 10240; sleep 0.1; " + "head -c 10240; sleep 0.1; " + "head -c 10240; sleep 0.1; " + "head -c 10240; sleep 0.1; cat)", + NULL + }; + + struct program_client *pc = + program_client_local_create("/bin/sh", args, &pc_set); + + /* make big input with only a small reference string */ + struct istream *is1 = test_istream_create(pclient_test_io_string); + struct istream *in1[11] = {is1, is1, is1, is1, is1, + is1, is1, is1, is1, is1, NULL}; + struct istream *is2 = i_stream_create_concat(in1); + struct istream *in2[11] = {is2, is2, is2, is2, is2, + is2, is2, is2, is2, is2, NULL}; + struct istream *is3 = i_stream_create_concat(in2); + struct istream *in3[11] = {is3, is3, is3, is3, is3, + is3, is3, is3, is3, is3, NULL}; + struct istream *is = i_stream_create_concat(in3); + + program_client_set_input(pc, is); + + buffer_t *output = buffer_create_dynamic(default_pool, 16); + struct ostream *os = test_ostream_create(output); + program_client_set_output(pc, os); + + test_assert(program_client_run(pc) == 1); + + test_assert(str_len(output) == strlen(pclient_test_io_string)*10*10*10); + + program_client_destroy(&pc); + + i_stream_unref(&is); + o_stream_unref(&os); + buffer_free(&output); + + test_end(); +} + int main(void) { int ret; @@ -176,6 +228,7 @@ test_program_success, test_program_io_sync, test_program_io_async, + test_program_io_big, test_program_failure, NULL };