mt-libuv 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.gitmodules +6 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +24 -0
  6. data/Gemfile +9 -0
  7. data/LICENSE +24 -0
  8. data/README.md +195 -0
  9. data/Rakefile +31 -0
  10. data/ext/README.md +6 -0
  11. data/ext/Rakefile +28 -0
  12. data/lib/mt-libuv/async.rb +51 -0
  13. data/lib/mt-libuv/check.rb +59 -0
  14. data/lib/mt-libuv/coroutines.rb +79 -0
  15. data/lib/mt-libuv/dns.rb +98 -0
  16. data/lib/mt-libuv/error.rb +88 -0
  17. data/lib/mt-libuv/ext/ext.rb +322 -0
  18. data/lib/mt-libuv/ext/platform/darwin_x64.rb +61 -0
  19. data/lib/mt-libuv/ext/platform/unix.rb +69 -0
  20. data/lib/mt-libuv/ext/platform/windows.rb +83 -0
  21. data/lib/mt-libuv/ext/tasks/mac.rb +24 -0
  22. data/lib/mt-libuv/ext/tasks/unix.rb +42 -0
  23. data/lib/mt-libuv/ext/tasks/win.rb +29 -0
  24. data/lib/mt-libuv/ext/tasks.rb +27 -0
  25. data/lib/mt-libuv/ext/types.rb +253 -0
  26. data/lib/mt-libuv/fiber_pool.rb +83 -0
  27. data/lib/mt-libuv/file.rb +309 -0
  28. data/lib/mt-libuv/filesystem.rb +263 -0
  29. data/lib/mt-libuv/fs_event.rb +37 -0
  30. data/lib/mt-libuv/handle.rb +108 -0
  31. data/lib/mt-libuv/idle.rb +59 -0
  32. data/lib/mt-libuv/mixins/accessors.rb +41 -0
  33. data/lib/mt-libuv/mixins/assertions.rb +25 -0
  34. data/lib/mt-libuv/mixins/fs_checks.rb +96 -0
  35. data/lib/mt-libuv/mixins/listener.rb +69 -0
  36. data/lib/mt-libuv/mixins/net.rb +42 -0
  37. data/lib/mt-libuv/mixins/resource.rb +30 -0
  38. data/lib/mt-libuv/mixins/stream.rb +276 -0
  39. data/lib/mt-libuv/pipe.rb +217 -0
  40. data/lib/mt-libuv/prepare.rb +59 -0
  41. data/lib/mt-libuv/q.rb +475 -0
  42. data/lib/mt-libuv/reactor.rb +567 -0
  43. data/lib/mt-libuv/signal.rb +62 -0
  44. data/lib/mt-libuv/spawn.rb +113 -0
  45. data/lib/mt-libuv/tcp.rb +465 -0
  46. data/lib/mt-libuv/timer.rb +107 -0
  47. data/lib/mt-libuv/tty.rb +42 -0
  48. data/lib/mt-libuv/udp.rb +302 -0
  49. data/lib/mt-libuv/version.rb +5 -0
  50. data/lib/mt-libuv/work.rb +86 -0
  51. data/lib/mt-libuv.rb +80 -0
  52. data/mt-libuv.gemspec +62 -0
  53. data/spec/async_spec.rb +67 -0
  54. data/spec/coroutines_spec.rb +121 -0
  55. data/spec/cpu_spec.rb +10 -0
  56. data/spec/defer_spec.rb +906 -0
  57. data/spec/dns_spec.rb +110 -0
  58. data/spec/dsl_spec.rb +43 -0
  59. data/spec/filesystem_spec.rb +270 -0
  60. data/spec/idle_spec.rb +44 -0
  61. data/spec/pipe_spec.rb +151 -0
  62. data/spec/spawn_spec.rb +119 -0
  63. data/spec/tcp_spec.rb +272 -0
  64. data/spec/test.sh +4 -0
  65. data/spec/test_fail.sh +3 -0
  66. data/spec/test_read.sh +3 -0
  67. data/spec/timer_spec.rb +14 -0
  68. data/spec/udp_spec.rb +73 -0
  69. data/spec/zen_spec.rb +34 -0
  70. 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
data/spec/cpu_spec.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'mt-libuv'
2
+
3
+
4
+ describe ::MTLibuv do
5
+ it "Should return the number of CPU cores on the platform" do
6
+ count = MTLibuv.cpu_count
7
+
8
+ expect(count != nil && count > 0).to eq(true)
9
+ end
10
+ end