test: add tests for bad inputs
This commit adds tests that pass bad options to uv_fs_copyfile(), uv_fs_read(), and uv_fs_write(). These tests verify that the asynchronous version of these functions do not hold the event loop open on bad inputs. Refs: https://github.com/nodejs/node/pull/18811 PR-URL: https://github.com/libuv/libuv/pull/1747 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
dab311afe9
commit
e485d28674
@ -36,6 +36,10 @@ static const char dst[] = "test_file_dst";
|
|||||||
static int result_check_count;
|
static int result_check_count;
|
||||||
|
|
||||||
|
|
||||||
|
static void fail_cb(uv_fs_t* req) {
|
||||||
|
FATAL("fail_cb should not have been called");
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_result(uv_fs_t* req) {
|
static void handle_result(uv_fs_t* req) {
|
||||||
uv_fs_t stat_req;
|
uv_fs_t stat_req;
|
||||||
uint64_t size;
|
uint64_t size;
|
||||||
@ -158,7 +162,12 @@ TEST_IMPL(fs_copyfile) {
|
|||||||
ASSERT(result_check_count == 5);
|
ASSERT(result_check_count == 5);
|
||||||
uv_run(loop, UV_RUN_DEFAULT);
|
uv_run(loop, UV_RUN_DEFAULT);
|
||||||
ASSERT(result_check_count == 6);
|
ASSERT(result_check_count == 6);
|
||||||
unlink(dst); /* Cleanup */
|
|
||||||
|
|
||||||
|
/* If the flags are invalid, the loop should not be kept open */
|
||||||
|
unlink(dst);
|
||||||
|
r = uv_fs_copyfile(loop, &req, fixture, dst, -1, fail_cb);
|
||||||
|
ASSERT(r == UV_EINVAL);
|
||||||
|
uv_run(loop, UV_RUN_DEFAULT);
|
||||||
|
unlink(dst); /* Cleanup */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -319,6 +319,9 @@ static void ftruncate_cb(uv_fs_t* req) {
|
|||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void fail_cb(uv_fs_t* req) {
|
||||||
|
FATAL("fail_cb should not have been called");
|
||||||
|
}
|
||||||
|
|
||||||
static void read_cb(uv_fs_t* req) {
|
static void read_cb(uv_fs_t* req) {
|
||||||
int r;
|
int r;
|
||||||
@ -2897,6 +2900,31 @@ TEST_IMPL(fs_read_write_null_arguments) {
|
|||||||
ASSERT(r == UV_EINVAL);
|
ASSERT(r == UV_EINVAL);
|
||||||
uv_fs_req_cleanup(&write_req);
|
uv_fs_req_cleanup(&write_req);
|
||||||
|
|
||||||
|
/* If the arguments are invalid, the loop should not be kept open */
|
||||||
|
loop = uv_default_loop();
|
||||||
|
|
||||||
|
r = uv_fs_read(loop, &read_req, 0, NULL, 0, -1, fail_cb);
|
||||||
|
ASSERT(r == UV_EINVAL);
|
||||||
|
uv_run(loop, UV_RUN_DEFAULT);
|
||||||
|
uv_fs_req_cleanup(&read_req);
|
||||||
|
|
||||||
|
r = uv_fs_write(loop, &write_req, 0, NULL, 0, -1, fail_cb);
|
||||||
|
ASSERT(r == UV_EINVAL);
|
||||||
|
uv_run(loop, UV_RUN_DEFAULT);
|
||||||
|
uv_fs_req_cleanup(&write_req);
|
||||||
|
|
||||||
|
iov = uv_buf_init(NULL, 0);
|
||||||
|
r = uv_fs_read(loop, &read_req, 0, &iov, 0, -1, fail_cb);
|
||||||
|
ASSERT(r == UV_EINVAL);
|
||||||
|
uv_run(loop, UV_RUN_DEFAULT);
|
||||||
|
uv_fs_req_cleanup(&read_req);
|
||||||
|
|
||||||
|
iov = uv_buf_init(NULL, 0);
|
||||||
|
r = uv_fs_write(loop, &write_req, 0, &iov, 0, -1, fail_cb);
|
||||||
|
ASSERT(r == UV_EINVAL);
|
||||||
|
uv_run(loop, UV_RUN_DEFAULT);
|
||||||
|
uv_fs_req_cleanup(&write_req);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user