Skip to content

Commit 0031a46

Browse files
committed
Make sleep time configurable in MetadataDownloader
This way, the tests can run fast, instead of waiting for the default 20s
1 parent 0c53205 commit 0031a46

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Diff for: lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_download_helper.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,21 @@ module Helper
5757
class MetadataDownloader
5858
attr_reader :target_folder, :target_files
5959

60-
def initialize(target_folder, target_files, auto_retry)
60+
def initialize(target_folder, target_files, auto_retry, auto_retry_sleep_time = 20, auto_retry_max_attempts = 30)
6161
@target_folder = target_folder
6262
@target_files = target_files
6363
@auto_retry = auto_retry
64+
@auto_retry_sleep_time = auto_retry_sleep_time
6465
@alternates = {}
6566
@auto_retry_attempt_counter = 0
6667
end
6768

6869
# Downloads data from GlotPress, in JSON format
6970
def download(target_locale, glotpress_url, is_source)
70-
downloader = GlotPressDownloader.new(auto_retry: @auto_retry)
71+
downloader = GlotpressDownloader.new(
72+
auto_retry: @auto_retry,
73+
auto_retry_sleep_time: @auto_retry_sleep_time
74+
)
7175
response = downloader.download(glotpress_url)
7276
handle_glotpress_download(response: response, locale: target_locale, is_source: is_source)
7377
end

Diff for: spec/metadata_download_helper_spec.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
metadata_downloader = described_class.new(
99
tmp_dir,
1010
{ key: { desc: 'target-file-name.txt' } },
11-
true
11+
true,
12+
0.1
1213
)
1314

1415
fake_url = 'https://test.com'
@@ -24,7 +25,7 @@
2425
end
2526

2627
expect(Fastlane::UI).to receive(:message)
27-
.with(/Received 429 for `#{fake_url}`. Auto retrying in 20 seconds.../)
28+
.with(/Received 429 for `#{fake_url}`. Auto retrying in 0.1 seconds.../)
2829

2930
expect(Fastlane::UI).to receive(:message)
3031
.with(/No translation available for en-AU/)
@@ -34,7 +35,7 @@
3435

3536
metadata_downloader.download('en-AU', fake_url, false)
3637

37-
expect(count).to eq(2)
38+
assert_requested(:get, fake_url, times: 2)
3839
end
3940
end
4041
end

0 commit comments

Comments
 (0)