webmock 3.9.2 → 3.9.3

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: 288c357fc347a74fb184fce39aa9aae6bd519efa26ed02a9d04f9f8fe3b85d47
4
- data.tar.gz: 45b80da5db5b767f2ecf109bfcee71179f39607e313dfb0d633a2ed47c7d1dcd
3
+ metadata.gz: 0a87447f51d9795b044f000997ec83ce2d5673373a7a06dec331fa2de9d008bf
4
+ data.tar.gz: 5122a5da6a3914b138f1f1e1e690d82f1634f92af63da7efe4e1ac94f48ab4bf
5
5
  SHA512:
6
- metadata.gz: 47f67ac72cf54bfe63b33d383deb69724cf5574bdf37204df96b708f822613b21893848716e93e29d92a79a22dfdb44280a59fb71c4933a2a0a9d97496c0c16c
7
- data.tar.gz: e7f1ceaae61b7a29f81e5fc506477236a85ac5338f9fcf58ea41e0f66cfe2c7dbff40e2aedffba992901ac27139526cc9e43f41b7cf222e1ee02861aff78616d
6
+ metadata.gz: 8af4021d6ab4e24f09a1bccebc87c2031067c78dfadf92b3a598df0eb56742c3eed1dae935bec0abcd892082933c14114e964a95d41369d9855f7417f3d6b149
7
+ data.tar.gz: 68f43e43910e6bce66eb847caca053fd94bf3fe363d838deb6e31e98b83d9013592a03d0df499f059b5473d4ad81401e6720e86ae9799a19e62f182d41ea24b0
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ # 3.9.3
4
+
5
+ * Make httpclient_adapter thread-safe
6
+
7
+ Thanks to [Adam Harwood](https://github.com/adam-harwood)
8
+
3
9
  # 3.9.2
4
10
 
5
11
  * Made global stubs thread-safe
@@ -43,6 +43,9 @@ if defined?(::HTTPClient)
43
43
  end
44
44
 
45
45
  module WebMockHTTPClients
46
+
47
+ REQUEST_RESPONSE_LOCK = Mutex.new
48
+
46
49
  def do_get_block(req, proxy, conn, &block)
47
50
  do_get(req, proxy, conn, false, &block)
48
51
  end
@@ -57,7 +60,7 @@ if defined?(::HTTPClient)
57
60
  WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
58
61
 
59
62
  if webmock_responses[request_signature]
60
- webmock_response = webmock_responses.delete(request_signature)
63
+ webmock_response = synchronize_request_response { webmock_responses.delete(request_signature) }
61
64
  response = build_httpclient_response(webmock_response, stream, req.header, &block)
62
65
  @request_filter.each do |filter|
63
66
  filter.filter_response(req, response)
@@ -68,7 +71,7 @@ if defined?(::HTTPClient)
68
71
  res
69
72
  elsif WebMock.net_connect_allowed?(request_signature.uri)
70
73
  # in case there is a nil entry in the hash...
71
- webmock_responses.delete(request_signature)
74
+ synchronize_request_response { webmock_responses.delete(request_signature) }
72
75
 
73
76
  res = if stream
74
77
  do_get_stream_without_webmock(req, proxy, conn, &block)
@@ -100,7 +103,7 @@ if defined?(::HTTPClient)
100
103
  def do_request_async(method, uri, query, body, extheader)
101
104
  req = create_request(method, uri, query, body, extheader)
102
105
  request_signature = build_request_signature(req)
103
- webmock_request_signatures << request_signature
106
+ synchronize_request_response { webmock_request_signatures << request_signature }
104
107
 
105
108
  if webmock_responses[request_signature] || WebMock.net_connect_allowed?(request_signature.uri)
106
109
  super
@@ -184,7 +187,9 @@ if defined?(::HTTPClient)
184
187
 
185
188
  def webmock_responses
186
189
  @webmock_responses ||= Hash.new do |hash, request_signature|
187
- hash[request_signature] = WebMock::StubRegistry.instance.response_for_request(request_signature)
190
+ synchronize_request_response do
191
+ hash[request_signature] = WebMock::StubRegistry.instance.response_for_request(request_signature)
192
+ end
188
193
  end
189
194
  end
190
195
 
@@ -193,8 +198,10 @@ if defined?(::HTTPClient)
193
198
  end
194
199
 
195
200
  def previous_signature_for(signature)
196
- return nil unless index = webmock_request_signatures.index(signature)
197
- webmock_request_signatures.delete_at(index)
201
+ synchronize_request_response do
202
+ return nil unless index = webmock_request_signatures.index(signature)
203
+ webmock_request_signatures.delete_at(index)
204
+ end
198
205
  end
199
206
 
200
207
  private
@@ -209,6 +216,16 @@ if defined?(::HTTPClient)
209
216
  hdrs
210
217
  end
211
218
  end
219
+
220
+ def synchronize_request_response
221
+ if REQUEST_RESPONSE_LOCK.owned?
222
+ yield
223
+ else
224
+ REQUEST_RESPONSE_LOCK.synchronize do
225
+ yield
226
+ end
227
+ end
228
+ end
212
229
  end
213
230
 
214
231
  class WebMockHTTPClient < HTTPClient
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '3.9.2' unless defined?(::WebMock::VERSION)
2
+ VERSION = '3.9.3' unless defined?(::WebMock::VERSION)
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.2
4
+ version: 3.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Blimke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-12 00:00:00.000000000 Z
11
+ date: 2020-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -407,9 +407,9 @@ licenses:
407
407
  - MIT
408
408
  metadata:
409
409
  bug_tracker_uri: https://github.com/bblimke/webmock/issues
410
- changelog_uri: https://github.com/bblimke/webmock/blob/v3.9.2/CHANGELOG.md
411
- documentation_uri: https://www.rubydoc.info/gems/webmock/3.9.2
412
- source_code_uri: https://github.com/bblimke/webmock/tree/v3.9.2
410
+ changelog_uri: https://github.com/bblimke/webmock/blob/v3.9.3/CHANGELOG.md
411
+ documentation_uri: https://www.rubydoc.info/gems/webmock/3.9.3
412
+ source_code_uri: https://github.com/bblimke/webmock/tree/v3.9.3
413
413
  wiki_uri: https://github.com/bblimke/webmock/wiki
414
414
  post_install_message:
415
415
  rdoc_options: []