nonnative 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a5cb014d7be492fca744eb85ac93dc367935a8ac2e3693e133833597a3bd549
4
- data.tar.gz: ff5f799bb3dd66da7d9d933b0c16a596e43841a9bbcb2c87573de03a1dbf5f2f
3
+ metadata.gz: 5ccdd2979601ad074af9108e0cad92b25912bdb4cbfc53ba70c4dab7c833b828
4
+ data.tar.gz: af791d87b74e5db4d962405e975ee527e1d3e4522c48120835971f94af3a486a
5
5
  SHA512:
6
- metadata.gz: ca60a62a4fffa470f50afabe68e51eb3ed93c139c06c4f6cd12a061058c7ef92f75e025ae4fa4eaeae456a47511a97f305c5d3dcdbfb8f090406f2567db4ccc1
7
- data.tar.gz: 53b1f5fba7553ccac0cfada04affa93e0cf7c22c9778d807b70376f5fa7f542b61d262311daac903ae3d929828fcfaac6f053a91377b4b8cf2c4124c4e5fbe79
6
+ metadata.gz: 9bc5f8258ebbc338ff5fc6c09b0af4651c9969e4401ba91dbf2daebfe4ff8e4078520b822f51d14a080726ea7279b13dde7ded0d7b247c1c0c10015f4ee1ae96
7
+ data.tar.gz: 97ff9785e3eb41370fe71dea80c37497d90b16805e5999b6ef0d17575b16c68fdf8584445dfd151285c8f1c4e6c3410ba33f1d2f81fd6ffdafea2461a9d46178
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nonnative (1.11.0)
4
+ nonnative (1.12.0)
5
5
  cucumber (~> 3.1, >= 3.1.2)
6
6
  grpc (~> 1.28)
7
7
  puma (~> 4.3, >= 4.3.3)
@@ -18,6 +18,7 @@ require 'nonnative/port'
18
18
  require 'nonnative/configuration'
19
19
  require 'nonnative/configuration_process'
20
20
  require 'nonnative/configuration_server'
21
+ require 'nonnative/service'
21
22
  require 'nonnative/command'
22
23
  require 'nonnative/pool'
23
24
  require 'nonnative/server'
@@ -45,18 +46,25 @@ module Nonnative
45
46
 
46
47
  def start
47
48
  @pool ||= Nonnative::Pool.new(configuration)
49
+ errors = []
48
50
 
49
51
  @pool.start do |name, id, result|
50
- raise Nonnative::StartError, "Started #{name} with id #{id}, though did respond in time" unless result
52
+ errors << "Started #{name} with id #{id}, though did respond in time" unless result
51
53
  end
54
+
55
+ raise Nonnative::StartError, errors.join("\n") unless errors.empty?
52
56
  end
53
57
 
54
58
  def stop
55
59
  return if @pool.nil?
56
60
 
61
+ errors = []
62
+
57
63
  @pool.stop do |name, id, result|
58
- raise Nonnative::StopError, "Stopped #{name} with id #{id}, though did respond in time" unless result
64
+ errors << "Stopped #{name} with id #{id}, though did respond in time" unless result
59
65
  end
66
+
67
+ raise Nonnative::StopError, errors.join("\n") unless errors.empty?
60
68
  end
61
69
 
62
70
  def clear
@@ -1,40 +1,61 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Command
5
- def initialize(process)
6
- @process = process
7
- @started = false
4
+ class Command < Nonnative::Service
5
+ def initialize(service)
6
+ @service = service
7
+ @timeout = Nonnative::Timeout.new(service.timeout)
8
8
  end
9
9
 
10
10
  def name
11
- process.command
11
+ service.command
12
12
  end
13
13
 
14
14
  def start
15
- unless started
16
- @pid = spawn(process.command, %i[out err] => [process.file, 'a'])
17
- @started = true
18
-
19
- sleep 0.1 # Processes take time to start
15
+ unless command_exists?
16
+ @pid = command_spawn
17
+ wait_start
20
18
  end
21
19
 
22
20
  pid
23
21
  end
24
22
 
25
23
  def stop
26
- raise Nonnative::Error, "Can't stop a process that has not started" unless started
24
+ if command_exists?
25
+ command_kill
26
+ wait_stop
27
+ end
27
28
 
28
- ::Process.kill('SIGINT', pid)
29
- @started = false
29
+ pid
30
+ end
30
31
 
31
- sleep 0.1 # Processes take time to stop
32
+ protected
32
33
 
33
- pid
34
+ def wait_stop
35
+ timeout.perform do
36
+ Process.waitpid2(pid)
37
+ end
34
38
  end
35
39
 
36
40
  private
37
41
 
38
- attr_reader :process, :pid, :started
42
+ attr_reader :service, :timeout, :pid
43
+
44
+ def command_kill
45
+ Process.kill('SIGINT', pid)
46
+ end
47
+
48
+ def command_spawn
49
+ spawn(service.command, %i[out err] => [service.file, 'a'])
50
+ end
51
+
52
+ def command_exists?
53
+ return false if pid.nil?
54
+
55
+ Process.kill(0, pid)
56
+ true
57
+ rescue Errno::ESRCH
58
+ false
59
+ end
39
60
  end
40
61
  end
@@ -2,13 +2,13 @@
2
2
 
3
3
  module Nonnative
4
4
  class GRPCServer < Nonnative::Server
5
- def initialize(port)
5
+ def initialize(service)
6
6
  @server = GRPC::RpcServer.new
7
7
 
8
- server.add_http2_port("0.0.0.0:#{port}", :this_port_is_insecure)
8
+ server.add_http2_port("0.0.0.0:#{service.port}", :this_port_is_insecure)
9
9
  configure server
10
10
 
11
- super port
11
+ super service
12
12
  end
13
13
 
14
14
  def configure(grpc)
@@ -23,6 +23,12 @@ module Nonnative
23
23
  server.stop
24
24
  end
25
25
 
26
+ protected
27
+
28
+ def wait_start
29
+ server.wait_till_running(1)
30
+ end
31
+
26
32
  private
27
33
 
28
34
  attr_reader :server
@@ -2,11 +2,11 @@
2
2
 
3
3
  module Nonnative
4
4
  class HTTPServer < Nonnative::Server
5
- def initialize(port)
6
- Application.set :port, port
5
+ def initialize(service)
6
+ Application.set :port, service.port
7
7
  configure Application
8
8
 
9
- super port
9
+ super service
10
10
  end
11
11
 
12
12
  def configure(http)
@@ -28,7 +28,7 @@ module Nonnative
28
28
 
29
29
  def servers
30
30
  @servers ||= configuration.servers.map do |d|
31
- [d.klass.new(d.port), Nonnative::Port.new(d)]
31
+ [d.klass.new(d), Nonnative::Port.new(d)]
32
32
  end
33
33
  end
34
34
 
@@ -1,14 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Server < Thread
5
- def initialize(port)
6
- @port = port
7
- self.abort_on_exception = true
8
-
9
- super do
10
- perform_start
11
- end
4
+ class Server < Nonnative::Service
5
+ def initialize(service)
6
+ @service = service
7
+ @id = SecureRandom.hex(5)
12
8
  end
13
9
 
14
10
  def name
@@ -16,19 +12,25 @@ module Nonnative
16
12
  end
17
13
 
18
14
  def start
19
- sleep 0.1 # Servers take time to start
15
+ unless thread
16
+ @thread = Thread.new { perform_start }
17
+ wait_start
18
+ end
20
19
 
21
- object_id
20
+ id
22
21
  end
23
22
 
24
23
  def stop
25
- perform_stop
26
-
27
- sleep 0.1 # Servers take time to stop
24
+ if thread
25
+ perform_stop
26
+ thread.terminate
27
+ @thread = nil
28
+ wait_stop
29
+ end
28
30
 
29
- object_id
31
+ id
30
32
  end
31
33
 
32
- attr_reader :port
34
+ attr_reader :service, :id, :thread
33
35
  end
34
36
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class Service
5
+ protected
6
+
7
+ def wait_start
8
+ sleep 0.1
9
+ end
10
+
11
+ def wait_stop
12
+ sleep 0.1
13
+ end
14
+ end
15
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Nonnative.start
4
-
5
3
  at_exit do
6
4
  Nonnative.stop
7
5
  end
6
+
7
+ Nonnative.start
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- VERSION = '1.11.0'
4
+ VERSION = '1.12.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nonnative
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Falkowski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-14 00:00:00.000000000 Z
11
+ date: 2020-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -284,6 +284,7 @@ files:
284
284
  - lib/nonnative/pool.rb
285
285
  - lib/nonnative/port.rb
286
286
  - lib/nonnative/server.rb
287
+ - lib/nonnative/service.rb
287
288
  - lib/nonnative/start_error.rb
288
289
  - lib/nonnative/startup.rb
289
290
  - lib/nonnative/stop_error.rb