Skip to content

Commit 3f49170

Browse files
authored
Merge pull request #28 from testdouble/fix-test-crashes-in-parallel-execution
Fix parallel test file collisions
2 parents f6a18d6 + 5976de3 commit 3f49170

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/azure_blob/client.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ def blob_exist?(key, options = {})
194194
#
195195
# Returns a hash of the blob's tags.
196196
def get_blob_tags(key)
197-
uri = generate_uri("#{container}/#{key}?comp=tags")
197+
uri = generate_uri("#{container}/#{key}")
198+
uri.query = URI.encode_www_form(comp: "tags")
198199
response = Http.new(uri, signer:).get
199200

200201
Tags.from_response(response).to_h
@@ -246,7 +247,8 @@ def delete_container(options = {})
246247
#
247248
# Example: +generate_uri("#{container}/#{key}")+
248249
def generate_uri(path)
249-
URI.parse(URI::RFC2396_PARSER.escape(File.join(host, path)))
250+
encoded = path.split("/").map { |segment| CGI.escape(segment) }.join("/")
251+
URI.parse([ host.chomp("/"), encoded ].join("/"))
250252
end
251253

252254
# Returns an SAS signed URI

test/client/test_client.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def setup
2222
principal_id: @principal_id,
2323
host: @host,
2424
)
25-
@key = "test client##{name}"
25+
@uid = SecureRandom.uuid
26+
@key = "test-client-?-#{name}-#{@uid}" # ? in key to test proper escaping
2627
@content = "Some random content #{Random.rand(200)}"
2728
end
2829

@@ -197,9 +198,9 @@ def test_delete
197198
end
198199

199200
def test_delete_prefix
200-
prefix = "#{name}_prefix"
201+
prefix = "#{name}_prefix_#{@uid}"
201202
keys = 4.times.map do |i|
202-
key = "#{prefix}/#{name}_#{i}"
203+
key = "#{prefix}/#{i}"
203204
client.create_block_blob(key, content)
204205
key
205206
end
@@ -212,7 +213,7 @@ def test_delete_prefix
212213
end
213214

214215
def test_list_prefix
215-
prefix = "#{name}_prefix"
216+
prefix = "#{name}_prefix_#{@uid}"
216217
@key = "#{prefix}/#{key}"
217218
client.create_block_blob(key, content)
218219

@@ -222,9 +223,9 @@ def test_list_prefix
222223
end
223224

224225
def test_list_blobs_with_pages
225-
prefix = "#{name}_prefix"
226+
prefix = "#{name}_prefix_#{@uid}"
226227
keys = 4.times.map do |i|
227-
key = "#{prefix}/#{name}_#{i}"
228+
key = "#{prefix}/#{i}"
228229
client.create_block_blob(key, content)
229230
key
230231
end

0 commit comments

Comments
 (0)