nonnative 1.9.0 → 1.14.0

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: 01d1fb5190a9ee2aa28a1fda1b910077421c2117484485270f030bf1d60d47b8
4
- data.tar.gz: 8154d5f5c8bf9368a379d5076fa1c725a92b1717aa0acde6bd66c88daf8fe8ca
3
+ metadata.gz: d3d063b72e79c07612ef45de94f2b318c59d600be60823a3b72b97e14b819863
4
+ data.tar.gz: e49d9d93bd0657896c7fb1abba459ca59c6c8fc3e59b409fe9c231b20f77cf34
5
5
  SHA512:
6
- metadata.gz: 5b9aecc50dbf9f41cd7e1baaeb07bd40d3619aa83475021aedffead2d686793fa7a2a993a436c15adf62ef6603438e76eb913e3bf0539ce2731e06f63cc8bd66
7
- data.tar.gz: a068e479b0ee2cec5f486a9f17417a279a8fc0e74308a607608cfe766a0d0fbab56c5514b88d23fbeb2681cac1fe869b765c02cff06e91a9915223b8c28e07bc
6
+ metadata.gz: 7d12d87e1f2681fc8e9fef1eecb5b55d81eb773b1845ffb22ab094c17cd9d73bced1874ee277e11c024ca82d66d9f7c4c9d49f6f3827052f06d0ce3bdc86f1f5
7
+ data.tar.gz: 6436da5c0393b9842881722a50f23e80f3264c0a36006e9aeb8402b26910645e875313b430da8df9bd2ba02b5ff08bce576cc74f590a8b5707f6454a27ca83b4
@@ -31,3 +31,9 @@ Layout/SpaceAroundMethodCallOperator:
31
31
 
32
32
  Style/ExponentialNotation:
33
33
  Enabled: true
34
+
35
+ Layout/EmptyLinesAroundAttributeAccessor:
36
+ Enabled: true
37
+
38
+ Style/SlicingWithRange:
39
+ Enabled: true
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nonnative (1.9.0)
4
+ nonnative (1.14.0)
5
5
  cucumber (~> 3.1, >= 3.1.2)
6
6
  grpc (~> 1.28)
7
7
  puma (~> 4.3, >= 4.3.3)
@@ -16,9 +16,9 @@ GEM
16
16
  amatch (0.4.0)
17
17
  mize
18
18
  tins (~> 1.0)
19
- ast (2.4.0)
19
+ ast (2.4.1)
20
20
  backport (1.1.2)
21
- backports (3.17.1)
21
+ backports (3.17.2)
22
22
  benchmark (0.1.0)
23
23
  benchmark-malloc (0.2.0)
24
24
  benchmark-perf (0.6.0)
@@ -31,7 +31,7 @@ GEM
31
31
  pastel (~> 0.7)
32
32
  tty-pie (~> 0.3)
33
33
  concurrent-ruby (1.1.6)
34
- cucumber (3.1.2)
34
+ cucumber (3.2.0)
35
35
  builder (>= 2.1.2)
36
36
  cucumber-core (~> 3.2.0)
37
37
  cucumber-expressions (~> 6.0.1)
@@ -54,7 +54,7 @@ GEM
54
54
  e2mmap (0.1.0)
55
55
  equatable (0.6.1)
56
56
  gherkin (5.1.0)
57
- google-protobuf (3.11.4)
57
+ google-protobuf (3.12.2)
58
58
  googleapis-common-protos-types (1.0.5)
59
59
  google-protobuf (~> 3.11)
60
60
  grpc (1.28.0)
@@ -64,14 +64,14 @@ GEM
64
64
  http-accept (1.7.0)
65
65
  http-cookie (1.0.3)
66
66
  domain_name (~> 0.5)
67
- i18n (1.8.2)
67
+ i18n (1.8.3)
68
68
  concurrent-ruby (~> 1.0)
69
69
  jaro_winkler (1.5.4)
70
70
  json (2.3.0)
71
71
  maruku (0.7.3)
72
72
  mime-types (3.3.1)
73
73
  mime-types-data (~> 3.2015)
74
- mime-types-data (3.2020.0425)
74
+ mime-types-data (3.2020.0512)
75
75
  mini_portile2 (2.4.0)
76
76
  mize (0.4.0)
77
77
  protocol (~> 2.0)
@@ -83,17 +83,17 @@ GEM
83
83
  nio4r (2.5.2)
84
84
  nokogiri (1.10.9)
85
85
  mini_portile2 (~> 2.4.0)
86
- parallel (1.19.1)
87
- parser (2.7.1.2)
86
+ parallel (1.19.2)
87
+ parser (2.7.1.3)
88
88
  ast (~> 2.4.0)
89
89
  pastel (0.7.4)
90
90
  equatable (~> 0.6)
91
91
  tty-color (~> 0.5)
92
92
  protocol (2.0.0)
93
93
  ruby_parser (~> 3.0)
94
- puma (4.3.3)
94
+ puma (4.3.5)
95
95
  nio4r (~> 2.0)
96
- rack (2.2.2)
96
+ rack (2.2.3)
97
97
  rack-protection (2.0.8.1)
98
98
  rack
99
99
  rainbow (3.0.0)
@@ -103,7 +103,7 @@ GEM
103
103
  http-cookie (>= 1.0.2, < 2.0)
104
104
  mime-types (>= 1.16, < 4.0)
105
105
  netrc (~> 0.8)
106
- reverse_markdown (1.4.0)
106
+ reverse_markdown (2.0.0)
107
107
  nokogiri
108
108
  rexml (3.2.4)
109
109
  rspec (3.9.0)
@@ -124,8 +124,7 @@ GEM
124
124
  diff-lcs (>= 1.2.0, < 2.0)
125
125
  rspec-support (~> 3.9.0)
126
126
  rspec-support (3.9.3)
127
- rubocop (0.82.0)
128
- jaro_winkler (~> 1.5.1)
127
+ rubocop (0.83.0)
129
128
  parallel (~> 1.10)
130
129
  parser (>= 2.7.0.1)
131
130
  rainbow (>= 2.2.2, < 4.0)
@@ -136,7 +135,7 @@ GEM
136
135
  ruby2_keywords (0.0.2)
137
136
  ruby_parser (3.14.2)
138
137
  sexp_processor (~> 4.9)
139
- sexp_processor (4.14.1)
138
+ sexp_processor (4.15.0)
140
139
  simplecov (0.17.1)
141
140
  docile (~> 1.1)
142
141
  json (>= 1.8, < 3)
@@ -147,7 +146,7 @@ GEM
147
146
  rack (~> 2.0)
148
147
  rack-protection (= 2.0.8.1)
149
148
  tilt (~> 2.0)
150
- solargraph (0.39.7)
149
+ solargraph (0.39.8)
151
150
  backport (~> 1.1)
152
151
  benchmark
153
152
  bundler (>= 1.17.2)
@@ -156,7 +155,7 @@ GEM
156
155
  maruku (~> 0.7, >= 0.7.3)
157
156
  nokogiri (~> 1.9, >= 1.9.1)
158
157
  parser (~> 2.3)
159
- reverse_markdown (~> 1.0, >= 1.0.5)
158
+ reverse_markdown (>= 1.0.5, < 3)
160
159
  rubocop (~> 0.52)
161
160
  thor (~> 1.0)
162
161
  tilt (~> 2.0)
@@ -164,7 +163,7 @@ GEM
164
163
  sync (0.5.0)
165
164
  thor (1.0.1)
166
165
  tilt (2.0.10)
167
- tins (1.24.1)
166
+ tins (1.25.0)
168
167
  sync
169
168
  tty-color (0.5.1)
170
169
  tty-cursor (0.7.1)
@@ -186,7 +185,7 @@ DEPENDENCIES
186
185
  grpc-tools (~> 1.28)
187
186
  nonnative!
188
187
  rake (~> 13.0, >= 13.0.1)
189
- rubocop (~> 0.82.0)
188
+ rubocop (~> 0.83.0)
190
189
  simplecov (~> 0.17.1)
191
190
  solargraph (~> 0.39.7)
192
191
 
@@ -18,10 +18,12 @@ 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'
24
25
  require 'nonnative/http_client'
26
+ require 'nonnative/application'
25
27
  require 'nonnative/http_server'
26
28
  require 'nonnative/grpc_server'
27
29
  require 'nonnative/grpc_server'
@@ -45,18 +47,25 @@ module Nonnative
45
47
 
46
48
  def start
47
49
  @pool ||= Nonnative::Pool.new(configuration)
50
+ errors = []
48
51
 
49
52
  @pool.start do |name, id, result|
50
- raise Nonnative::StartError, "Started #{name} with id #{id}, though did respond in time" unless result
53
+ errors << "Started #{name} with id #{id}, though did respond in time" unless result
51
54
  end
55
+
56
+ raise Nonnative::StartError, errors.join("\n") unless errors.empty?
52
57
  end
53
58
 
54
59
  def stop
55
60
  return if @pool.nil?
56
61
 
62
+ errors = []
63
+
57
64
  @pool.stop do |name, id, result|
58
- raise Nonnative::StopError, "Stopped #{name} with id #{id}, though did respond in time" unless result
65
+ errors << "Stopped #{name} with id #{id}, though did respond in time" unless result
59
66
  end
67
+
68
+ raise Nonnative::StopError, errors.join("\n") unless errors.empty?
60
69
  end
61
70
 
62
71
  def clear
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class Application < Sinatra::Application
5
+ set :bind, '0.0.0.0'
6
+ set :server, :puma
7
+ set :logging, false
8
+ set :quiet, true
9
+ end
10
+ end
@@ -1,36 +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
15
+ unless command_exists?
16
+ @pid = command_spawn
17
+ wait_start
18
18
  end
19
19
 
20
20
  pid
21
21
  end
22
22
 
23
23
  def stop
24
- raise Nonnative::Error, "Can't stop a process that has not started" unless started
25
-
26
- ::Process.kill('SIGINT', pid)
27
- @started = false
24
+ if command_exists?
25
+ command_kill
26
+ wait_stop
27
+ end
28
28
 
29
29
  pid
30
30
  end
31
31
 
32
+ protected
33
+
34
+ def wait_stop
35
+ timeout.perform do
36
+ Process.waitpid2(pid)
37
+ end
38
+ end
39
+
32
40
  private
33
41
 
34
- 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
35
60
  end
36
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)
@@ -16,13 +16,19 @@ module Nonnative
16
16
  end
17
17
 
18
18
  def perform_start
19
- server.run_till_terminated
19
+ server.run
20
20
  end
21
21
 
22
22
  def perform_stop
23
23
  server.stop
24
24
  end
25
25
 
26
+ protected
27
+
28
+ def wait_start
29
+ server.wait_till_running(service.timeout)
30
+ end
31
+
26
32
  private
27
33
 
28
34
  attr_reader :server
@@ -22,6 +22,20 @@ module Nonnative
22
22
  end
23
23
  end
24
24
 
25
+ def delete(pathname, headers = {})
26
+ with_exception do
27
+ uri = URI.join(host, pathname)
28
+ RestClient.delete(uri.to_s, headers)
29
+ end
30
+ end
31
+
32
+ def put(pathname, payload, headers = {})
33
+ with_exception do
34
+ uri = URI.join(host, pathname)
35
+ RestClient.put(uri.to_s, payload.to_json, headers)
36
+ end
37
+ end
38
+
25
39
  private
26
40
 
27
41
  attr_reader :host
@@ -2,11 +2,14 @@
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
+ @timeout = Nonnative::Timeout.new(service.timeout)
7
+ @queue = Queue.new
8
+
9
+ Application.set :port, service.port
7
10
  configure Application
8
11
 
9
- super port
12
+ super service
10
13
  end
11
14
 
12
15
  def configure(http)
@@ -14,18 +17,25 @@ module Nonnative
14
17
  end
15
18
 
16
19
  def perform_start
17
- Application.start!
20
+ Application.start! do |server|
21
+ queue << server
22
+ end
18
23
  end
19
24
 
20
25
  def perform_stop
21
26
  Application.stop!
22
27
  end
23
28
 
24
- class Application < Sinatra::Application
25
- set :bind, '0.0.0.0'
26
- set :server, :puma
27
- set :logging, false
28
- set :quiet, true
29
+ protected
30
+
31
+ def wait_start
32
+ timeout.perform do
33
+ queue.pop
34
+ end
29
35
  end
36
+
37
+ private
38
+
39
+ attr_reader :timeout, :queue
30
40
  end
31
41
  end
@@ -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,14 +12,25 @@ module Nonnative
16
12
  end
17
13
 
18
14
  def start
19
- object_id
15
+ unless thread
16
+ @thread = Thread.new { perform_start }
17
+ wait_start
18
+ end
19
+
20
+ id
20
21
  end
21
22
 
22
23
  def stop
23
- perform_stop
24
- object_id
24
+ if thread
25
+ perform_stop
26
+ thread.terminate
27
+ @thread = nil
28
+ wait_stop
29
+ end
30
+
31
+ id
25
32
  end
26
33
 
27
- attr_reader :port
34
+ attr_reader :service, :id, :thread
28
35
  end
29
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.9.0'
4
+ VERSION = '1.14.0'
5
5
  end
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency 'chutney', '~> 2.0', '>= 2.0.3.1'
37
37
  spec.add_development_dependency 'grpc-tools', '~> 1.28'
38
38
  spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
39
- spec.add_development_dependency 'rubocop', '~> 0.82.0'
39
+ spec.add_development_dependency 'rubocop', '~> 0.83.0'
40
40
  spec.add_development_dependency 'simplecov', '~> 0.17.1'
41
41
  spec.add_development_dependency 'solargraph', '~> 0.39.7'
42
42
  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.9.0
4
+ version: 1.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Falkowski
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-09 00:00:00.000000000 Z
11
+ date: 2020-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -212,14 +212,14 @@ dependencies:
212
212
  requirements:
213
213
  - - "~>"
214
214
  - !ruby/object:Gem::Version
215
- version: 0.82.0
215
+ version: 0.83.0
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
- version: 0.82.0
222
+ version: 0.83.0
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: simplecov
225
225
  requirement: !ruby/object:Gem::Requirement
@@ -270,6 +270,7 @@ files:
270
270
  - bin/console
271
271
  - bin/setup
272
272
  - lib/nonnative.rb
273
+ - lib/nonnative/application.rb
273
274
  - lib/nonnative/before.rb
274
275
  - lib/nonnative/command.rb
275
276
  - lib/nonnative/configuration.rb
@@ -284,6 +285,7 @@ files:
284
285
  - lib/nonnative/pool.rb
285
286
  - lib/nonnative/port.rb
286
287
  - lib/nonnative/server.rb
288
+ - lib/nonnative/service.rb
287
289
  - lib/nonnative/start_error.rb
288
290
  - lib/nonnative/startup.rb
289
291
  - lib/nonnative/stop_error.rb
@@ -295,7 +297,7 @@ homepage: https://github.com/alexfalkowski/nonnative
295
297
  licenses:
296
298
  - Unlicense
297
299
  metadata: {}
298
- post_install_message:
300
+ post_install_message:
299
301
  rdoc_options: []
300
302
  require_paths:
301
303
  - lib
@@ -311,7 +313,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
311
313
  version: '0'
312
314
  requirements: []
313
315
  rubygems_version: 3.0.3
314
- signing_key:
316
+ signing_key:
315
317
  specification_version: 4
316
318
  summary: Allows you to keep using the power of ruby to test other systems
317
319
  test_files: []