Skip to content

Commit 9a51a01

Browse files
committed
fix: use native lockfile, rather than ruby gem, tested on ruby 3.3.0-dev
1 parent e63774a commit 9a51a01

File tree

3 files changed

+86
-86
lines changed

3 files changed

+86
-86
lines changed

lib/pact/consumer_contract/consumer_contract_writer.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
require 'pact/consumer_contract/consumer_contract_decorator'
66
require 'pact/shared/active_support_support'
77
require 'fileutils'
8-
require 'filelock'
98

109
module Pact
1110

@@ -60,16 +59,18 @@ def update_pactfile_if_needed
6059
def update_pactfile
6160
logger.info log_message
6261
FileUtils.mkdir_p File.dirname(pactfile_path)
63-
Filelock(pactfile_path) do | pact_file |
64-
# must be read after obtaining the lock, and must be read from the yielded file object, otherwise windows freaks out
62+
# update a counter using write lock
63+
# don't use "w" because it truncates the file before lock.
64+
File.open(pactfile_path, File::RDWR|File::CREAT, 0644) {|pact_file|
65+
pact_file.flock(File::LOCK_EX)
6566
@existing_contents = pact_file.read
6667
new_contents = pact_json
6768
pact_file.rewind
6869
pact_file.truncate 0
6970
pact_file.write new_contents
7071
pact_file.flush
7172
pact_file.truncate(pact_file.pos)
72-
end
73+
}
7374
end
7475

7576
def pact_json

pact-mock_service.gemspec

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ Gem::Specification.new do |gem|
2525
gem.add_runtime_dependency 'find_a_port', '~> 1.0.1'
2626
gem.add_runtime_dependency 'thor', '>= 0.19', '< 2.0'
2727
gem.add_runtime_dependency 'json'
28-
gem.add_runtime_dependency 'webrick', '~> 1.3'
28+
gem.add_runtime_dependency 'webrick', '~> 1.8'
2929
gem.add_runtime_dependency 'pact-support', '~> 1.16', '>= 1.16.4'
30-
gem.add_runtime_dependency 'filelock', '~> 1.1'
3130

3231
gem.add_development_dependency 'rack-test', '~> 0.7'
3332
gem.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
INFO -- : Cleared interactions for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches one expected request returns the expected response"
1+
INFO -- : Cleared interactions for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches more than one expected request returns an error response"
22
INFO -- : Registered expected interaction GET /alligators
33
DEBUG -- : {
44
"description": "a request for alligators",
@@ -23,13 +23,13 @@ DEBUG -- : {
2323
},
2424
"metadata": null
2525
}
26-
INFO -- : Registered expected interaction GET /zebras
26+
INFO -- : Registered expected interaction GET /alligators
2727
DEBUG -- : {
28-
"description": "a request for zebras",
29-
"providerState": "there are zebras",
28+
"description": "a request for alligators",
29+
"providerState": "there are no alligators",
3030
"request": {
3131
"method": "get",
32-
"path": "/zebras",
32+
"path": "/alligators",
3333
"headers": {
3434
"Accept": "application/json"
3535
}
@@ -40,9 +40,7 @@ DEBUG -- : {
4040
"Content-Type": "application/json"
4141
},
4242
"body": [
43-
{
44-
"name": "Xena Zebra"
45-
}
43+
4644
]
4745
},
4846
"metadata": null
@@ -60,46 +58,7 @@ DEBUG -- : {
6058
"Cookie": ""
6159
}
6260
}
63-
INFO -- : Found matching response for GET /alligators
64-
DEBUG -- : {
65-
"status": 200,
66-
"headers": {
67-
"Content-Type": "application/json"
68-
},
69-
"body": [
70-
{
71-
"name": "Mary"
72-
}
73-
]
74-
}
75-
INFO -- : Received request GET /zebras
76-
DEBUG -- : {
77-
"method": "get",
78-
"query": "",
79-
"path": "/zebras",
80-
"headers": {
81-
"Https": "off",
82-
"Content-Length": "0",
83-
"Accept": "application/json",
84-
"Host": "example.org",
85-
"Cookie": ""
86-
}
87-
}
88-
INFO -- : Found matching response for GET /zebras
89-
DEBUG -- : {
90-
"status": 200,
91-
"headers": {
92-
"Content-Type": "application/json"
93-
},
94-
"body": [
95-
{
96-
"name": "Xena Zebra"
97-
}
98-
]
99-
}
100-
INFO -- : Verifying - interactions matched for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches one expected request returns the expected response"
101-
INFO -- : Cleared interactions for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches more than one expected request returns an error response"
102-
INFO -- : Registered expected interaction GET /alligators
61+
ERROR -- : Multiple interactions found for GET /alligators:
10362
DEBUG -- : {
10463
"description": "a request for alligators",
10564
"providerState": "alligators exist",
@@ -123,7 +82,6 @@ DEBUG -- : {
12382
},
12483
"metadata": null
12584
}
126-
INFO -- : Registered expected interaction GET /alligators
12785
DEBUG -- : {
12886
"description": "a request for alligators",
12987
"providerState": "there are no alligators",
@@ -145,20 +103,21 @@ DEBUG -- : {
145103
},
146104
"metadata": null
147105
}
148-
INFO -- : Received request GET /alligators
149-
DEBUG -- : {
150-
"method": "get",
151-
"query": "",
152-
"path": "/alligators",
153-
"headers": {
154-
"Https": "off",
155-
"Content-Length": "0",
156-
"Accept": "application/json",
157-
"Host": "example.org",
158-
"Cookie": ""
159-
}
160-
}
161-
ERROR -- : Multiple interactions found for GET /alligators:
106+
WARN -- : Verifying - actual interactions do not match expected interactions for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches more than one expected request returns an error response".
107+
Missing requests:
108+
GET /alligators
109+
GET /alligators
110+
111+
112+
113+
WARN -- : Missing requests:
114+
GET /alligators
115+
GET /alligators
116+
117+
118+
119+
INFO -- : Cleared interactions for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches one expected request returns the expected response"
120+
INFO -- : Registered expected interaction GET /alligators
162121
DEBUG -- : {
163122
"description": "a request for alligators",
164123
"providerState": "alligators exist",
@@ -182,12 +141,13 @@ DEBUG -- : {
182141
},
183142
"metadata": null
184143
}
144+
INFO -- : Registered expected interaction GET /zebras
185145
DEBUG -- : {
186-
"description": "a request for alligators",
187-
"providerState": "there are no alligators",
146+
"description": "a request for zebras",
147+
"providerState": "there are zebras",
188148
"request": {
189149
"method": "get",
190-
"path": "/alligators",
150+
"path": "/zebras",
191151
"headers": {
192152
"Accept": "application/json"
193153
}
@@ -198,21 +158,61 @@ DEBUG -- : {
198158
"Content-Type": "application/json"
199159
},
200160
"body": [
201-
161+
{
162+
"name": "Xena Zebra"
163+
}
202164
]
203165
},
204166
"metadata": null
205167
}
206-
WARN -- : Verifying - actual interactions do not match expected interactions for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches more than one expected request returns an error response".
207-
Missing requests:
208-
GET /alligators
209-
GET /alligators
210-
211-
212-
213-
WARN -- : Missing requests:
214-
GET /alligators
215-
GET /alligators
216-
217-
218-
168+
INFO -- : Received request GET /alligators
169+
DEBUG -- : {
170+
"method": "get",
171+
"query": "",
172+
"path": "/alligators",
173+
"headers": {
174+
"Https": "off",
175+
"Content-Length": "0",
176+
"Accept": "application/json",
177+
"Host": "example.org",
178+
"Cookie": ""
179+
}
180+
}
181+
INFO -- : Found matching response for GET /alligators
182+
DEBUG -- : {
183+
"status": 200,
184+
"headers": {
185+
"Content-Type": "application/json"
186+
},
187+
"body": [
188+
{
189+
"name": "Mary"
190+
}
191+
]
192+
}
193+
INFO -- : Received request GET /zebras
194+
DEBUG -- : {
195+
"method": "get",
196+
"query": "",
197+
"path": "/zebras",
198+
"headers": {
199+
"Https": "off",
200+
"Content-Length": "0",
201+
"Accept": "application/json",
202+
"Host": "example.org",
203+
"Cookie": ""
204+
}
205+
}
206+
INFO -- : Found matching response for GET /zebras
207+
DEBUG -- : {
208+
"status": 200,
209+
"headers": {
210+
"Content-Type": "application/json"
211+
},
212+
"body": [
213+
{
214+
"name": "Xena Zebra"
215+
}
216+
]
217+
}
218+
INFO -- : Verifying - interactions matched for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches one expected request returns the expected response"

0 commit comments

Comments
 (0)