test: make sure all handles in the loop are closed
This commit is contained in:
parent
29ed404138
commit
e4f28adce4
18
test/task.h
18
test/task.h
@ -22,6 +22,8 @@
|
|||||||
#ifndef TASK_H_
|
#ifndef TASK_H_
|
||||||
#define TASK_H_
|
#define TASK_H_
|
||||||
|
|
||||||
|
#include "uv.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -113,7 +115,10 @@ typedef enum {
|
|||||||
* warnings about memory being "leaked" by the main event loop.
|
* warnings about memory being "leaked" by the main event loop.
|
||||||
*/
|
*/
|
||||||
#define MAKE_VALGRIND_HAPPY() \
|
#define MAKE_VALGRIND_HAPPY() \
|
||||||
uv_loop_delete(uv_default_loop())
|
do { \
|
||||||
|
close_loop(uv_default_loop()); \
|
||||||
|
uv_loop_delete(uv_default_loop()); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
/* Just sugar for wrapping the main() for a task or helper. */
|
/* Just sugar for wrapping the main() for a task or helper. */
|
||||||
#define TEST_IMPL(name) \
|
#define TEST_IMPL(name) \
|
||||||
@ -204,4 +209,15 @@ static int snprintf(char* buf, size_t len, const char* fmt, ...) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Fully close a loop */
|
||||||
|
static void close_walk_cb(uv_handle_t* handle, void* arg) {
|
||||||
|
if (!uv_is_closing(handle))
|
||||||
|
uv_close(handle, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void close_loop(uv_loop_t* loop) {
|
||||||
|
uv_walk(loop, close_walk_cb, NULL);
|
||||||
|
uv_run(loop, UV_RUN_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* TASK_H_ */
|
#endif /* TASK_H_ */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user