if (ioloop->handler_context != NULL)
io_loop_handler_deinit(ioloop);
-
- i_assert(ioloop->cur_ctx == NULL);
+ if (ioloop->cur_ctx != NULL)
+ io_loop_context_unref(&ioloop->cur_ctx);
i_free(ioloop);
}
test_end();
}
+static void test_ioloop_context_callback(struct ioloop_context *ctx)
+{
+ test_assert(io_loop_get_current_context(current_ioloop) == ctx);
+ io_loop_stop(current_ioloop);
+}
+
+static void test_ioloop_context(void)
+{
+ test_begin("ioloop context");
+ struct ioloop *ioloop = io_loop_create();
+ struct ioloop_context *ctx = io_loop_context_new(ioloop);
+
+ test_assert(io_loop_get_current_context(current_ioloop) == NULL);
+ io_loop_context_activate(ctx);
+ test_assert(io_loop_get_current_context(current_ioloop) == ctx);
+ struct timeout *to = timeout_add(0, test_ioloop_context_callback, ctx);
+
+ io_loop_run(ioloop);
+ test_assert(io_loop_get_current_context(current_ioloop) == NULL);
+ /* test that we don't crash at deinit if we leave the context active */
+ io_loop_context_activate(ctx);
+ test_assert(io_loop_get_current_context(current_ioloop) == ctx);
+
+ timeout_remove(&to);
+ io_loop_context_unref(&ctx);
+ io_loop_destroy(&ioloop);
+ test_end();
+}
+
void test_ioloop(void)
{
test_ioloop_timeout();
test_ioloop_find_fd_conditions();
test_ioloop_pending_io();
test_ioloop_fd();
+ test_ioloop_context();
}