1
0
forked from cory/tildefriends
Files
apps
core
deps
codemirror
crypt_blowfish
libbacktrace
libbacktrace_config
libsodium
libuv
.github
cmake-toolchains
docs
img
include
m4
src
test
fixtures
benchmark-async-pummel.c
benchmark-async.c
benchmark-fs-stat.c
benchmark-getaddrinfo.c
benchmark-list.h
benchmark-loop-count.c
benchmark-million-async.c
benchmark-million-timers.c
benchmark-multi-accept.c
benchmark-ping-pongs.c
benchmark-ping-udp.c
benchmark-pound.c
benchmark-pump.c
benchmark-queue-work.c
benchmark-sizes.c
benchmark-spawn.c
benchmark-tcp-write-batch.c
benchmark-thread.c
benchmark-udp-pummel.c
blackhole-server.c
echo-server.c
run-benchmarks.c
run-tests.c
runner-unix.c
runner-unix.h
runner-win.c
runner-win.h
runner.c
runner.h
task.h
test-active.c
test-async-null-cb.c
test-async.c
test-barrier.c
test-callback-stack.c
test-close-fd.c
test-close-order.c
test-condvar.c
test-connect-unspecified.c
test-connection-fail.c
test-cwd-and-chdir.c
test-default-loop-close.c
test-delayed-accept.c
test-dlerror.c
test-eintr-handling.c
test-embed.c
test-emfile.c
test-env-vars.c
test-error.c
test-fail-always.c
test-fork.c
test-fs-copyfile.c
test-fs-event.c
test-fs-fd-hash.c
test-fs-open-flags.c
test-fs-poll.c
test-fs-readdir.c
test-fs.c
test-get-currentexe.c
test-get-loadavg.c
test-get-memory.c
test-get-passwd.c
test-getaddrinfo.c
test-gethostname.c
test-getnameinfo.c
test-getsockname.c
test-getters-setters.c
test-gettimeofday.c
test-handle-fileno.c
test-homedir.c
test-hrtime.c
test-idle.c
test-idna.c
test-ip-name.c
test-ip4-addr.c
test-ip6-addr.c
test-ipc-heavy-traffic-deadlock-bug.c
test-ipc-send-recv.c
test-ipc.c
test-list.h
test-loop-alive.c
test-loop-close.c
test-loop-configure.c
test-loop-handles.c
test-loop-stop.c
test-loop-time.c
test-metrics.c
test-multiple-listen.c
test-mutexes.c
test-not-readable-nor-writable-on-read-error.c
test-not-writable-after-shutdown.c
test-osx-select.c
test-pass-always.c
test-ping-pong.c
test-pipe-bind-error.c
test-pipe-close-stdout-read-stdin.c
test-pipe-connect-error.c
test-pipe-connect-multiple.c
test-pipe-connect-prepare.c
test-pipe-getsockname.c
test-pipe-pending-instances.c
test-pipe-sendmsg.c
test-pipe-server-close.c
test-pipe-set-fchmod.c
test-pipe-set-non-blocking.c
test-platform-output.c
test-poll-close-doesnt-corrupt-stack.c
test-poll-close.c
test-poll-closesocket.c
test-poll-multiple-handles.c
test-poll-oob.c
test-poll.c
test-process-priority.c
test-process-title-threadsafe.c
test-process-title.c
test-queue-foreach-delete.c
test-random.c
test-readable-on-eof.c
test-ref.c
test-run-nowait.c
test-run-once.c
test-semaphore.c
test-shutdown-close.c
test-shutdown-eof.c
test-shutdown-simultaneous.c
test-shutdown-twice.c
test-signal-multiple-loops.c
test-signal-pending-on-close.c
test-signal.c
test-socket-buffer-size.c
test-spawn.c
test-stdio-over-pipes.c
test-strscpy.c
test-strtok.c
test-tcp-alloc-cb-fail.c
test-tcp-bind-error.c
test-tcp-bind6-error.c
test-tcp-close-accept.c
test-tcp-close-after-read-timeout.c
test-tcp-close-reset.c
test-tcp-close-while-connecting.c
test-tcp-close.c
test-tcp-connect-error-after-write.c
test-tcp-connect-error.c
test-tcp-connect-timeout.c
test-tcp-connect6-error.c
test-tcp-create-socket-early.c
test-tcp-flags.c
test-tcp-oob.c
test-tcp-open.c
test-tcp-read-stop-start.c
test-tcp-read-stop.c
test-tcp-rst.c
test-tcp-shutdown-after-write.c
test-tcp-try-write-error.c
test-tcp-try-write.c
test-tcp-unexpected-read.c
test-tcp-write-after-connect.c
test-tcp-write-fail.c
test-tcp-write-in-a-row.c
test-tcp-write-queue-order.c
test-tcp-write-to-half-open-connection.c
test-tcp-writealot.c
test-test-macros.c
test-thread-affinity.c
test-thread-equal.c
test-thread.c
test-threadpool-cancel.c
test-threadpool.c
test-timer-again.c
test-timer-from-check.c
test-timer.c
test-tmpdir.c
test-tty-duplicate-key.c
test-tty-escape-sequence-processing.c
test-tty.c
test-udp-alloc-cb-fail.c
test-udp-bind.c
test-udp-connect.c
test-udp-connect6.c
test-udp-create-socket-early.c
test-udp-dgram-too-big.c
test-udp-ipv6.c
test-udp-mmsg.c
test-udp-multicast-interface.c
test-udp-multicast-interface6.c
test-udp-multicast-join.c
test-udp-multicast-join6.c
test-udp-multicast-ttl.c
test-udp-open.c
test-udp-options.c
test-udp-recv-in-a-row.c
test-udp-send-and-recv.c
test-udp-send-hang-loop.c
test-udp-send-immediate.c
test-udp-send-unreachable.c
test-udp-sendmmsg-error.c
test-udp-try-send.c
test-uname.c
test-walk-handles.c
test-watcher-cross-stop.c
tools
.gitattributes
.gitignore
.mailmap
.readthedocs.yaml
AUTHORS
CMakeLists.txt
CONTRIBUTING.md
ChangeLog
LICENSE
LICENSE-docs
LICENSE-extra
LINKS.md
MAINTAINERS.md
Makefile.am
README.md
SUPPORTED_PLATFORMS.md
autogen.sh
configure.ac
libuv-static.pc.in
libuv.pc.in
tsansupp.txt
uv_win_longpath.manifest
lit
openssl
picohttpparser
quickjs
smoothie
speedscope
split
sqlite
xopt
zlib
docs
src
tools
.dockerignore
Dockerfile
LICENSE
Makefile
README.md
tildefriends/deps/libuv/test/test-timer-again.c

142 lines
4.1 KiB
C
Raw Normal View History

/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "uv.h"
#include "task.h"
static int close_cb_called = 0;
static int repeat_1_cb_called = 0;
static int repeat_2_cb_called = 0;
static int repeat_2_cb_allowed = 0;
static uv_timer_t dummy, repeat_1, repeat_2;
static uint64_t start_time;
static void close_cb(uv_handle_t* handle) {
ASSERT_NOT_NULL(handle);
close_cb_called++;
}
static void repeat_1_cb(uv_timer_t* handle) {
int r;
ASSERT(handle == &repeat_1);
ASSERT(uv_timer_get_repeat((uv_timer_t*)handle) == 50);
fprintf(stderr, "repeat_1_cb called after %ld ms\n",
(long int)(uv_now(uv_default_loop()) - start_time));
fflush(stderr);
repeat_1_cb_called++;
r = uv_timer_again(&repeat_2);
ASSERT(r == 0);
if (repeat_1_cb_called == 10) {
uv_close((uv_handle_t*)handle, close_cb);
/* We're not calling uv_timer_again on repeat_2 any more, so after this
* timer_2_cb is expected. */
repeat_2_cb_allowed = 1;
return;
}
}
static void repeat_2_cb(uv_timer_t* handle) {
ASSERT(handle == &repeat_2);
ASSERT(repeat_2_cb_allowed);
fprintf(stderr, "repeat_2_cb called after %ld ms\n",
(long int)(uv_now(uv_default_loop()) - start_time));
fflush(stderr);
repeat_2_cb_called++;
if (uv_timer_get_repeat(&repeat_2) == 0) {
ASSERT(0 == uv_is_active((uv_handle_t*) handle));
uv_close((uv_handle_t*)handle, close_cb);
return;
}
fprintf(stderr, "uv_timer_get_repeat %ld ms\n",
(long int)uv_timer_get_repeat(&repeat_2));
fflush(stderr);
ASSERT(uv_timer_get_repeat(&repeat_2) == 100);
/* This shouldn't take effect immediately. */
uv_timer_set_repeat(&repeat_2, 0);
}
TEST_IMPL(timer_again) {
int r;
start_time = uv_now(uv_default_loop());
ASSERT(0 < start_time);
/* Verify that it is not possible to uv_timer_again a never-started timer. */
r = uv_timer_init(uv_default_loop(), &dummy);
ASSERT(r == 0);
r = uv_timer_again(&dummy);
ASSERT(r == UV_EINVAL);
uv_unref((uv_handle_t*)&dummy);
/* Start timer repeat_1. */
r = uv_timer_init(uv_default_loop(), &repeat_1);
ASSERT(r == 0);
r = uv_timer_start(&repeat_1, repeat_1_cb, 50, 0);
ASSERT(r == 0);
ASSERT(uv_timer_get_repeat(&repeat_1) == 0);
/* Actually make repeat_1 repeating. */
uv_timer_set_repeat(&repeat_1, 50);
ASSERT(uv_timer_get_repeat(&repeat_1) == 50);
/*
* Start another repeating timer. It'll be again()ed by the repeat_1 so
* it should not time out until repeat_1 stops.
*/
r = uv_timer_init(uv_default_loop(), &repeat_2);
ASSERT(r == 0);
r = uv_timer_start(&repeat_2, repeat_2_cb, 100, 100);
ASSERT(r == 0);
ASSERT(uv_timer_get_repeat(&repeat_2) == 100);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(repeat_1_cb_called == 10);
ASSERT(repeat_2_cb_called == 2);
ASSERT(close_cb_called == 2);
fprintf(stderr, "Test took %ld ms (expected ~700 ms)\n",
(long int)(uv_now(uv_default_loop()) - start_time));
fflush(stderr);
MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0;
}