stub_server 0.1.0 → 0.5.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
- SHA1:
3
- metadata.gz: 955f6568b93ddc0eb9c8176802b6d6b3656f0efa
4
- data.tar.gz: b74b997143e42a544d44b845eaba4e8e168ceb33
2
+ SHA256:
3
+ metadata.gz: 9bfaeb55228fa829f8e96705257e9fc5876ad4d1457e34f059e7e667414a637a
4
+ data.tar.gz: 98dc6aa936d0c0dd38bd0ef684c2cd54fd80deca9bc11842f0fb85ea09273892
5
5
  SHA512:
6
- metadata.gz: 78883018277395e88f966079b2c36ffb1bdce72a89d56f6f74ff7c1b39e54f8e7282322afbaa95b7114c9b25bc2f5d7740c401b044e0397ac6aadf229d412981
7
- data.tar.gz: 5c4a74865266f6bc4ddfd9581d1e79609e004c6f4093b66fd994a056fa752450c5ae99b8ef27c33603c582cbe250e621e285dddfd6c01656a2c528a79a44b019
6
+ metadata.gz: ff17fa306dae8ae5004031578c566648e6dff274cdca5508878c258577810d3e4ab8d9cd419c35726f7093fb049fc8e9fed88099ad795f748b6becc23cc8ffdd
7
+ data.tar.gz: c130620e847ed59521a4bd83ff789ed6a1f1eb099c9ec22db6cb5cd47fac6e1083e96851d27c4174afa0deb773bfe1d1d8f58de2c3cb9aa3f3cef61b4f24b0be
@@ -17,14 +17,19 @@ class StubServer
17
17
  @ssl = ssl
18
18
  @json = json
19
19
  @webrick = webrick
20
+ @started = false
21
+ @server = nil
22
+ @thread = nil
20
23
  end
21
24
 
22
25
  def boot
23
- Thread.new do
26
+ @thread = Thread.new do
24
27
  options = {
25
28
  Port: @port,
26
29
  Logger: WEBrick::Log.new("/dev/null"),
27
- AccessLog: []
30
+ AccessLog: [],
31
+ DoNotReverseLookup: true, # http://stackoverflow.com/questions/1156759/webrick-is-very-slow-to-respond-how-to-speed-it-up
32
+ StartCallback: -> { @started = true }
28
33
  }
29
34
 
30
35
  if @ssl
@@ -42,30 +47,19 @@ class StubServer
42
47
 
43
48
  options.merge!(@webrick)
44
49
 
45
- Rack::Handler::WEBrick.run(self, options) { |s| @server = s }
50
+ Rack::Handler::WEBrick.run(self, **options) { |s| @server = s }
46
51
  end
47
52
  end
48
53
 
49
54
  def wait
50
- Timeout.timeout(10) do
51
- loop do
52
- begin
53
- socket = TCPSocket.new('localhost', @port)
54
- socket.close if socket
55
- sleep 0.1 if ENV['CI']
56
- return
57
- rescue Errno::ECONNREFUSED
58
- nil
59
- end
60
- end
61
- end
55
+ Timeout.timeout(10) { sleep 0.1 until @started }
62
56
  end
63
57
 
64
58
  def call(env)
65
59
  path = env.fetch("PATH_INFO")
66
60
  code, headers, body = @replies[path]
67
61
  unless code
68
- warn "StubServer: Missing reply for path #{path}" # some clients does not show current url when failing
62
+ warn "StubServer #{@port}: Missing reply for path #{path}" # some clients does not show current url when failing
69
63
  raise
70
64
  end
71
65
  body = [body.to_json] if @json
@@ -73,6 +67,17 @@ class StubServer
73
67
  end
74
68
 
75
69
  def shutdown
76
- @server.shutdown if @server
70
+ @server&.shutdown
71
+ @thread.join # need to wait here and cannot simpliy kill or webbrick keeps running
72
+
73
+ # TimeoutHandler keeps running forever which breaks tests that assert no extra threads
74
+ # we should only stop it if it is empty, otherwise we are still waiting for other servers
75
+ # ideally we'd use WEBrick::Utils::TimeoutHandler::TimeoutMutex.synchronize to avoid race conditions,
76
+ # but that is also used in .terminate and would lead to deadlocks ...
77
+ # TODO: open ruby issue for race-condition free terminate_if_empty
78
+ return if RUBY_VERSION < "2.4.0"
79
+ if WEBrick::Utils::TimeoutHandler.instance.instance_variable_get(:@timeout_info).empty?
80
+ WEBrick::Utils::TimeoutHandler.terminate
81
+ end
77
82
  end
78
83
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class StubServer
3
- VERSION = "0.1.0"
3
+ VERSION = "0.5.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stub_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-16 00:00:00.000000000 Z
11
+ date: 2020-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -45,15 +45,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: 2.0.0
48
+ version: 2.5.0
49
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
- rubyforge_project:
56
- rubygems_version: 2.4.5.1
55
+ rubygems_version: 3.1.2
57
56
  signing_key:
58
57
  specification_version: 4
59
58
  summary: Boot up a real server to serve testing replies