rspec-tracer 0.4.0 → 0.5.0

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: 34f47b6527f2c8f3c1cb3524adf8d81a9fe7e3833c202605a206598dee8758b2
4
- data.tar.gz: e647137006f5f8af18999ea8f2665c09d703bf2cd8ea1e84dec85e66f87ba5e2
3
+ metadata.gz: 2817cccf4825e28177bb8794f8d261635f81ec5c1bd6ca0242ba171e702850ca
4
+ data.tar.gz: 9c5f6af579eec43a994c28b5e8132fec5d71f7a2ddddfb531fafd5c51943d283
5
5
  SHA512:
6
- metadata.gz: 05c204bd00cfa15258a1770790360184c9481d670cc8ef3542b06024976a9e13cf3595e79ecefa0d22c8337d35dee9ef6963b145cf1aa16268f3de467c7d171b
7
- data.tar.gz: b2f7e88fbf404793a9e2daaade7448d51bd63150701a6735c9ae8bdcb17eaf25c926bde411cd61bc5dd20133829d1576d16b7588336f05ec968ae4f3d82a5453
6
+ metadata.gz: 2d3af598e09b8ac043b5f605acf39b588701c4f0e7b4d74646eb0da74c1c85746db60f215e02cd5fba1880bb75288d0d35df3986b08cc71cfbad4d45ad722d2f
7
+ data.tar.gz: 7ce36336213d4d37337afa5b50fd774bd6ef7b235539f3a289f1a804a878fba3fa1e7972e9bd09bb8083c80929c0fc3b6bf0b30f257542fdb5e5c466c1247360
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.5.0] - 2021-09-03
2
+
3
+ ### Fixed
4
+
5
+ - Limit number of cached files download (#16)
6
+
1
7
  ## [0.4.0] - 2021-09-03
2
8
 
3
9
  ### Added
data/README.md CHANGED
@@ -33,8 +33,8 @@ and **caching on CI**, etc.
33
33
  * [RSPEC_TRACER_NO_SKIP](#rspec_tracer_no_skip)
34
34
  * [RSPEC_TRACER_S3_URI](#rspec_tracer_s3_uri)
35
35
  * [RSPEC_TRACER_UPLOAD_LOCAL_CACHE](#rspec_tracer_upload_local_cache)
36
- * [TEST_SUITE_ID](#test_suite_id)
37
36
  * [TEST_SUITES](#test_suites)
37
+ * [TEST_SUITE_ID](#test_suite_id)
38
38
  * [Sample Reports](#sample-reports)
39
39
  * [Examples](#examples)
40
40
  * [Examples Dependency](#examples-dependency)
@@ -128,13 +128,13 @@ Rakefile in your project to have the following:
128
128
  ```
129
129
  3. Before running tests, download the remote cache using the following rake task:
130
130
 
131
- ```ruby
131
+ ```sh
132
132
  bundle exec rake rspec_tracer:remote_cache:download
133
133
  ```
134
134
  4. Run the tests with RSpec using `bundle exec rspec`.
135
135
  5. After running tests, upload the local cache using the following rake task:
136
136
 
137
- ```ruby
137
+ ```sh
138
138
  bundle exec rake rspec_tracer:remote_cache:upload
139
139
  ```
140
140
  6. After running your tests, open `rspec_tracer_report/index.html` in the
@@ -177,6 +177,15 @@ export RSPEC_TRACER_S3_URI=s3://ci-artifacts-bucket/rspec-tracer-cache
177
177
  By default, RSpec Tracer does not upload local cache files. You can set this
178
178
  environment variable to `true` to upload the local cache to S3.
179
179
 
180
+ ### TEST_SUITES
181
+
182
+ Set this environment variable when using test suite id. It determines the total
183
+ number of different test suites you are running.
184
+
185
+ ```ruby
186
+ export TEST_SUITES=8
187
+ ```
188
+
180
189
  ### TEST_SUITE_ID
181
190
 
182
191
  If you have a large set of tests to run, it is recommended to run them in
@@ -189,13 +198,19 @@ TEST_SUITE_ID=1 bundle exec rspec spec/models
189
198
  TEST_SUITE_ID=2 bundle exec rspec spec/helpers
190
199
  ```
191
200
 
192
- ### TEST_SUITES
201
+ If you run parallel builds on the CI, you should specify the test suite ID and
202
+ the total number of test suites when downloading the cache files.
193
203
 
194
- Set this environment variable when using test suite id. It determines the total
195
- number of different test suites you are running.
204
+ ```sh
205
+ $ TEST_SUITES=5 TEST_SUITE_ID=1 bundle exec rake rspec_tracer:remote_cache:download
206
+ ```
196
207
 
197
- ```ruby
198
- export TEST_SUITES=8
208
+ In this case, the appropriate cache should have all the cache files available on
209
+ the S3 for each test suite, not just for the current one. Also, while uploading,
210
+ make sure to provide the test suite id.
211
+
212
+ ```sh
213
+ $ TEST_SUITE_ID=1 bundle exec rake rspec_tracer:remote_cache:upload
199
214
  ```
200
215
 
201
216
  ## Sample Reports
@@ -11,7 +11,7 @@ module RSpecTracer
11
11
 
12
12
  class LocalCacheNotFoundError < StandardError; end
13
13
 
14
- CACHE_FILES_PER_TEST_SUITE = 8
14
+ CACHE_FILES_PER_TEST_SUITE = 7
15
15
 
16
16
  def initialize
17
17
  @s3_uri = ENV['RSPEC_TRACER_S3_URI']
@@ -20,9 +20,6 @@ module RSpecTracer
20
20
  else
21
21
  'aws'
22
22
  end
23
- @test_suite_id = ENV['TEST_SUITE_ID'].to_s
24
- @test_suites = ENV.fetch('TEST_SUITES', '1').to_i
25
- @total_objects = CACHE_FILES_PER_TEST_SUITE * @test_suites
26
23
  end
27
24
 
28
25
  def download
@@ -32,10 +29,7 @@ module RSpecTracer
32
29
  return
33
30
  end
34
31
 
35
- @git = RSpecTracer::RemoteCache::Git.new
36
- @git.prepare_for_download
37
-
38
- @cache_sha = nearest_cache_sha
32
+ prepare_for_download
39
33
 
40
34
  if @cache_sha.nil?
41
35
  puts 'Could not find a suitable cache sha to download'
@@ -57,9 +51,7 @@ module RSpecTracer
57
51
  return
58
52
  end
59
53
 
60
- @run_id = last_run_id
61
- @git = RSpecTracer::RemoteCache::Git.new
62
-
54
+ prepare_for_upload
63
55
  upload_files
64
56
 
65
57
  puts "Uploaded cache from #{@upload_path} to #{@upload_prefix}"
@@ -69,20 +61,57 @@ module RSpecTracer
69
61
 
70
62
  private
71
63
 
64
+ def prepare_for_download
65
+ @test_suite_id = ENV['TEST_SUITE_ID']
66
+ @test_suites = ENV['TEST_SUITES']
67
+
68
+ if @test_suite_id.nil? ^ @test_suites.nil?
69
+ raise(
70
+ CacheDownloadError,
71
+ 'Both the enviornment variables TEST_SUITE_ID and TEST_SUITES are not set'
72
+ )
73
+ end
74
+
75
+ @git = RSpecTracer::RemoteCache::Git.new
76
+ @git.prepare_for_download
77
+
78
+ generate_cached_files_count_and_regex
79
+
80
+ @cache_sha = nearest_cache_sha
81
+ end
82
+
83
+ def generate_cached_files_count_and_regex
84
+ if @test_suites.nil?
85
+ @last_run_files_count = 1
86
+ @last_run_files_regex = '/%<ref>s/last_run.json$'
87
+ @cached_files_count = CACHE_FILES_PER_TEST_SUITE
88
+ @cached_files_regex = '/%<ref>s/[0-9a-f]{32}/.+.json'
89
+ else
90
+ @test_suites = @test_suites.to_i
91
+ @test_suites_regex = (1..@test_suites).to_a.join('|')
92
+
93
+ @last_run_files_count = @test_suites
94
+ @last_run_files_regex = "/%<ref>s/(#{@test_suites_regex})/last_run.json$"
95
+ @cached_files_count = CACHE_FILES_PER_TEST_SUITE * @test_suites.to_i
96
+ @cached_files_regex = "/%<ref>s/(#{@test_suites_regex})/[0-9a-f]{32}/.+.json$"
97
+ end
98
+ end
99
+
72
100
  def nearest_cache_sha
73
101
  @git.ref_list.detect do |ref|
74
- prefix = "#{@s3_uri}/#{ref}/#{@test_suite_id}/".sub(%r{/+$}, '/')
102
+ prefix = "#{@s3_uri}/#{ref}/"
75
103
 
76
104
  puts "Testing prefix #{prefix}"
77
105
 
78
- command = <<-COMMAND.strip.gsub(/\s+/, ' ')
79
- #{@aws_s3} s3 ls #{prefix}
80
- --recursive
81
- --summarize
82
- | grep 'Total Objects'
83
- COMMAND
106
+ objects = `#{@aws_s3} s3 ls #{prefix} --recursive`.chomp.split("\n")
107
+
108
+ last_run_regex = Regexp.new(format(@last_run_files_regex, ref: ref))
109
+
110
+ next if objects.count { |object| object.match?(last_run_regex) } != @last_run_files_count
84
111
 
85
- @total_objects == `#{command}`.chomp.split('Total Objects:').last.to_s.strip.to_i
112
+ cache_regex = Regexp.new(format(@cached_files_regex, ref: ref))
113
+
114
+ objects.count { |object| object.match?(cache_regex) } == @cached_files_count
86
115
  end
87
116
  end
88
117
 
@@ -90,10 +119,19 @@ module RSpecTracer
90
119
  @download_prefix = "#{@s3_uri}/#{@cache_sha}/#{@test_suite_id}/".sub(%r{/+$}, '/')
91
120
  @download_path = RSpecTracer.cache_path
92
121
 
93
- return if system(
122
+ raise CacheDownloadError, 'Failed to download cache files' unless system(
94
123
  @aws_s3, 's3', 'cp',
95
- @download_prefix,
124
+ File.join(@download_prefix, 'last_run.json'),
96
125
  @download_path,
126
+ out: File::NULL, err: File::NULL
127
+ )
128
+
129
+ @run_id = last_run_id
130
+
131
+ return if system(
132
+ @aws_s3, 's3', 'cp',
133
+ File.join(@download_prefix, @run_id),
134
+ File.join(@download_path, @run_id),
97
135
  '--recursive',
98
136
  out: File::NULL, err: File::NULL
99
137
  )
@@ -103,22 +141,20 @@ module RSpecTracer
103
141
  raise CacheDownloadError, 'Failed to download cache files'
104
142
  end
105
143
 
106
- def last_run_id
107
- file_name = File.join(RSpecTracer.cache_path, 'last_run.json')
108
-
109
- return unless File.file?(file_name)
110
-
111
- run_id = JSON.parse(File.read(file_name))['run_id']
112
-
113
- raise LocalCacheNotFoundError, 'Could not find any local cache to upload' if run_id.nil?
144
+ def prepare_for_upload
145
+ @git = RSpecTracer::RemoteCache::Git.new
146
+ @test_suite_id = ENV['TEST_SUITE_ID']
147
+ @upload_prefix = if @test_suite_id.nil?
148
+ "#{@s3_uri}/#{@git.branch_ref}/"
149
+ else
150
+ "#{@s3_uri}/#{@git.branch_ref}/#{@test_suite_id}/"
151
+ end
114
152
 
115
- run_id
153
+ @upload_path = RSpecTracer.cache_path
154
+ @run_id = last_run_id
116
155
  end
117
156
 
118
157
  def upload_files
119
- @upload_prefix = "#{@s3_uri}/#{@git.branch_ref}/#{@test_suite_id}/".sub(%r{/+$}, '/')
120
- @upload_path = RSpecTracer.cache_path
121
-
122
158
  return if system(
123
159
  @aws_s3, 's3', 'cp',
124
160
  File.join(@upload_path, 'last_run.json'),
@@ -127,13 +163,25 @@ module RSpecTracer
127
163
  ) && system(
128
164
  @aws_s3, 's3', 'cp',
129
165
  File.join(@upload_path, @run_id),
130
- "#{@upload_prefix}/#{@run_id}",
166
+ File.join(@upload_prefix, @run_id),
131
167
  '--recursive',
132
168
  out: File::NULL, err: File::NULL
133
169
  )
134
170
 
135
171
  raise CacheUploadError, 'Failed to upload cache files'
136
172
  end
173
+
174
+ def last_run_id
175
+ file_name = File.join(RSpecTracer.cache_path, 'last_run.json')
176
+
177
+ return unless File.file?(file_name)
178
+
179
+ run_id = JSON.parse(File.read(file_name))['run_id']
180
+
181
+ raise LocalCacheNotFoundError, 'Could not find any local cache to upload' if run_id.nil?
182
+
183
+ run_id
184
+ end
137
185
  end
138
186
  end
139
187
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RSpecTracer
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abhimanyu Singh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-02 00:00:00.000000000 Z
11
+ date: 2021-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docile
@@ -105,7 +105,7 @@ licenses:
105
105
  - MIT
106
106
  metadata:
107
107
  homepage_uri: https://github.com/avmnu-sng/rspec-tracer
108
- source_code_uri: https://github.com/avmnu-sng/rspec-tracer/tree/v0.4.0
108
+ source_code_uri: https://github.com/avmnu-sng/rspec-tracer/tree/v0.5.0
109
109
  changelog_uri: https://github.com/avmnu-sng/rspec-tracer/blob/main/CHANGELOG.md
110
110
  bug_tracker_uri: https://github.com/avmnu-sng/rspec-tracer/issues
111
111
  post_install_message: