]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-program-client: test-program-client-net - Add test for delayed disconnect after...
authorStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 3 May 2021 21:54:11 +0000 (23:54 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 5 May 2021 18:26:46 +0000 (18:26 +0000)
src/lib-program-client/test-program-client-net.c

index 9dc98182c3ce4a128016c3f26b5cfb8a936a5c6f..9aa424680bcb822225bfe85c0be718f818858767 100644 (file)
@@ -164,9 +164,16 @@ test_program_input_handle(struct test_client *client, const char *line)
        return 0;
 }
 
+static void test_program_end(struct test_client *client)
+{
+       timeout_remove(&test_globals.to);
+       test_program_client_destroy(&client);
+}
+
 static void test_program_run(struct test_client *client)
 {
        const char *const *args;
+       bool disconnect_later = FALSE;
        unsigned int count;
 
        struct ostream *os;
@@ -195,8 +202,18 @@ static void test_program_run(struct test_client *client)
                        }
                } else
                        o_stream_nsend_str(client->out, ".\n-\n");
+               if (count >= 3 && strcmp(args[1], "slow_disconnect") == 0)
+                       disconnect_later = TRUE;
+       }
+
+       test_assert(o_stream_flush(client->out) > 0);
+
+       if (!disconnect_later)
+               test_program_client_destroy(&client);
+       else {
+               test_globals.to = timeout_add_short(
+                       500, test_program_end, client);
        }
-       test_program_client_destroy(&client);
 }
 
 static void test_program_input(struct test_client *client)
@@ -341,17 +358,11 @@ static void test_program_success(void)
        test_end();
 }
 
-static void test_program_io(void)
+static void test_program_io_common(const char *const *args)
 {
        struct program_client *pc;
        int ret = -2;
 
-       const char *const args[] = {
-               "test_program_io", NULL
-       };
-
-       test_begin("test_program_io (async)");
-
        pc = program_client_net_create("127.0.0.1", test_globals.port, args,
                                       &pc_set, FALSE);
 
@@ -377,6 +388,25 @@ static void test_program_io(void)
        buffer_free(&output);
 
        i_assert(test_globals.client == NULL);
+}
+
+static void test_program_io(void)
+{
+       const char *args[3] = {
+               "test_program_io", NULL, NULL
+       };
+
+       test_begin("test_program_io (async)");
+
+       test_program_io_common(args);
+
+       test_end();
+
+       args[1] = "slow_disconnect";
+
+       test_begin("test_program_io (async, slow disconnect)");
+
+       test_program_io_common(args);
 
        test_end();
 }