quarantine 1.0.2 → 1.0.7

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: 124d4c397570d733b8fff064d45174dac576a0a066e96468f195433803c54427
4
- data.tar.gz: 2ccdb87664e827cb07eb7ac70c0909eac402463196908b9b1f3d661c08dda180
3
+ metadata.gz: 4b012ecdd8fb1b5f4b8d014d294bdce9e02370d46afd79bf1f69577c4821f9dc
4
+ data.tar.gz: 6e9ac0c7edfb4d38db0487db389623b7ad75bdf342f74e97e471a6073d81357e
5
5
  SHA512:
6
- metadata.gz: da94641acc051c26921a07ca067915bda895b692fe6016918437aa9cce9a759fed0081965310da3374f2bde002780d650ec1b9dc2ff7c593793d5bf76dba726b
7
- data.tar.gz: df1245c0034495fc9bfd1545e1222459530b7a420311fa218d5164d8fafafd8c3cb4cef9399994e439f75fed305247910837e420ebea23a530a1949ab5ef8546
6
+ metadata.gz: e63db8d4dfc55809f9099fde29350ad86d88d6fb5617bfff576263bbd9ebb155f76d0f38c6e5dc9c7b465c969a8b21714ebacde8c7f8534c207aada2337d632b
7
+ data.tar.gz: 06ee957f72bcdf07da8b3b67d0bb5cbf62aa970c81dd991eb2a28c962d69c232b7f06a37062cf288b74531099e4aa7f2d0935fa00e296961d095c814ede34faf
@@ -1,3 +1,18 @@
1
+ ### 1.0.7
2
+ Support `it_behaves_like` behavior
3
+
4
+ ### 1.0.6
5
+ Update DynamoDB batch_write_item implementation to check for duplicates based on different keys before uploading
6
+
7
+ ### 1.0.5
8
+ Add aws_credentials argument during dynamodb initialization to override the AWS SDK credential chain
9
+
10
+ ### 1.0.4
11
+ Enable upstream callers to mark an example as flaky through the example's metadata
12
+
13
+ ### 1.0.3
14
+ Only require dynamodb instead of full aws-sdk
15
+
1
16
  ### 1.0.2
2
17
  Relax Aws gem version constraint as aws-sdk v3 is 100% backwards
3
18
  compatible with v2
data/README.md CHANGED
@@ -25,7 +25,7 @@ Add these lines to your application's Gemfile:
25
25
  ```rb
26
26
  group :test do
27
27
  gem 'quarantine'
28
- gem 'rspec-retry
28
+ gem 'rspec-retry'
29
29
  end
30
30
  ```
31
31
 
@@ -39,7 +39,7 @@ In your `spec_helper.rb` setup quarantine and rspec-retry gem. Click [rspec-retr
39
39
  require 'quarantine'
40
40
  require 'rspec-retry'
41
41
 
42
- Quarantine.bind({database: :dynamodb, aws_region: 'us-west-1'})
42
+ Quarantine.bind({database: :dynamodb, aws_region: 'us-west-1'}) # Also accepts aws_credentials to override the standard AWS credential chain
43
43
 
44
44
  RSpec.configure do |config|
45
45
 
@@ -100,7 +100,7 @@ end
100
100
 
101
101
  - Table name where failed test are uploaded `:quarantine_failed_tests_table, default: "master_failed_tests"`
102
102
 
103
- - Quarantined tests are not skipped automatically `:skip_quarantined_tests, default: true`
103
+ - Skipping quarantined tests during test runs `:skip_quarantined_tests, default: true`
104
104
 
105
105
  - Recording failed tests `:quarantine_record_failed_tests, default: true`
106
106
 
@@ -140,7 +140,8 @@ CI="1" BRANCH="master" rspec
140
140
 
141
141
  #### Why is dynamodb failing to connect?
142
142
 
143
- The AWS client loads credentials from the following locations:
143
+ The AWS client loads credentials from the following locations (in order of precedence):
144
+ - The optional `aws_credentials` parameter passed into `Quarantine.bind`
144
145
  - `ENV['AWS_ACCESS_KEY_ID']` and `ENV['AWS_SECRET_ACCESS_KEY']`
145
146
  - `Aws.config[:credentials]`
146
147
  - The shared credentials ini file at `~/.aws/credentials`
@@ -148,7 +149,3 @@ The AWS client loads credentials from the following locations:
148
149
  To get AWS credentials, please contact your AWS administrator to get access to dynamodb and create your credentials through IAM.
149
150
 
150
151
  More detailed information can be found: [AWS documentation](https://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Client.html)
151
-
152
- #### Why is `example.clear_exception` failing locally?
153
-
154
- `example.clear_exception` is an attribute added through `rspec_retry`. Make sure `rspec-retry` has been installed and configured.
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'aws-sdk'
4
3
  require 'optparse'
5
4
 
6
5
  require_relative '../lib/quarantine/cli'
@@ -1,10 +1,23 @@
1
- require 'aws-sdk'
2
1
  require 'rspec/retry'
3
2
  require 'quarantine/rspec_adapter'
4
3
  require 'quarantine/test'
5
4
  require 'quarantine/databases/base'
6
5
  require 'quarantine/databases/dynamo_db'
7
6
 
7
+ module RSpec
8
+ module Core
9
+ class Example
10
+ # The implementation of clear_exception in rspec-retry doesn't work
11
+ # for examples that use `it_behaves_like`, so we implement our own version that
12
+ # clear the exception field recursively.
13
+ def clear_exception!
14
+ @exception = nil
15
+ example.clear_exception! if defined?(example)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
8
21
  class Quarantine
9
22
  extend RSpecAdapter
10
23
 
@@ -120,11 +133,8 @@ class Quarantine
120
133
 
121
134
  # Param: RSpec::Core::Example
122
135
  # Clear exceptions on a flaky tests that has been quarantined
123
- #
124
- # example.clear_exception is tightly coupled with the rspec-retry gem and will only exist if
125
- # the rspec-retry gem is enabled
126
136
  def pass_flaky_test(example)
127
- example.clear_exception
137
+ example.clear_exception!
128
138
  add_to_summary(:quarantined_tests, example.id)
129
139
  end
130
140
 
@@ -1,4 +1,4 @@
1
- require 'aws-sdk'
1
+ require 'aws-sdk-dynamodb'
2
2
  require 'quarantine/databases/base'
3
3
  require 'quarantine/error'
4
4
 
@@ -7,13 +7,16 @@ class Quarantine
7
7
  class DynamoDB < Base
8
8
  attr_accessor :dynamodb
9
9
 
10
- def initialize(aws_region: 'us-west-1', **_additional_arguments)
11
- @dynamodb = Aws::DynamoDB::Client.new({ region: aws_region })
10
+ def initialize(aws_region: 'us-west-1', aws_credentials: nil, **_additional_arguments)
11
+ options = { region: aws_region }
12
+ options[:credentials] = aws_credentials if aws_credentials
13
+
14
+ @dynamodb = Aws::DynamoDB::Client.new(options)
12
15
  end
13
16
 
14
17
  def scan(table_name)
15
18
  begin
16
- result = dynamodb.scan({ table_name: table_name })
19
+ result = dynamodb.scan(table_name: table_name)
17
20
  rescue Aws::DynamoDB::Errors::ServiceError
18
21
  raise Quarantine::DatabaseError
19
22
  end
@@ -21,17 +24,32 @@ class Quarantine
21
24
  result&.items
22
25
  end
23
26
 
24
- def batch_write_item(table_name, items, additional_attributes = {})
27
+ def batch_write_item(table_name, items, additional_attributes = {}, dedup_keys = %w[id full_description])
28
+ return if items.empty?
29
+
30
+ # item_a is a duplicate of item_b if all values for each dedup_key in both item_a and item_b match
31
+ is_a_duplicate = ->(item_a, item_b) { dedup_keys.all? { |key| item_a[key] == item_b[key] } }
32
+
33
+ scanned_items = scan(table_name)
34
+
35
+ deduped_items = items.reject do |item|
36
+ scanned_items.any? do |scanned_item|
37
+ is_a_duplicate.call(item.to_string_hash, scanned_item)
38
+ end
39
+ end
40
+
41
+ return if deduped_items.empty?
42
+
25
43
  dynamodb.batch_write_item(
26
- { request_items: {
27
- table_name => items.map do |item|
44
+ request_items: {
45
+ table_name => deduped_items.map do |item|
28
46
  {
29
47
  put_request: {
30
48
  item: { **item.to_hash, **additional_attributes }
31
49
  }
32
50
  }
33
51
  end
34
- } }
52
+ }
35
53
  )
36
54
  rescue Aws::DynamoDB::Errors::ServiceError
37
55
  raise Quarantine::DatabaseError
@@ -39,11 +57,9 @@ class Quarantine
39
57
 
40
58
  def delete_item(table_name, keys)
41
59
  dynamodb.delete_item(
42
- {
43
- table_name: table_name,
44
- key: {
45
- **keys
46
- }
60
+ table_name: table_name,
61
+ key: {
62
+ **keys
47
63
  }
48
64
  )
49
65
  rescue Aws::DynamoDB::Errors::ServiceError
@@ -57,11 +57,13 @@ module RSpecAdapter
57
57
  !quarantine.test_quarantined?(example) &&
58
58
  metadata[:retry_attempts] + 1 == metadata[:retry] && example.exception
59
59
 
60
- # will record the flaky test if is not quarantined and it failed the first run but passed a subsequent run
60
+ # will record the flaky test if is not quarantined and it failed the first run but passed a subsequent run;
61
+ # optionally, the upstream RSpec configuration could define an after hook that marks an example as flaky in
62
+ # the example's metadata
61
63
  quarantine.record_flaky_test(example) if
62
64
  RSpec.configuration.quarantine_record_flaky_tests &&
63
65
  !quarantine.test_quarantined?(example) &&
64
- metadata[:retry_attempts] > 0 && example.exception.nil?
66
+ (metadata[:retry_attempts] > 0 && example.exception.nil?) || metadata[:flaky]
65
67
  end
66
68
  end
67
69
 
@@ -20,5 +20,14 @@ class Quarantine
20
20
  build_number: build_number
21
21
  }
22
22
  end
23
+
24
+ def to_string_hash
25
+ {
26
+ 'id' => id,
27
+ 'full_description' => full_description,
28
+ 'location' => location,
29
+ 'build_number' => build_number
30
+ }
31
+ end
23
32
  end
24
33
  end
@@ -1,3 +1,3 @@
1
1
  class Quarantine
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.0.7'.freeze
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.executables = ['quarantine_dynamodb']
19
19
  s.required_ruby_version = '>= 2.0'
20
20
 
21
- s.add_dependency('aws-sdk', '>= 2.11')
21
+ s.add_dependency('aws-sdk-dynamodb', '~> 1')
22
22
  s.add_dependency('rspec', '~> 3.0')
23
23
  s.add_dependency('rspec-retry', '~> 0.6')
24
24
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quarantine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flexport Engineering, Eric Zhu
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-13 00:00:00.000000000 Z
11
+ date: 2020-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: aws-sdk
14
+ name: aws-sdk-dynamodb
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.11'
19
+ version: '1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.11'
26
+ version: '1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.6'
55
- description:
55
+ description:
56
56
  email:
57
57
  - ericzhu77@gmail.com
58
58
  executables:
@@ -76,7 +76,7 @@ homepage: https://github.com/flexport/quarantine
76
76
  licenses:
77
77
  - MIT
78
78
  metadata: {}
79
- post_install_message:
79
+ post_install_message:
80
80
  rdoc_options: []
81
81
  require_paths:
82
82
  - lib
@@ -91,8 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
- rubygems_version: 3.0.3
95
- signing_key:
94
+ rubygems_version: 3.0.2
95
+ signing_key:
96
96
  specification_version: 4
97
97
  summary: Quarantine flaky Ruby Rspec tests
98
98
  test_files: []