polyphony 0.64 → 0.68

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +1 -1
  3. data/CHANGELOG.md +22 -0
  4. data/Gemfile.lock +1 -1
  5. data/TODO.md +10 -40
  6. data/bin/pdbg +112 -0
  7. data/examples/core/await.rb +9 -1
  8. data/ext/polyphony/backend_common.c +14 -1
  9. data/ext/polyphony/backend_common.h +3 -1
  10. data/ext/polyphony/backend_io_uring.c +85 -25
  11. data/ext/polyphony/backend_io_uring_context.c +42 -0
  12. data/ext/polyphony/backend_io_uring_context.h +6 -9
  13. data/ext/polyphony/backend_libev.c +85 -39
  14. data/ext/polyphony/fiber.c +20 -0
  15. data/ext/polyphony/polyphony.c +2 -0
  16. data/ext/polyphony/polyphony.h +5 -2
  17. data/ext/polyphony/queue.c +1 -1
  18. data/ext/polyphony/runqueue.c +7 -3
  19. data/ext/polyphony/runqueue.h +4 -3
  20. data/ext/polyphony/runqueue_ring_buffer.c +25 -14
  21. data/ext/polyphony/runqueue_ring_buffer.h +2 -0
  22. data/ext/polyphony/thread.c +2 -8
  23. data/lib/polyphony.rb +6 -0
  24. data/lib/polyphony/debugger.rb +225 -0
  25. data/lib/polyphony/extensions/debug.rb +1 -1
  26. data/lib/polyphony/extensions/fiber.rb +64 -71
  27. data/lib/polyphony/extensions/io.rb +4 -2
  28. data/lib/polyphony/extensions/openssl.rb +66 -0
  29. data/lib/polyphony/extensions/socket.rb +8 -2
  30. data/lib/polyphony/net.rb +1 -0
  31. data/lib/polyphony/version.rb +1 -1
  32. data/test/helper.rb +6 -5
  33. data/test/stress.rb +6 -2
  34. data/test/test_backend.rb +13 -4
  35. data/test/test_fiber.rb +35 -11
  36. data/test/test_global_api.rb +9 -4
  37. data/test/test_io.rb +2 -0
  38. data/test/test_socket.rb +14 -11
  39. data/test/test_supervise.rb +24 -24
  40. data/test/test_thread.rb +3 -0
  41. data/test/test_thread_pool.rb +1 -1
  42. data/test/test_throttler.rb +2 -2
  43. data/test/test_timer.rb +5 -3
  44. metadata +5 -3
data/test/test_socket.rb CHANGED
@@ -158,19 +158,22 @@ class SocketTest < MiniTest::Test
158
158
  end
159
159
  end
160
160
 
161
- class HTTPClientTest < MiniTest::Test
162
- require 'json'
161
+ if IS_LINUX
162
+ class HTTPClientTest < MiniTest::Test
163
163
 
164
- def test_http
165
- res = HTTParty.get('http://ipinfo.io/')
164
+ require 'json'
166
165
 
167
- response = JSON.load(res.body)
168
- assert_equal 'https://ipinfo.io/missingauth', response['readme']
169
- end
166
+ def test_http
167
+ res = HTTParty.get('http://ipinfo.io/')
168
+
169
+ response = JSON.load(res.body)
170
+ assert_equal 'https://ipinfo.io/missingauth', response['readme']
171
+ end
170
172
 
171
- def test_https
172
- res = HTTParty.get('https://ipinfo.io/')
173
- response = JSON.load(res.body)
174
- assert_equal 'https://ipinfo.io/missingauth', response['readme']
173
+ def test_https
174
+ res = HTTParty.get('https://ipinfo.io/')
175
+ response = JSON.load(res.body)
176
+ assert_equal 'https://ipinfo.io/missingauth', response['readme']
177
+ end
175
178
  end
176
179
  end
@@ -2,29 +2,29 @@
2
2
 
3
3
  require_relative 'helper'
4
4
 
5
- # class SuperviseTest < MiniTest::Test
6
- # def test_supervise
7
- # p = spin { supervise }
8
- # snooze
9
- # f1 = p.spin { receive }
10
- # f2 = p.spin { receive }
11
-
12
- # snooze
13
- # assert_equal p.state, :waiting
14
- # f1 << 'foo'
15
- # f1.await
16
- # snooze
17
-
18
- # assert_equal :waiting, p.state
19
- # assert_equal :waiting, f2.state
20
-
21
- # f2 << 'bar'
22
- # f2.await
23
- # assert_equal :runnable, p.state
24
-
25
- # 3.times { snooze }
26
- # assert_equal :dead, p.state
27
- # end
5
+ class SuperviseTest < MiniTest::Test
6
+ def test_supervise_with_no_arguments
7
+ assert_raises(RuntimeError) do
8
+ supervise
9
+ end
10
+ end
11
+
12
+ def test_supervise_with_block
13
+ buffer = []
14
+ f1 = spin(:f1) { receive }
15
+ f2 = spin(:f2) { receive }
16
+ supervisor = spin(:supervisor) { supervise(f1, f2) { |*args| buffer << args } }
17
+
18
+ snooze
19
+ f1 << 'foo'
20
+ f1.await
21
+ 10.times { snooze }
22
+ assert_equal [[f1, 'foo']], buffer
23
+
24
+ f2 << 'bar'
25
+ f2.await
26
+ assert_equal [[f1, 'foo'], [f2, 'bar']], buffer
27
+ end
28
28
 
29
29
  # def test_supervise_with_restart
30
30
  # watcher = spin { receive }
@@ -101,4 +101,4 @@ require_relative 'helper'
101
101
  # assert :dead, f.state
102
102
  # assert :dead, p.state
103
103
  # end
104
- # end
104
+ end
data/test/test_thread.rb CHANGED
@@ -180,6 +180,9 @@ class ThreadTest < MiniTest::Test
180
180
  assert_equal count, GC.count
181
181
  sleep 0.05
182
182
  assert_equal count, GC.count
183
+
184
+ return unless IS_LINUX
185
+
183
186
  # The idle tasks are ran at most once per fiber switch, before the backend
184
187
  # is polled. Therefore, the second sleep will not have triggered a GC, since
185
188
  # only 0.05s have passed since the gc period was set.
@@ -70,7 +70,7 @@ class ThreadPoolTest < MiniTest::Test
70
70
 
71
71
  sleep 0.15 # allow time for threads to spawn
72
72
  assert_equal @pool.size, threads.uniq.size
73
- assert_equal (0..9).to_a, buffer.sort
73
+ assert_equal (0..9).to_a, buffer.sort if IS_LINUX
74
74
  end
75
75
 
76
76
  def test_busy?
@@ -10,7 +10,7 @@ class ThrottlerTest < MiniTest::Test
10
10
  f = spin { loop { t.process { buffer << 1 } } }
11
11
  sleep 0.2
12
12
  f.stop
13
- assert_in_range 1..3, buffer.size
13
+ assert_in_range 1..4, buffer.size
14
14
  ensure
15
15
  t.stop
16
16
  end
@@ -23,7 +23,7 @@ class ThrottlerTest < MiniTest::Test
23
23
  end
24
24
  sleep 0.25
25
25
  f.stop
26
- assert_in_range 2..6, buffer.size
26
+ assert_in_range 2..7, buffer.size
27
27
  ensure
28
28
  t.stop
29
29
  end
data/test/test_timer.rb CHANGED
@@ -19,7 +19,7 @@ class TimerMoveOnAfterTest < MiniTest::Test
19
19
  end
20
20
  t1 = Time.now
21
21
 
22
- assert_in_range 0.1..0.15, t1 - t0
22
+ assert_in_range 0.1..0.15, t1 - t0 if IS_LINUX
23
23
  assert_nil v
24
24
  end
25
25
 
@@ -31,11 +31,13 @@ class TimerMoveOnAfterTest < MiniTest::Test
31
31
  end
32
32
  t1 = Time.now
33
33
 
34
- assert_in_range 0.01..0.05, t1 - t0
34
+ assert_in_range 0.01..0.05, t1 - t0 if IS_LINUX
35
35
  assert_equal :bar, v
36
36
  end
37
37
 
38
38
  def test_timer_move_on_after_with_reset
39
+ skip unless IS_LINUX
40
+
39
41
  t0 = Time.now
40
42
  v = @timer.move_on_after(0.01, with_value: :moved_on) do
41
43
  sleep 0.007
@@ -71,7 +73,7 @@ class TimerCancelAfterTest < MiniTest::Test
71
73
  end
72
74
  end
73
75
  t1 = Time.now
74
- assert_in_range 0.01..0.03, t1 - t0
76
+ assert_in_range 0.01..0.03, t1 - t0 if IS_LINUX
75
77
  end
76
78
 
77
79
  def test_timer_cancel_after_with_reset
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyphony
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.64'
4
+ version: '0.68'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-26 00:00:00.000000000 Z
11
+ date: 2021-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -156,6 +156,7 @@ files:
156
156
  - README.md
157
157
  - Rakefile
158
158
  - TODO.md
159
+ - bin/pdbg
159
160
  - bin/polyphony-debug
160
161
  - bin/stress.rb
161
162
  - bin/test
@@ -356,6 +357,7 @@ files:
356
357
  - lib/polyphony/core/thread_pool.rb
357
358
  - lib/polyphony/core/throttler.rb
358
359
  - lib/polyphony/core/timer.rb
360
+ - lib/polyphony/debugger.rb
359
361
  - lib/polyphony/extensions/core.rb
360
362
  - lib/polyphony/extensions/debug.rb
361
363
  - lib/polyphony/extensions/fiber.rb
@@ -419,7 +421,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
419
421
  - !ruby/object:Gem::Version
420
422
  version: '0'
421
423
  requirements: []
422
- rubygems_version: 3.1.6
424
+ rubygems_version: 3.1.4
423
425
  signing_key:
424
426
  specification_version: 4
425
427
  summary: Fine grained concurrency for Ruby