asyncengine 0.0.1.testing1 → 0.0.2.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -0
- data/Rakefile +38 -0
- data/asyncengine.gemspec +8 -4
- data/ext/asyncengine/ae_call_from_other_thread.c +106 -0
- data/ext/asyncengine/ae_call_from_other_thread.h +12 -0
- data/ext/asyncengine/ae_handle_common.c +193 -48
- data/ext/asyncengine/ae_handle_common.h +40 -13
- data/ext/asyncengine/ae_ip_utils.c +246 -0
- data/ext/asyncengine/ae_ip_utils.h +25 -0
- data/ext/asyncengine/ae_next_tick.c +81 -21
- data/ext/asyncengine/ae_next_tick.h +4 -2
- data/ext/asyncengine/ae_resolver.c +156 -0
- data/ext/asyncengine/ae_resolver.h +10 -0
- data/ext/asyncengine/ae_tcp.c +908 -0
- data/ext/asyncengine/ae_tcp.h +20 -0
- data/ext/asyncengine/ae_timer.c +355 -81
- data/ext/asyncengine/ae_timer.h +11 -4
- data/ext/asyncengine/ae_udp.c +579 -13
- data/ext/asyncengine/ae_udp.h +15 -2
- data/ext/asyncengine/ae_utils.c +192 -0
- data/ext/asyncengine/ae_utils.h +16 -0
- data/ext/asyncengine/asyncengine_ruby.c +469 -26
- data/ext/asyncengine/asyncengine_ruby.h +49 -11
- data/ext/asyncengine/debug.h +68 -0
- data/ext/asyncengine/extconf.rb +26 -2
- data/ext/asyncengine/ip_parser.c +5954 -0
- data/ext/asyncengine/ip_parser.h +16 -0
- data/ext/asyncengine/libuv/AUTHORS +16 -0
- data/ext/asyncengine/libuv/common.gypi +4 -4
- data/ext/asyncengine/libuv/config-mingw.mk +6 -6
- data/ext/asyncengine/libuv/config-unix.mk +13 -13
- data/ext/asyncengine/libuv/gyp_uv +5 -1
- data/ext/asyncengine/libuv/ibc_tests/exec_test.sh +8 -0
- data/ext/asyncengine/libuv/ibc_tests/uv_shutdown_write_issue.c +171 -0
- data/ext/asyncengine/libuv/ibc_tests/uv_tcp_close_while_connecting.c +102 -0
- data/ext/asyncengine/libuv/include/uv-private/ngx-queue.h +3 -1
- data/ext/asyncengine/libuv/include/uv-private/uv-unix.h +103 -50
- data/ext/asyncengine/libuv/include/uv-private/uv-win.h +76 -24
- data/ext/asyncengine/libuv/include/uv.h +353 -88
- data/ext/asyncengine/libuv/src/ares/ares__close_sockets.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares__get_hostent.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares__read_line.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares__timeval.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_cancel.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_data.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_destroy.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_expand_name.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_expand_string.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_fds.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_free_hostent.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_free_string.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_gethostbyaddr.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_gethostbyname.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_getnameinfo.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_getopt.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_getsock.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_init.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_library_init.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_llist.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_mkquery.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_nowarn.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_options.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_a_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_aaaa_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_mx_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_ns_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_ptr_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_srv_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_txt_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_process.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_query.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_search.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_send.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_strcasecmp.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_strdup.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_strerror.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_timeout.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_version.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_writev.o +0 -0
- data/ext/asyncengine/libuv/src/ares/bitncmp.o +0 -0
- data/ext/asyncengine/libuv/src/ares/inet_net_pton.o +0 -0
- data/ext/asyncengine/libuv/src/ares/inet_ntop.o +0 -0
- data/ext/asyncengine/libuv/src/cares.c +225 -0
- data/ext/asyncengine/libuv/src/cares.o +0 -0
- data/ext/asyncengine/libuv/src/fs-poll.c +237 -0
- data/ext/asyncengine/libuv/src/fs-poll.o +0 -0
- data/ext/asyncengine/libuv/src/unix/async.c +78 -17
- data/ext/asyncengine/libuv/src/unix/async.o +0 -0
- data/ext/asyncengine/libuv/src/unix/core.c +305 -213
- data/ext/asyncengine/libuv/src/unix/core.o +0 -0
- data/ext/asyncengine/libuv/src/unix/cygwin.c +1 -1
- data/ext/asyncengine/libuv/src/unix/darwin.c +2 -1
- data/ext/asyncengine/libuv/src/unix/dl.c +36 -44
- data/ext/asyncengine/libuv/src/unix/dl.o +0 -0
- data/ext/asyncengine/libuv/src/unix/eio/eio.o +0 -0
- data/ext/asyncengine/libuv/src/unix/error.c +6 -0
- data/ext/asyncengine/libuv/src/unix/error.o +0 -0
- data/ext/asyncengine/libuv/src/unix/ev/ev.c +8 -4
- data/ext/asyncengine/libuv/src/unix/ev/ev.o +0 -0
- data/ext/asyncengine/libuv/src/unix/freebsd.c +1 -1
- data/ext/asyncengine/libuv/src/unix/fs.c +25 -33
- data/ext/asyncengine/libuv/src/unix/fs.o +0 -0
- data/ext/asyncengine/libuv/src/unix/internal.h +50 -31
- data/ext/asyncengine/libuv/src/unix/kqueue.c +2 -7
- data/ext/asyncengine/libuv/src/unix/linux/core.o +0 -0
- data/ext/asyncengine/libuv/src/unix/linux/inotify.c +12 -14
- data/ext/asyncengine/libuv/src/unix/linux/inotify.o +0 -0
- data/ext/asyncengine/libuv/src/unix/linux/{core.c → linux-core.c} +1 -1
- data/ext/asyncengine/libuv/src/unix/linux/linux-core.o +0 -0
- data/ext/asyncengine/libuv/src/unix/linux/syscalls.c +147 -1
- data/ext/asyncengine/libuv/src/unix/linux/syscalls.h +39 -2
- data/ext/asyncengine/libuv/src/unix/linux/syscalls.o +0 -0
- data/ext/asyncengine/libuv/src/unix/loop-watcher.c +63 -0
- data/ext/asyncengine/libuv/src/unix/loop-watcher.o +0 -0
- data/ext/asyncengine/libuv/src/unix/loop.c +29 -6
- data/ext/asyncengine/libuv/src/unix/loop.o +0 -0
- data/ext/asyncengine/libuv/src/unix/netbsd.c +1 -1
- data/ext/asyncengine/libuv/src/unix/openbsd.c +1 -1
- data/ext/asyncengine/libuv/src/unix/pipe.c +31 -36
- data/ext/asyncengine/libuv/src/unix/pipe.o +0 -0
- data/ext/asyncengine/libuv/src/unix/poll.c +116 -0
- data/ext/asyncengine/libuv/src/unix/poll.o +0 -0
- data/ext/asyncengine/libuv/src/unix/process.c +193 -115
- data/ext/asyncengine/libuv/src/unix/process.o +0 -0
- data/ext/asyncengine/libuv/src/unix/stream.c +146 -153
- data/ext/asyncengine/libuv/src/unix/stream.o +0 -0
- data/ext/asyncengine/libuv/src/unix/sunos.c +45 -36
- data/ext/asyncengine/libuv/src/unix/tcp.c +6 -5
- data/ext/asyncengine/libuv/src/unix/tcp.o +0 -0
- data/ext/asyncengine/libuv/src/unix/thread.c +82 -25
- data/ext/asyncengine/libuv/src/unix/thread.o +0 -0
- data/ext/asyncengine/libuv/src/unix/timer.c +69 -58
- data/ext/asyncengine/libuv/src/unix/timer.o +0 -0
- data/ext/asyncengine/libuv/src/unix/tty.c +3 -3
- data/ext/asyncengine/libuv/src/unix/tty.o +0 -0
- data/ext/asyncengine/libuv/src/unix/udp.c +57 -66
- data/ext/asyncengine/libuv/src/unix/udp.o +0 -0
- data/ext/asyncengine/libuv/src/unix/uv-eio.c +33 -50
- data/ext/asyncengine/libuv/src/unix/uv-eio.o +0 -0
- data/ext/asyncengine/libuv/src/uv-common.c +68 -38
- data/ext/asyncengine/libuv/src/uv-common.h +104 -20
- data/ext/asyncengine/libuv/src/uv-common.o +0 -0
- data/ext/asyncengine/libuv/src/win/async.c +20 -17
- data/ext/asyncengine/libuv/src/win/core.c +44 -31
- data/ext/asyncengine/libuv/src/win/dl.c +40 -36
- data/ext/asyncengine/libuv/src/win/error.c +21 -1
- data/ext/asyncengine/libuv/src/win/fs-event.c +19 -21
- data/ext/asyncengine/libuv/src/win/fs.c +541 -189
- data/ext/asyncengine/libuv/src/win/getaddrinfo.c +56 -63
- data/ext/asyncengine/libuv/src/win/handle-inl.h +145 -0
- data/ext/asyncengine/libuv/src/win/handle.c +26 -101
- data/ext/asyncengine/libuv/src/win/internal.h +92 -107
- data/ext/asyncengine/libuv/src/win/loop-watcher.c +6 -14
- data/ext/asyncengine/libuv/src/win/pipe.c +78 -64
- data/ext/asyncengine/libuv/src/win/poll.c +618 -0
- data/ext/asyncengine/libuv/src/win/process-stdio.c +479 -0
- data/ext/asyncengine/libuv/src/win/process.c +147 -274
- data/ext/asyncengine/libuv/src/win/req-inl.h +225 -0
- data/ext/asyncengine/libuv/src/win/req.c +0 -149
- data/ext/asyncengine/libuv/src/{unix/check.c → win/stream-inl.h} +31 -42
- data/ext/asyncengine/libuv/src/win/stream.c +9 -43
- data/ext/asyncengine/libuv/src/win/tcp.c +200 -82
- data/ext/asyncengine/libuv/src/win/thread.c +42 -2
- data/ext/asyncengine/libuv/src/win/threadpool.c +3 -2
- data/ext/asyncengine/libuv/src/win/timer.c +13 -63
- data/ext/asyncengine/libuv/src/win/tty.c +26 -20
- data/ext/asyncengine/libuv/src/win/udp.c +26 -17
- data/ext/asyncengine/libuv/src/win/util.c +312 -167
- data/ext/asyncengine/libuv/src/win/winapi.c +16 -1
- data/ext/asyncengine/libuv/src/win/winapi.h +33 -9
- data/ext/asyncengine/libuv/src/win/winsock.c +88 -1
- data/ext/asyncengine/libuv/src/win/winsock.h +36 -3
- data/ext/asyncengine/libuv/test/benchmark-ares.c +16 -17
- data/ext/asyncengine/libuv/test/benchmark-fs-stat.c +164 -0
- data/ext/asyncengine/libuv/test/benchmark-list.h +9 -0
- data/ext/asyncengine/libuv/{src/unix/prepare.c → test/benchmark-loop-count.c} +42 -33
- data/ext/asyncengine/libuv/test/benchmark-million-timers.c +65 -0
- data/ext/asyncengine/libuv/test/benchmark-pound.c +1 -1
- data/ext/asyncengine/libuv/test/benchmark-sizes.c +2 -0
- data/ext/asyncengine/libuv/test/benchmark-spawn.c +7 -1
- data/ext/asyncengine/libuv/test/benchmark-udp-packet-storm.c +1 -1
- data/ext/asyncengine/libuv/test/echo-server.c +8 -0
- data/ext/asyncengine/libuv/test/run-tests.c +30 -0
- data/ext/asyncengine/libuv/test/runner-unix.c +6 -26
- data/ext/asyncengine/libuv/test/runner-win.c +5 -63
- data/ext/asyncengine/libuv/test/runner.c +10 -1
- data/ext/asyncengine/libuv/test/task.h +0 -8
- data/ext/asyncengine/libuv/test/test-async.c +43 -141
- data/ext/asyncengine/libuv/test/test-callback-order.c +76 -0
- data/ext/asyncengine/libuv/test/test-counters-init.c +2 -3
- data/ext/asyncengine/libuv/test/test-dlerror.c +17 -8
- data/ext/asyncengine/libuv/test/test-fs-event.c +31 -39
- data/ext/asyncengine/libuv/test/test-fs-poll.c +146 -0
- data/ext/asyncengine/libuv/test/test-fs.c +114 -2
- data/ext/asyncengine/libuv/test/test-gethostbyname.c +8 -8
- data/ext/asyncengine/libuv/test/test-hrtime.c +18 -15
- data/ext/asyncengine/libuv/test/test-ipc.c +8 -2
- data/ext/asyncengine/libuv/test/test-list.h +59 -9
- data/ext/asyncengine/libuv/test/test-loop-handles.c +2 -25
- data/ext/asyncengine/libuv/{src/unix/idle.c → test/test-poll-close.c} +37 -39
- data/ext/asyncengine/libuv/test/test-poll.c +573 -0
- data/ext/asyncengine/libuv/test/test-ref.c +79 -63
- data/ext/asyncengine/libuv/test/test-run-once.c +15 -11
- data/ext/asyncengine/libuv/test/test-semaphore.c +111 -0
- data/ext/asyncengine/libuv/test/test-spawn.c +368 -20
- data/ext/asyncengine/libuv/test/test-stdio-over-pipes.c +25 -35
- data/ext/asyncengine/libuv/test/test-tcp-close-while-connecting.c +80 -0
- data/ext/asyncengine/libuv/test/test-tcp-close.c +1 -1
- data/ext/asyncengine/libuv/test/test-tcp-connect-error-after-write.c +95 -0
- data/ext/asyncengine/libuv/test/test-tcp-connect-timeout.c +85 -0
- data/ext/asyncengine/libuv/test/test-tcp-shutdown-after-write.c +131 -0
- data/ext/asyncengine/libuv/test/test-tcp-write-error.c +2 -2
- data/ext/asyncengine/libuv/test/test-tcp-writealot.c +29 -54
- data/ext/asyncengine/libuv/test/test-timer-again.c +1 -1
- data/ext/asyncengine/libuv/test/test-timer.c +23 -1
- data/ext/asyncengine/libuv/test/test-udp-options.c +1 -1
- data/ext/asyncengine/libuv/test/{test-eio-overflow.c → test-walk-handles.c} +31 -44
- data/ext/asyncengine/libuv/uv.gyp +26 -9
- data/ext/asyncengine/rb_utilities.c +54 -0
- data/ext/asyncengine/rb_utilities.h +63 -0
- data/lib/asyncengine.rb +45 -38
- data/lib/asyncengine/asyncengine_ext.so +0 -0
- data/lib/asyncengine/debug.rb +37 -0
- data/lib/asyncengine/handle.rb +9 -0
- data/lib/asyncengine/tcp.rb +28 -0
- data/lib/asyncengine/timer.rb +18 -28
- data/lib/asyncengine/udp.rb +29 -0
- data/lib/asyncengine/utils.rb +32 -0
- data/lib/asyncengine/uv_error.rb +17 -0
- data/lib/asyncengine/version.rb +9 -1
- data/test/ae_test_helper.rb +62 -0
- data/test/test_basic.rb +169 -0
- data/test/test_call_from_other_thread.rb +55 -0
- data/test/test_error.rb +92 -0
- data/test/test_ip_utils.rb +44 -0
- data/test/test_next_tick.rb +37 -0
- data/test/test_resolver.rb +51 -0
- data/test/test_threads.rb +69 -0
- data/test/test_timer.rb +95 -0
- data/test/test_udp.rb +216 -0
- data/test/test_utils.rb +49 -0
- metadata +84 -57
- data/ext/asyncengine/libuv/mkmf.log +0 -24
- data/ext/asyncengine/libuv/src/unix/cares.c +0 -194
- data/ext/asyncengine/libuv/src/unix/cares.o +0 -0
- data/ext/asyncengine/libuv/src/unix/check.o +0 -0
- data/ext/asyncengine/libuv/src/unix/idle.o +0 -0
- data/ext/asyncengine/libuv/src/unix/prepare.o +0 -0
- data/ext/asyncengine/libuv/src/win/cares.c +0 -290
- data/lib/asyncengine/errors.rb +0 -5
- data/lib/asyncengine/next_tick.rb +0 -24
data/lib/asyncengine/version.rb
CHANGED
@@ -1,3 +1,11 @@
|
|
1
1
|
module AsyncEngine
|
2
|
-
|
2
|
+
module Version
|
3
|
+
MAJOR = 0
|
4
|
+
MINOR = 0
|
5
|
+
TINY = 2
|
6
|
+
DEVEL = "alpha1" # Set to nil for stable releases.
|
7
|
+
end
|
8
|
+
|
9
|
+
VERSION = [Version::MAJOR, Version::MINOR, Version::TINY].join(".")
|
10
|
+
VERSION << ".#{Version::DEVEL}" if Version::DEVEL
|
3
11
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "asyncengine"
|
2
|
+
require "test/unit"
|
3
|
+
require "socket"
|
4
|
+
|
5
|
+
|
6
|
+
class AETest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def assert_true(object, message="")
|
9
|
+
assert_equal(true, object, message)
|
10
|
+
end
|
11
|
+
|
12
|
+
def assert_false(object, message="")
|
13
|
+
assert_equal(false, object, message)
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
AE.ensure_released
|
18
|
+
end
|
19
|
+
|
20
|
+
def host_loopback_ipv4 ; @@host_loopback_ipv4 ; end
|
21
|
+
def host_ipv4 ; @@host_ipv4 ; end
|
22
|
+
def host_loopback_ipv6 ; @@host_loopback_ipv6 ; end
|
23
|
+
def host_ipv6 ; @@host_ipv6 ; end
|
24
|
+
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def self.get_host_ipv4 loopback
|
29
|
+
remote_ip = ( loopback ? "127.0.0.1" : "1.2.3.4" )
|
30
|
+
orig, ::Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
|
31
|
+
::UDPSocket.open(::Socket::AF_INET) do |s|
|
32
|
+
s.connect remote_ip, 1
|
33
|
+
s.addr.last
|
34
|
+
end
|
35
|
+
rescue => e
|
36
|
+
warn "WARN: ae_test_helper.rb: cannot get IPv4 #{loopback ? "loopback " : ""}address in this host, some tests will be skipped"
|
37
|
+
false
|
38
|
+
ensure
|
39
|
+
::Socket.do_not_reverse_lookup = orig
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.get_host_ipv6 loopback
|
43
|
+
remote_ip = ( loopback ? "::1" : "2001::1" )
|
44
|
+
orig, ::Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
|
45
|
+
::UDPSocket.open(::Socket::AF_INET6) do |s|
|
46
|
+
s.connect remote_ip, 1
|
47
|
+
s.addr.last
|
48
|
+
end
|
49
|
+
rescue => e
|
50
|
+
warn "WARN: ae_test_helper.rb: cannot get IPv6 #{loopback ? "loopback " : ""}address in this host, some tests will be skipped"
|
51
|
+
false
|
52
|
+
ensure
|
53
|
+
::Socket.do_not_reverse_lookup = orig
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
@@host_loopback_ipv4 = get_host_ipv4 loopback=true
|
58
|
+
@@host_ipv4 = get_host_ipv4 loopback=false
|
59
|
+
@@host_loopback_ipv6 = get_host_ipv6 loopback=true
|
60
|
+
@@host_ipv6 = get_host_ipv6 loopback=false
|
61
|
+
|
62
|
+
end
|
data/test/test_basic.rb
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
require "ae_test_helper"
|
2
|
+
|
3
|
+
|
4
|
+
class TestBasic < AETest
|
5
|
+
|
6
|
+
def test_01_AE_is_restartable
|
7
|
+
str = ""
|
8
|
+
|
9
|
+
assert_false AE.running?
|
10
|
+
AE.run { assert_true AE.running? ; AE.stop }
|
11
|
+
assert_false AE.running?
|
12
|
+
|
13
|
+
assert_true AE.run { AE.stop }
|
14
|
+
assert_false AE.running?
|
15
|
+
|
16
|
+
assert_true AE.run { AE.add_timer(0.001) { assert_true AE.running? ; str << "a" ; AE.stop } }
|
17
|
+
assert_false AE.running?
|
18
|
+
|
19
|
+
assert_true AE.run { AE.next_tick { str << "b" ; AE.stop } }
|
20
|
+
assert_true AE.run { AE.stop }
|
21
|
+
|
22
|
+
AE.run do
|
23
|
+
char = "b"
|
24
|
+
iteration = 0
|
25
|
+
pt1 = AE::PeriodicTimer.new(0.001) do
|
26
|
+
str << char.next!
|
27
|
+
iteration += 1
|
28
|
+
AE.stop if iteration == 4
|
29
|
+
end
|
30
|
+
end
|
31
|
+
assert_false AE.running?
|
32
|
+
|
33
|
+
assert_equal "abcdef", str
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_02_stop_works_as_expected
|
37
|
+
@var = false
|
38
|
+
AE.run do
|
39
|
+
AE.next_tick { @var = true }
|
40
|
+
AE.stop
|
41
|
+
end
|
42
|
+
assert_false AE.running?
|
43
|
+
assert_true @var
|
44
|
+
|
45
|
+
@var = false
|
46
|
+
AE.run do
|
47
|
+
AE.next_tick { AE.next_tick { @var = true } }
|
48
|
+
AE.stop
|
49
|
+
end
|
50
|
+
assert_false AE.running?
|
51
|
+
assert_false @var
|
52
|
+
|
53
|
+
@var = false
|
54
|
+
AE.run do
|
55
|
+
AE.add_timer(0.1) { @var = true }
|
56
|
+
AE.stop
|
57
|
+
end
|
58
|
+
assert_false @var
|
59
|
+
|
60
|
+
@var = false
|
61
|
+
AE.run do
|
62
|
+
AE.add_timer(0.11) { @var = true }
|
63
|
+
AE.next_tick { AE.stop }
|
64
|
+
end
|
65
|
+
assert_false @var
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_03_run_in_run
|
69
|
+
num = 0
|
70
|
+
|
71
|
+
AE.run do
|
72
|
+
num+=1
|
73
|
+
AE.run { num+=1 }
|
74
|
+
AE.run { AE.run { num+=1 } } # Wont' occur.
|
75
|
+
AE.next_tick { num+=1 }
|
76
|
+
AE.next_tick { AE.next_tick { num+=1 } } # Won't occur.
|
77
|
+
AE.stop
|
78
|
+
end
|
79
|
+
assert_equal 3, num
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_04_multiple_stop
|
83
|
+
AE.run do
|
84
|
+
AE.next_tick { AE.next_tick { AE.stop } }
|
85
|
+
AE.next_tick { AE.stop ; AE.stop }
|
86
|
+
AE.add_timer(0) { AE.stop }
|
87
|
+
end
|
88
|
+
assert_false AE.running?
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_05_stop_from_different_thread
|
92
|
+
@var = false
|
93
|
+
Thread.new { sleep 0.05 ; AE.stop }
|
94
|
+
AE.run do
|
95
|
+
AE.add_timer(1) { @var = true } # Won't occur.
|
96
|
+
end
|
97
|
+
assert_false @var
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_06_signal_kills_asyncengine
|
101
|
+
@var = false
|
102
|
+
|
103
|
+
assert_raise SignalException do
|
104
|
+
AE.run do
|
105
|
+
AE.add_timer(0) { Process.kill :USR1, $$ }
|
106
|
+
AE.add_timer(1) { @var = true } # Won't occur.
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
assert_true AE.run { AE.stop }
|
111
|
+
assert_false @var
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_07_on_exit
|
115
|
+
num = 0
|
116
|
+
|
117
|
+
AE.on_exit { num += 1 }
|
118
|
+
AE.on_exit { num += 1 }
|
119
|
+
AE.run do
|
120
|
+
AE.on_exit { num += 1 }
|
121
|
+
AE.next_tick { AE.on_exit { num += 1 } ; AE.stop }
|
122
|
+
AE.on_exit { num += 1 }
|
123
|
+
end
|
124
|
+
|
125
|
+
assert_equal 5, num
|
126
|
+
|
127
|
+
num = 0
|
128
|
+
|
129
|
+
AE.on_exit { num += 1 }
|
130
|
+
AE.run do
|
131
|
+
AE.unset_on_exit
|
132
|
+
AE.stop
|
133
|
+
end
|
134
|
+
|
135
|
+
assert_equal 0, num
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_08_on_exit_with_error
|
139
|
+
num = 0
|
140
|
+
|
141
|
+
AE.on_exit {|error| num += 1 }
|
142
|
+
AE.on_exit {|error| num += 1 ; raise RuntimeError, "runtime error" }
|
143
|
+
AE.on_exit {|error| num += 1 } # This won't occur.
|
144
|
+
|
145
|
+
begin
|
146
|
+
AE.run do
|
147
|
+
pumpppp # This will produce NameError.
|
148
|
+
end
|
149
|
+
# But the last exception took place when executing @_on_exit_procs: RuntimeError.
|
150
|
+
rescue => e
|
151
|
+
assert_equal RuntimeError, e.class
|
152
|
+
end
|
153
|
+
|
154
|
+
assert_equal 2, num
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_09_run_in_on_error
|
158
|
+
num = 0
|
159
|
+
|
160
|
+
AE.on_exit do
|
161
|
+
AE.run { num += 1 ; AE.stop }
|
162
|
+
end
|
163
|
+
|
164
|
+
AE.run { num += 1 ; AE.stop }
|
165
|
+
|
166
|
+
assert_equal 2, num
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "ae_test_helper"
|
2
|
+
|
3
|
+
|
4
|
+
class TestCallFromOtherThread < AETest
|
5
|
+
|
6
|
+
def test_01_call_from_other_thread_run_in_order_when_in_same_thread
|
7
|
+
str = ""
|
8
|
+
|
9
|
+
AE.run do
|
10
|
+
AE.call_from_other_thread { str << "1" }
|
11
|
+
AE.call_from_other_thread { str << "2" }
|
12
|
+
AE.call_from_other_thread { str << "3" ; AE.call_from_other_thread { str << "6" } ; AE.call_from_other_thread { str << "7" } }
|
13
|
+
AE.call_from_other_thread { AE.call_from_other_thread { str << "8" ; AE.call_from_other_thread { str << "B" } } }
|
14
|
+
AE.call_from_other_thread { AE.call_from_other_thread { str << "9" ; AE.call_from_other_thread { str << "C" } ; AE.call_from_other_thread { str << "D" ; AE.stop } } }
|
15
|
+
AE.call_from_other_thread { str << "4" }
|
16
|
+
AE.call_from_other_thread { str << "5" ; AE.call_from_other_thread { str << "A" } }
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_equal "123456789ABCD", str
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_02_call_from_other_thread_and_timer
|
23
|
+
str = ""
|
24
|
+
|
25
|
+
AE.run do
|
26
|
+
AE.call_from_other_thread { str << "1" }
|
27
|
+
AE.add_timer(0.01) { AE.call_from_other_thread { str << "3" } }
|
28
|
+
AE.add_timer(0.02) { AE.call_from_other_thread { str << "4" ; AE.call_from_other_thread { str << "6" ; AE.stop } } ; AE.call_from_other_thread { str << "5" } }
|
29
|
+
AE.call_from_other_thread { str << "2" }
|
30
|
+
end
|
31
|
+
|
32
|
+
assert_equal "123456", str
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_03_multiple_stop_in_cascade_from_different_thread
|
36
|
+
@var = false
|
37
|
+
|
38
|
+
AE.run do
|
39
|
+
AE.add_timer(1) { @var = true } # Won't occur.
|
40
|
+
Thread.new do
|
41
|
+
AE.call_from_other_thread do
|
42
|
+
AE.call_from_other_thread do
|
43
|
+
AE.call_from_other_thread do
|
44
|
+
AE.stop
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
assert_false @var
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
data/test/test_error.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require "ae_test_helper"
|
2
|
+
|
3
|
+
|
4
|
+
class TestError < AETest
|
5
|
+
|
6
|
+
def test_01_exception_raised
|
7
|
+
assert_raise NameError do
|
8
|
+
AE.run { ouch1a }
|
9
|
+
end
|
10
|
+
assert_false AE.running?
|
11
|
+
|
12
|
+
assert_raise NameError do
|
13
|
+
AE.run { AE.next_tick { ouch1b } }
|
14
|
+
end
|
15
|
+
assert_false AE.running?
|
16
|
+
|
17
|
+
assert_raise NameError do
|
18
|
+
AE.run { AE.add_timer(0) { ouch1c } }
|
19
|
+
end
|
20
|
+
assert_false AE.running?
|
21
|
+
|
22
|
+
assert_raise NameError do
|
23
|
+
AE.run do
|
24
|
+
AE.add_timer(0) do
|
25
|
+
AE.next_tick do
|
26
|
+
AE.add_timer(0) { ouch1d }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
assert_false AE.running?
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_02_error_handler
|
35
|
+
AE.on_error {|e| assert e.is_a? ::StandardError }
|
36
|
+
assert_respond_to AE.instance_variable_get(:@_user_error_handler), :call
|
37
|
+
|
38
|
+
assert_nothing_raised do
|
39
|
+
AE.run do
|
40
|
+
AE.next_tick { qweqwe }
|
41
|
+
AE.add_timer(0) { uhhhh2 }
|
42
|
+
AE.add_timer(0.01) { AE.stop }
|
43
|
+
lalalalala
|
44
|
+
end
|
45
|
+
end
|
46
|
+
assert_false AE.running?
|
47
|
+
|
48
|
+
# Dissable the error handler again.
|
49
|
+
AE.unset_on_error
|
50
|
+
assert_equal nil, AE.instance_variable_get(:@_user_error_manager)
|
51
|
+
|
52
|
+
assert_raise NameError do
|
53
|
+
AE.run { AE.add_timer(0) { opppps } }
|
54
|
+
end
|
55
|
+
assert_false AE.running?
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_03_exception_in_error_handler
|
59
|
+
AE.on_error {|e| 1/0 }
|
60
|
+
|
61
|
+
assert_raise ZeroDivisionError do
|
62
|
+
AE.run { AE.next_tick { ouch3 } }
|
63
|
+
end
|
64
|
+
assert_false AE.running?
|
65
|
+
|
66
|
+
assert_raise ZeroDivisionError do
|
67
|
+
AE.run { AE::Timer.new(0) { 1/0 } }
|
68
|
+
end
|
69
|
+
assert_false AE.running?
|
70
|
+
|
71
|
+
AE.unset_on_error
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_04_error_handler_in_next_tick_allows_executes_all_next_ticks
|
75
|
+
AE.on_error {|e| assert e.is_a? ::StandardError }
|
76
|
+
|
77
|
+
num = 0
|
78
|
+
AE.run do
|
79
|
+
AE.next_tick { num+=1 }
|
80
|
+
AE.next_tick { num+=1 }
|
81
|
+
AE.next_tick { bumpppp }
|
82
|
+
AE.next_tick { num+=1 }
|
83
|
+
AE.next_tick { num+=1 }
|
84
|
+
AE.next_tick { AE.stop }
|
85
|
+
end
|
86
|
+
|
87
|
+
AE.unset_on_error
|
88
|
+
|
89
|
+
assert_equal 4, num
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "ae_test_helper"
|
2
|
+
|
3
|
+
|
4
|
+
class TestIpUtils < AETest
|
5
|
+
|
6
|
+
def test_01_ip_type
|
7
|
+
assert_equal :ipv4, AE::IpUtils.ip_type("1.2.3.4")
|
8
|
+
assert_false AE::IpUtils.ip_type("1.2.3.04")
|
9
|
+
assert_false AE::IpUtils.ip_type("1.2.3.004")
|
10
|
+
assert_false AE::IpUtils.ip_type("1.2.3.0004")
|
11
|
+
|
12
|
+
assert_equal :ipv6, AE::IpUtils.ip_type("1080::8:800:200C:417A")
|
13
|
+
assert_equal :ipv6, AE::IpUtils.ip_type("1080:0:0:0:8:800:200C:417A")
|
14
|
+
assert_equal :ipv6, AE::IpUtils.ip_type("1080:0000:0000:0000:0008:0800:200C:417A")
|
15
|
+
assert_false AE::IpUtils.ip_type("1::8::1")
|
16
|
+
|
17
|
+
assert_equal :ipv6_reference, AE::IpUtils.ip_type("[1080::8:800:200C:417A]")
|
18
|
+
assert_equal :ipv6_reference, AE::IpUtils.ip_type("[1080:0:0:0:8:800:200C:417A]")
|
19
|
+
assert_equal :ipv6_reference, AE::IpUtils.ip_type("[1080:0000:0000:0000:0008:0800:200C:417A]")
|
20
|
+
assert_false AE::IpUtils.ip_type("[1::8::1]")
|
21
|
+
|
22
|
+
assert_false AE::IpUtils.ip_type("domain.net")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_02_compare_ips
|
26
|
+
assert_true AE::IpUtils.compare_ips("255.255.255.255", "255.255.255.255")
|
27
|
+
assert_false AE::IpUtils.compare_ips("1.2.3.4", "9.9.9.9")
|
28
|
+
assert_nil AE::IpUtils.compare_ips("1.2.3.4", "1.2.3.04")
|
29
|
+
|
30
|
+
assert_true AE::IpUtils.compare_ips("1080::8:800:200C:417A", "1080:0:0:0:8:800:200C:417A")
|
31
|
+
assert_true AE::IpUtils.compare_ips("1080::8:800:200C:417A", "1080:0000:0000:0000:0008:0800:200c:417a")
|
32
|
+
assert_true AE::IpUtils.compare_ips("::", "00::00:0")
|
33
|
+
assert_false AE::IpUtils.compare_ips("1080::8:800:200C:417A", "1::2")
|
34
|
+
|
35
|
+
assert_true AE::IpUtils.compare_ips("[1080::8:800:200C:417A]", "[1080:0:0:0:8:800:200C:417A]")
|
36
|
+
assert_true AE::IpUtils.compare_ips("[1080::8:800:200C:417A]", "[1080:0:0:0:8:800:200C:417A]")
|
37
|
+
|
38
|
+
assert_true AE::IpUtils.compare_ips("1080::8:800:200C:417A", "[1080:0:0:0:8:800:200C:417A]", true)
|
39
|
+
assert_true AE::IpUtils.compare_ips("[1080:0:0:0:8:800:200C:417A]", "1080::8:800:200C:417A", true)
|
40
|
+
|
41
|
+
assert_nil AE::IpUtils.compare_ips("1", "::")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "ae_test_helper"
|
2
|
+
|
3
|
+
|
4
|
+
class TestNextTick < AETest
|
5
|
+
|
6
|
+
def test_01_next_tick_run_in_order
|
7
|
+
str = ""
|
8
|
+
|
9
|
+
AE.run do
|
10
|
+
AE.next_tick { str << "1" }
|
11
|
+
AE.next_tick { str << "2" }
|
12
|
+
AE.next_tick { str << "3" ; AE.next_tick { str << "6" } ; AE.next_tick { str << "7" } }
|
13
|
+
AE.next_tick { AE.next_tick { str << "8" ; AE.next_tick { str << "B" } } }
|
14
|
+
AE.next_tick { AE.next_tick { str << "9" ; AE.next_tick { str << "C" } ; AE.next_tick { str << "D" ; AE.stop } } }
|
15
|
+
AE.next_tick { str << "4" }
|
16
|
+
AE.next_tick { str << "5" ; AE.next_tick { str << "A" } }
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_equal "123456789ABCD", str
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_02_next_tick_and_timer
|
23
|
+
str = ""
|
24
|
+
|
25
|
+
AE.run do
|
26
|
+
AE.next_tick { str << "1" }
|
27
|
+
AE.add_timer(0.001) { AE.next_tick { str << "3" } }
|
28
|
+
AE.add_timer(0.002) { AE.next_tick { str << "4" ; AE.next_tick { str << "6" ; AE.stop } } ; AE.next_tick { str << "5" } }
|
29
|
+
AE.next_tick { str << "2" }
|
30
|
+
end
|
31
|
+
|
32
|
+
assert_equal "123456", str
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|