mt-libuv 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.gitmodules +6 -0
- data/.rspec +1 -0
- data/.travis.yml +24 -0
- data/Gemfile +9 -0
- data/LICENSE +24 -0
- data/README.md +195 -0
- data/Rakefile +31 -0
- data/ext/README.md +6 -0
- data/ext/Rakefile +28 -0
- data/lib/mt-libuv/async.rb +51 -0
- data/lib/mt-libuv/check.rb +59 -0
- data/lib/mt-libuv/coroutines.rb +79 -0
- data/lib/mt-libuv/dns.rb +98 -0
- data/lib/mt-libuv/error.rb +88 -0
- data/lib/mt-libuv/ext/ext.rb +322 -0
- data/lib/mt-libuv/ext/platform/darwin_x64.rb +61 -0
- data/lib/mt-libuv/ext/platform/unix.rb +69 -0
- data/lib/mt-libuv/ext/platform/windows.rb +83 -0
- data/lib/mt-libuv/ext/tasks/mac.rb +24 -0
- data/lib/mt-libuv/ext/tasks/unix.rb +42 -0
- data/lib/mt-libuv/ext/tasks/win.rb +29 -0
- data/lib/mt-libuv/ext/tasks.rb +27 -0
- data/lib/mt-libuv/ext/types.rb +253 -0
- data/lib/mt-libuv/fiber_pool.rb +83 -0
- data/lib/mt-libuv/file.rb +309 -0
- data/lib/mt-libuv/filesystem.rb +263 -0
- data/lib/mt-libuv/fs_event.rb +37 -0
- data/lib/mt-libuv/handle.rb +108 -0
- data/lib/mt-libuv/idle.rb +59 -0
- data/lib/mt-libuv/mixins/accessors.rb +41 -0
- data/lib/mt-libuv/mixins/assertions.rb +25 -0
- data/lib/mt-libuv/mixins/fs_checks.rb +96 -0
- data/lib/mt-libuv/mixins/listener.rb +69 -0
- data/lib/mt-libuv/mixins/net.rb +42 -0
- data/lib/mt-libuv/mixins/resource.rb +30 -0
- data/lib/mt-libuv/mixins/stream.rb +276 -0
- data/lib/mt-libuv/pipe.rb +217 -0
- data/lib/mt-libuv/prepare.rb +59 -0
- data/lib/mt-libuv/q.rb +475 -0
- data/lib/mt-libuv/reactor.rb +567 -0
- data/lib/mt-libuv/signal.rb +62 -0
- data/lib/mt-libuv/spawn.rb +113 -0
- data/lib/mt-libuv/tcp.rb +465 -0
- data/lib/mt-libuv/timer.rb +107 -0
- data/lib/mt-libuv/tty.rb +42 -0
- data/lib/mt-libuv/udp.rb +302 -0
- data/lib/mt-libuv/version.rb +5 -0
- data/lib/mt-libuv/work.rb +86 -0
- data/lib/mt-libuv.rb +80 -0
- data/mt-libuv.gemspec +62 -0
- data/spec/async_spec.rb +67 -0
- data/spec/coroutines_spec.rb +121 -0
- data/spec/cpu_spec.rb +10 -0
- data/spec/defer_spec.rb +906 -0
- data/spec/dns_spec.rb +110 -0
- data/spec/dsl_spec.rb +43 -0
- data/spec/filesystem_spec.rb +270 -0
- data/spec/idle_spec.rb +44 -0
- data/spec/pipe_spec.rb +151 -0
- data/spec/spawn_spec.rb +119 -0
- data/spec/tcp_spec.rb +272 -0
- data/spec/test.sh +4 -0
- data/spec/test_fail.sh +3 -0
- data/spec/test_read.sh +3 -0
- data/spec/timer_spec.rb +14 -0
- data/spec/udp_spec.rb +73 -0
- data/spec/zen_spec.rb +34 -0
- metadata +196 -0
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'mt-libuv'
|
2
|
+
|
3
|
+
# No support for Fibers in jRuby
|
4
|
+
if RUBY_PLATFORM != 'java'
|
5
|
+
require 'mt-libuv/coroutines' # adds support for coroutines
|
6
|
+
|
7
|
+
|
8
|
+
describe Object do
|
9
|
+
before :each do
|
10
|
+
@log = []
|
11
|
+
@general_failure = []
|
12
|
+
|
13
|
+
@reactor = MTLibuv::Reactor.default
|
14
|
+
@reactor.notifier do |error, context|
|
15
|
+
begin
|
16
|
+
@general_failure << "Log called: #{context}\n#{error.message}\n#{error.backtrace.join("\n") if error.backtrace}\n"
|
17
|
+
rescue Exception => e
|
18
|
+
@general_failure << "error in logger #{e.inspect}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
@timeout = @reactor.timer do
|
23
|
+
@timeout.close
|
24
|
+
@reactor.stop
|
25
|
+
@general_failure << "test timed out"
|
26
|
+
end
|
27
|
+
@timeout.start(5000)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'serial execution' do
|
31
|
+
it "should wait for work to complete and return the result" do
|
32
|
+
@reactor.run { |reactor|
|
33
|
+
|
34
|
+
@log << @reactor.work {
|
35
|
+
sleep 1
|
36
|
+
'work done'
|
37
|
+
}.value
|
38
|
+
@log << 'after work'
|
39
|
+
|
40
|
+
@timeout.close
|
41
|
+
}
|
42
|
+
|
43
|
+
expect(@general_failure).to eq([])
|
44
|
+
expect(@log).to eq(['work done', 'after work'])
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should raise an error if the promise is rejected" do
|
48
|
+
@reactor.run { |reactor|
|
49
|
+
begin
|
50
|
+
@log << @reactor.work {
|
51
|
+
raise 'rejected'
|
52
|
+
}.value
|
53
|
+
@log << 'after work'
|
54
|
+
rescue => e
|
55
|
+
@log << e.message
|
56
|
+
end
|
57
|
+
|
58
|
+
@timeout.close
|
59
|
+
}
|
60
|
+
|
61
|
+
expect(@general_failure).to eq([])
|
62
|
+
expect(@log).to eq(['rejected'])
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return the results of multiple promises" do
|
66
|
+
@reactor.run { |reactor|
|
67
|
+
job1 = @reactor.work {
|
68
|
+
sleep 1
|
69
|
+
'job1'
|
70
|
+
}
|
71
|
+
|
72
|
+
job2 = @reactor.work {
|
73
|
+
sleep 1
|
74
|
+
'job2'
|
75
|
+
}
|
76
|
+
|
77
|
+
# Job1 and Job2 are executed in parallel
|
78
|
+
result1, result2 = ::MTLibuv.co(job1, job2)
|
79
|
+
|
80
|
+
@log << result1
|
81
|
+
@log << result2
|
82
|
+
@log << 'after work'
|
83
|
+
|
84
|
+
@timeout.close
|
85
|
+
}
|
86
|
+
|
87
|
+
expect(@general_failure).to eq([])
|
88
|
+
expect(@log).to eq(['job1', 'job2', 'after work'])
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should provide a callback option for progress events" do
|
92
|
+
@reactor.run { |reactor|
|
93
|
+
timer = @reactor.timer
|
94
|
+
timer.start(0)
|
95
|
+
::MTLibuv.co(timer) do
|
96
|
+
@log << 'in timer'
|
97
|
+
timer.close # close will resolve the promise
|
98
|
+
end
|
99
|
+
|
100
|
+
@log << 'after timer'
|
101
|
+
@timeout.close
|
102
|
+
}
|
103
|
+
|
104
|
+
expect(@log).to eq(['in timer', 'after timer'])
|
105
|
+
expect(@general_failure).to eq([])
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should provide a sleep function that doesn't block the reactor" do
|
109
|
+
@reactor.run { |reactor|
|
110
|
+
@log << 'before sleep'
|
111
|
+
reactor.sleep 200
|
112
|
+
@log << 'after sleep'
|
113
|
+
@timeout.close
|
114
|
+
}
|
115
|
+
|
116
|
+
expect(@log).to eq(['before sleep', 'after sleep'])
|
117
|
+
expect(@general_failure).to eq([])
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|