async-container 0.16.3 → 0.16.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7adf1896a47b233182c937ab7b2af7dc5c096580ebba30fad4c6153f1af26c0
4
- data.tar.gz: f84bdd5f8bdc921449c814788a093342e7508cb1b449b42cfc3994069c2d350a
3
+ metadata.gz: a5d86c65b350b653e621c4f36e8005fc85ba7c6a97569784dc2d5170d1310a27
4
+ data.tar.gz: 708b959103791bb424fae6c8f32e8a213dc04986c4e33e498069ebcd08b12473
5
5
  SHA512:
6
- metadata.gz: 2fd17ac64451b53a6ce97c057c2cc150b2e17a7540252770fa2e0ab9a3652ed27acbe1250a218e9ec6f14ef95471d0004855870572da666f77d1b9d7776b15e8
7
- data.tar.gz: a9503f7eb323e982812103fb313e1dff3edbc558479240a97b451f3458b34e9f85415a2e1db505573cfa6f4241a354fcfd5f8d767dab14af15f1602a77de48a0
6
+ metadata.gz: 5b216348b1514841d813e1455565b41e108a9c284e2b26e2629d8a8cf26acf7c5952bc0e63a2a84ab2c144b6a4c462cbdb1e1b54255ed1ecdbc4107a92d0e66b
7
+ data.tar.gz: f0afa2fcb3cd7ee73dd67cc92d0b004bc7b467cef2b7f4753ddbd296316d6364e81f7edd22987887957e14fe5bb0971370263e84731b7ebb181a109e635ea5e1
@@ -81,13 +81,12 @@ module Async
81
81
  end
82
82
 
83
83
  def stop(timeout = 1)
84
- # Handle legacy `graceful = true` argument:
84
+ # Use a default timeout if not specified:
85
+ timeout = 1 if timeout == true
86
+
85
87
  if timeout
86
88
  start_time = Async::Clock.now
87
89
 
88
- # Use a default timeout if not specified:
89
- timeout = 1 if timeout == true
90
-
91
90
  self.interrupt
92
91
 
93
92
  while self.any?
@@ -103,14 +102,6 @@ module Async
103
102
  end
104
103
  end
105
104
 
106
- # Timeout can also be `graceful = false`:
107
- if timeout
108
- self.interrupt
109
- self.sleep(timeout)
110
- end
111
-
112
- self.wait_for_children(duration)
113
-
114
105
  # Terminate all children:
115
106
  self.terminate
116
107
 
@@ -38,7 +38,7 @@ module Async
38
38
  end
39
39
 
40
40
  def send(level: :debug, **message)
41
- @logger.send(level, self) {message[:status]}
41
+ @logger.send(level, self) {message}
42
42
  end
43
43
 
44
44
  def ready!(**message)
@@ -98,7 +98,7 @@ module Async
98
98
 
99
99
  def receive
100
100
  while true
101
- data, address, flags, *controls = @bound.recvmsg(MAXIMUM_MESSAGE_SIZE)
101
+ data, _address, _flags, *_controls = @bound.recvmsg(MAXIMUM_MESSAGE_SIZE)
102
102
 
103
103
  message = Server.load(data)
104
104
 
@@ -116,7 +116,7 @@ module Async
116
116
  end
117
117
 
118
118
  def name= value
119
- @thread.name = name
119
+ @thread.name = value
120
120
  end
121
121
 
122
122
  def name
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Async
24
24
  module Container
25
- VERSION = "0.16.3"
25
+ VERSION = "0.16.4"
26
26
  end
27
27
  end
@@ -33,18 +33,18 @@ RSpec.describe Async::Container::Controller do
33
33
  container.spawn(key: "test") do |instance|
34
34
  instance.ready!
35
35
 
36
- sleep(0.2)
36
+ sleep(0.2 * QUANTUM)
37
37
 
38
38
  @output.write(".")
39
39
  @output.flush
40
40
 
41
- sleep(0.4)
41
+ sleep(0.4 * QUANTUM)
42
42
  end
43
43
 
44
44
  container.spawn do |instance|
45
45
  instance.ready!
46
46
 
47
- sleep(0.3)
47
+ sleep(0.3 * QUANTUM)
48
48
 
49
49
  @output.write(",")
50
50
  @output.flush
@@ -101,6 +101,5 @@ RSpec.describe Async::Container::Controller do
101
101
  subject.run
102
102
  end.to raise_exception(Async::Container::InitializationError)
103
103
  end
104
-
105
104
  end
106
105
  end
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../../../lib/async/container/controller'
5
+ require_relative '../../../lib/async/container/forked'
6
+
7
+ Console.logger.debug!
8
+
9
+ class Dots < Async::Container::Controller
10
+ def setup(container)
11
+ container.run(name: "dots", count: 1, restart: true) do |instance|
12
+ instance.ready!
13
+
14
+ sleep 1
15
+
16
+ $stdout.write "."
17
+ $stdout.flush
18
+
19
+ sleep
20
+ rescue Async::Container::Interrupt
21
+ $stdout.write("I")
22
+ rescue Async::Container::Terminate
23
+ $stdout.write("T")
24
+ end
25
+ end
26
+ end
27
+
28
+ controller = Dots.new
29
+
30
+ begin
31
+ controller.run
32
+ ensure
33
+ $stderr.puts $!
34
+ end
@@ -45,7 +45,7 @@ RSpec.describe Async::Container::Forked, if: Async::Container.fork? do
45
45
 
46
46
  3.times do
47
47
  trigger.last.puts "die"
48
- child_pid = pids.first.gets
48
+ _child_pid = pids.first.gets
49
49
  end
50
50
 
51
51
  thread.kill
@@ -38,7 +38,7 @@ RSpec.describe Async::Container::Notify::Pipe do
38
38
  # Wait for the state to be updated by the child process:
39
39
  container.sleep
40
40
 
41
- child, state = container.state.first
41
+ _child, state = container.state.first
42
42
  expect(state).to be == {status: "Initializing..."}
43
43
 
44
44
  container.wait
@@ -51,11 +51,11 @@ RSpec.shared_examples_for Async::Container do
51
51
  describe '#sleep' do
52
52
  it "can sleep for a short time" do
53
53
  subject.spawn do
54
- sleep(0.2)
54
+ sleep(0.2 * QUANTUM)
55
55
  raise "Boom"
56
56
  end
57
57
 
58
- subject.sleep(0.1)
58
+ subject.sleep(0.1 * QUANTUM)
59
59
  expect(subject.statistics).to have_attributes(failures: 0)
60
60
 
61
61
  subject.wait
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require "async/container/controller"
24
+
25
+ RSpec.describe Async::Container::Controller do
26
+ let(:controller_path) {File.expand_path("dots.rb", __dir__)}
27
+
28
+ let(:pipe) {IO.pipe}
29
+ let(:input) {pipe.first}
30
+ let(:output) {pipe.last}
31
+
32
+ let(:pid) {Process.spawn(controller_path, out: output)}
33
+
34
+ before do
35
+ pid
36
+ output.close
37
+ end
38
+
39
+ after do
40
+ Process.kill(:KILL, pid)
41
+ end
42
+
43
+ it "restarts children when receiving SIGHUP" do
44
+ expect(input.read(1)).to be == '.'
45
+
46
+ Process.kill(:HUP, pid)
47
+
48
+ expect(input.read(2)).to be == 'I.'
49
+ end
50
+
51
+ it "exits gracefully when receiving SIGINT" do
52
+ expect(input.read(1)).to be == '.'
53
+
54
+ Process.kill(:INT, pid)
55
+
56
+ expect(input.read).to be == 'I'
57
+ end
58
+
59
+ it "exits gracefully when receiving SIGTERM" do
60
+ expect(input.read(1)).to be == '.'
61
+
62
+ Process.kill(:TERM, pid)
63
+
64
+ expect(input.read).to be == 'T'
65
+ end
66
+ end
@@ -5,10 +5,16 @@ require 'covered/rspec'
5
5
  # Shared rspec helpers:
6
6
  require "async/rspec"
7
7
 
8
+ if RUBY_PLATFORM =~ /darwin/i
9
+ QUANTUM = 2.0
10
+ else
11
+ QUANTUM = 1.0
12
+ end
13
+
8
14
  RSpec.configure do |config|
9
15
  # Enable flags like --only-failures and --next-failure
10
16
  config.example_status_persistence_file_path = ".rspec_status"
11
-
17
+
12
18
  config.expect_with :rspec do |c|
13
19
  c.syntax = :expect
14
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-container
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.3
4
+ version: 0.16.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-18 00:00:00.000000000 Z
11
+ date: 2020-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: process-group
@@ -173,12 +173,14 @@ files:
173
173
  - lib/async/container/threaded.rb
174
174
  - lib/async/container/version.rb
175
175
  - spec/async/container/controller_spec.rb
176
+ - spec/async/container/dots.rb
176
177
  - spec/async/container/forked_spec.rb
177
178
  - spec/async/container/hybrid_spec.rb
178
179
  - spec/async/container/notify/notify.rb
179
180
  - spec/async/container/notify/pipe_spec.rb
180
181
  - spec/async/container/notify_spec.rb
181
182
  - spec/async/container/shared_examples.rb
183
+ - spec/async/container/signal_spec.rb
182
184
  - spec/async/container/threaded_spec.rb
183
185
  - spec/async/container_spec.rb
184
186
  - spec/spec_helper.rb
@@ -207,12 +209,14 @@ specification_version: 4
207
209
  summary: Async is an asynchronous I/O framework based on nio4r.
208
210
  test_files:
209
211
  - spec/async/container/controller_spec.rb
212
+ - spec/async/container/dots.rb
210
213
  - spec/async/container/forked_spec.rb
211
214
  - spec/async/container/hybrid_spec.rb
212
215
  - spec/async/container/notify/notify.rb
213
216
  - spec/async/container/notify/pipe_spec.rb
214
217
  - spec/async/container/notify_spec.rb
215
218
  - spec/async/container/shared_examples.rb
219
+ - spec/async/container/signal_spec.rb
216
220
  - spec/async/container/threaded_spec.rb
217
221
  - spec/async/container_spec.rb
218
222
  - spec/spec_helper.rb