attempt 0.5.1 → 0.6.2

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: 4d3a19c0af424d2b75bea45b426104ce8975948ad978e71b8fb27aaad902feeb
4
- data.tar.gz: bf8d228e1f539cd01877013452dab333f2af8fc315c70cac1a016abcd7960875
3
+ metadata.gz: c954f55aef2408950c9aeafde149fa2562576e62af9f6a0215f6dc90bec184eb
4
+ data.tar.gz: 1951edd8ffc473008f37850504fda990593721378c26c84c3375f9c58df868ef
5
5
  SHA512:
6
- metadata.gz: 065e16dfce9c78d505a81b220e77d5ac0d5855606a4b10b90f2a8fd3dd1d12f7bd83a42268d9e2e2b43db8adaad7506a05cf7ddaba97117ba215c736c6eea3bf
7
- data.tar.gz: 29180b07080e2ee8201ef1ac29b9f266b290ee37ac06ccaa27e79c196548afcc8f8daaf3f9535d8eaeb4cc519bdff9572afa0fbee406ce8e09c37eb864cc962a
6
+ metadata.gz: 687f808427b5c2a686c89892af635b5528886207c6bf0a38036c0b4cceb92592a2a89579301083eb7a3ca01e297878e02ccf57148504e4fb10f1188ebf1841c4
7
+ data.tar.gz: '028d54de4b4602f76d2ffae474c1f1bdc2835604aac33d24cc503cdd250661839bb6eefcf15a7e8fa0d5e25af401cf5a91ff144213c2599551f3d28d38788972'
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,31 +1,56 @@
1
- == 0.5.0 - 2-Jun-2020
1
+ ## 0.6.2 - 2-Jun-2022
2
+ * The safe_timeout library is not used on MS Windows.
3
+
4
+ ## 0.6.1 - 20-Oct-2020
5
+ * Switched the README, MANIFEST and CHANGES to markdown format.
6
+ * Fiddling with the .travis.yml file again.
7
+
8
+ ## 0.6.0 - 17-Sep-2020
9
+
10
+ * Switched from test-unit to rspec and rewrote the specs.
11
+
12
+ ## 0.5.1 - 28-Aug-2020
13
+
14
+ * Added a Gemfile.
15
+ * Updated Rakefile to clean .lock files.
16
+ * Bumped structured_warnings version to 0.4.0 so that it works with Ruby 2.7.
17
+ Thanks go to Alexey Zapriy for the spot.
18
+
19
+ ## 0.5.0 - 2-Jun-2020
20
+
2
21
  * Switched to Apache-2.0 license, added LICENSE file.
3
22
  * Updated cert again.
4
23
 
5
- == 0.4.0 - 5-Sep-2017
24
+ ## 0.4.0 - 5-Sep-2017
25
+
6
26
  * Switched constructor to use keyword arguments.
7
27
  * Replaced Timeout with SafeTimeout and added the safe_timeout dependency.
8
28
  * The :log option now accepts either an IO or Logger object.
9
29
  * Updated cert.
10
30
 
11
- == 0.3.2 - 4-Apr-2017
31
+ ## 0.3.2 - 4-Apr-2017
32
+
12
33
  * Fix metadata key names.
13
34
 
14
- == 0.3.1 - 4-Apr-2017
35
+ ## 0.3.1 - 4-Apr-2017
36
+
15
37
  * Added some metadata to the gemspec.
16
38
 
17
- == 0.3.0 - 27-Mar-2017
39
+ ## 0.3.0 - 27-Mar-2017
40
+
18
41
  * The structured_warnings gem requirement was updated to 0.3.0 or later. This
19
42
  is necessary if you are using Ruby 2.4 or later.
20
43
  * The VERSION string is now frozen.
21
44
  * Updated the certs file.
22
45
 
23
- == 0.2.1 - 13-Dec-2015
46
+ ## 0.2.1 - 13-Dec-2015
47
+
24
48
  * This gem is now signed.
25
49
  * Updates to the Rakefile and gemspec.
26
50
  * Added a caveat regarding the timeout module to the README.
27
51
 
28
- == 0.2.0 - 26-Sep-2009
52
+ ## 0.2.0 - 26-Sep-2009
53
+
29
54
  * Now requires and uses the structured_warnings gem. If a block of code fails
30
55
  prior to reaching the maximum number of tries, and warnings are on, then
31
56
  an Attempt::Warning is raised.
@@ -33,16 +58,19 @@
33
58
  * Refactored the attempt.gemspec file a bit.
34
59
  * Added the 'gem' task to the Rakefile.
35
60
 
36
- == 0.1.2 - 1-Aug-2009
61
+ ## 0.1.2 - 1-Aug-2009
62
+
37
63
  * License changed to Artistic 2.0.
38
64
  * Added test-unit as a development dependency.
39
65
  * Test file renamed to more closely follow Ruby style.
40
66
  * Gemspec updates, including addition of license.
41
67
 
42
- == 0.1.1 - 31-Jul-2007
68
+ ## 0.1.1 - 31-Jul-2007
69
+
43
70
  * Added a Rakefile with tasks for testing and installation.
44
71
  * Removed the install.rb file, since installation is now handled by the Rakefile.
45
72
  * Some minor doc updates.
46
73
 
47
- == 0.1.0 - 9-Jun-2006
74
+ ## 0.1.0 - 9-Jun-2006
75
+
48
76
  * Initial commit
data/Gemfile CHANGED
@@ -1,8 +1,2 @@
1
- source 'https://rubygems.org' do
2
- gem 'rake'
3
- gem 'structured_warnings', '~> 0.4.0'
4
- gem 'safe_timeout', '~> 0.0.5'
5
- group 'test' do
6
- gem 'test-unit', '~> 3.0'
7
- end
8
- end
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -1,10 +1,10 @@
1
- * CHANGES
1
+ * CHANGES.md
2
2
  * LICENSE
3
- * MANIFEST
4
- * README
3
+ * MANIFEST.md
4
+ * README.md
5
5
  * Gemfile
6
6
  * Rakefile
7
7
  * attempt.gemspec
8
8
  * certs/djberg96_pub.pem
9
9
  * lib/attempt.rb
10
- * test/test_attempt.rb
10
+ * spec/attempt_spec.rb
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ ## Description
2
+ A thin wrapper for begin + rescue + sleep + retry.
3
+
4
+ ## Installation
5
+ `gem install attempt`
6
+
7
+ ## Adding the trusted cert
8
+ `gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/attempt/main/certs/djberg96_pub.pem)`
9
+
10
+ ## Synopsis
11
+ ```ruby
12
+ require 'attempt'
13
+
14
+ # Attempt to ftp to some host, trying 3 times with 30 seconds between
15
+ # attempts before finally raising an error.
16
+
17
+ attempt(tries: 3, interval: 30){
18
+ Net::FTP.open(host, user, passwd){ ... }
19
+ }
20
+
21
+ # Or, do things the long way...
22
+ code = Attempt.new do |a|
23
+ a.tries = 3
24
+ a.interval = 30
25
+ end
26
+
27
+ code.attempt{
28
+ Net::FTP.open(host, user, passwd){ ... }
29
+ }
30
+ ```
31
+
32
+ ## Known Bugs
33
+ None that I'm aware of. If you find any bugs, please log them on the project page at:
34
+
35
+ https://github.com/djberg96/attempt
36
+
37
+ ## Caveats
38
+ Use with caution. Specifically, make sure you aren't inadvertantly
39
+ wrapping code that already performs sleep + retry. Otherwise, you'll
40
+ end up with a series of nested retry's that could take much longer to
41
+ work than you expect.
42
+
43
+ Also, this library uses the timeout library internally, which has some
44
+ known issues. See Future Plans, below.
45
+
46
+ As of version 0.3.0, this library requires structured_warnings 0.3.0 or
47
+ later. This is necessary because of changes in Ruby 2.4.
48
+
49
+ Update: I've switched from the timeout library in the standard library to
50
+ the safe_timeout library on non-Windows platforms which should improve things.
51
+ In addition, the structured_warnings library requirement is now 0.4.0 or later
52
+ in order to work with Ruby 2.7.
53
+
54
+ ## Future Plans
55
+ Add the ability to set an absolute maximum number of seconds to prevent
56
+ nested sleep/retry from delaying attempts longer than expected.
57
+
58
+ Replace the timeout library with a self selecting pipe if possible.
59
+
60
+ ## Acknowledgements
61
+ This library is partially based on Mark Fowler's 'Attempt' Perl module.
62
+
63
+ ## Warranty
64
+ This package is provided "as is" and without any express or
65
+ implied warranties, including, without limitation, the implied
66
+ warranties of merchantability and fitness for a particular purpose.
67
+
68
+ ## License
69
+ Apache-2.0
70
+
71
+ ## Copyright
72
+ (C) 2006-2022, Daniel J. Berger
73
+ All Rights Reserved
74
+
75
+ ## Author
76
+ Daniel J. Berger
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rake'
2
2
  require 'rake/clean'
3
- require 'rake/testtask'
3
+ require 'rspec/core/rake_task'
4
4
 
5
5
  CLEAN.include('**/*.gem', '**/*.rbc', '**/*.lock')
6
6
 
@@ -8,9 +8,9 @@ namespace :gem do
8
8
  desc 'Build the attempt gem'
9
9
  task :create => [:clean] do
10
10
  require 'rubygems/package'
11
- spec = eval(IO.read('attempt.gemspec'))
11
+ spec = Gem::Specification.load('attempt.gemspec')
12
12
  spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
13
- Gem::Package.build(spec, true)
13
+ Gem::Package.build(spec)
14
14
  end
15
15
 
16
16
  desc "Install the attempt gem"
@@ -20,10 +20,7 @@ namespace :gem do
20
20
  end
21
21
  end
22
22
 
23
- Rake::TestTask.new do |t|
24
- task :test => :clean
25
- t.warning = true
26
- t.verbose = true
27
- end
23
+ desc "Run the test suite"
24
+ RSpec::Core::RakeTask.new(:spec)
28
25
 
29
- task :default => :test
26
+ task :default => :spec
data/attempt.gemspec CHANGED
@@ -2,29 +2,27 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'attempt'
5
- spec.version = '0.5.1'
5
+ spec.version = '0.6.2'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.license = 'Apache-2.0'
8
8
  spec.email = 'djberg96@gmail.com'
9
9
  spec.homepage = 'https://github.com/djberg96/attempt'
10
10
  spec.summary = 'A thin wrapper for begin + rescue + sleep + retry'
11
- spec.test_file = 'test/test_attempt.rb'
11
+ spec.test_file = 'spec/attempt_spec.rb'
12
12
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
13
  spec.cert_chain = Dir['certs/*']
14
14
 
15
- spec.extra_rdoc_files = ['README','CHANGES','MANIFEST']
16
-
17
15
  spec.metadata = {
18
- 'changelog_uri' => 'https://github.com/djberg96/attempt/blob/master/CHANGES',
19
- 'source_code_uri' => 'https://github.com/djberg96/attempt/blob/master/lib/attempt.rb',
16
+ 'changelog_uri' => 'https://github.com/djberg96/attempt/blob/main/CHANGES.md',
17
+ 'source_code_uri' => 'https://github.com/djberg96/attempt/blob/main/lib/attempt.rb',
20
18
  'bug_tracker_uri' => 'https://github.com/djberg96/attempt/issues',
21
19
  'wiki_uri' => 'https://github.com/djberg96/attempt/wiki'
22
20
  }
23
21
 
22
+ spec.add_development_dependency('rake')
24
23
  spec.add_dependency('structured_warnings', '~> 0.4.0')
25
24
  spec.add_dependency('safe_timeout', '~> 0.0.5')
26
-
27
- spec.add_development_dependency('test-unit')
25
+ spec.add_dependency('rspec', '~> 3.9')
28
26
 
29
27
  spec.description = <<-EOF
30
28
  The attempt library provides a thin wrapper for the typical
data/lib/attempt.rb CHANGED
@@ -1,12 +1,18 @@
1
- require 'safe_timeout'
1
+ # frozen_string_literal: true
2
+
3
+ if File::ALT_SEPARATOR
4
+ require 'timeout'
5
+ else
6
+ require 'safe_timeout'
7
+ end
8
+
2
9
  require 'structured_warnings'
3
10
 
4
11
  # The Attempt class encapsulates methods related to multiple attempts at
5
12
  # running the same method before actually failing.
6
13
  class Attempt
7
-
8
14
  # The version of the attempt library.
9
- VERSION = '0.5.1'.freeze
15
+ VERSION = '0.6.2'
10
16
 
11
17
  # Warning raised if an attempt fails before the maximum number of tries
12
18
  # has been reached.
@@ -51,7 +57,7 @@ class Attempt
51
57
  # * warnings - Boolean value that indicates whether or not errors are treated as warnings
52
58
  # until the maximum number of attempts has been made. The default is true.
53
59
  # * timeout - Boolean value to indicate whether or not to automatically wrap your
54
- # proc in a SafeTimeout block. The default is false.
60
+ # proc in a Timeout/SafeTimeout block. The default is false.
55
61
  #
56
62
  # Example:
57
63
  #
@@ -74,18 +80,18 @@ class Attempt
74
80
  # You will not typically use this method directly, but the Kernel#attempt
75
81
  # method instead.
76
82
  #
77
- def attempt
83
+ def attempt(&block)
78
84
  count = 1
79
85
  begin
80
86
  if @timeout
81
- SafeTimeout.timeout(@timeout){ yield }
87
+ File::ALT_SEPARATOR ? Timeout.timeout(@timeout, &block) : SafeTimeout.timeout(@timeout, &block)
82
88
  else
83
89
  yield
84
90
  end
85
- rescue @level => error
91
+ rescue @level => err
86
92
  @tries -= 1
87
93
  if @tries > 0
88
- msg = "Error on attempt # #{count}: #{error}; retrying"
94
+ msg = "Error on attempt # #{count}: #{err}; retrying"
89
95
  count += 1
90
96
  warn Warning, msg if @warnings
91
97
 
@@ -102,30 +108,31 @@ class Attempt
102
108
  end
103
109
  end
104
110
 
111
+ # Extend the Kernel module with a simple interface for the Attempt class.
105
112
  module Kernel
106
- # :call-seq:
107
- # attempt(tries: 3, interval: 60, timeout: 10){ # some op }
108
- #
109
- # Attempt to perform the operation in the provided block up to +tries+
110
- # times, sleeping +interval+ between each try. By default the number
111
- # of tries defaults to 3, the interval defaults to 60 seconds, and there
112
- # is no timeout specified.
113
- #
114
- # If +timeout+ is provided then the operation is wrapped in a Timeout
115
- # block as well. This is handy for those rare occasions when an IO
116
- # connection could hang indefinitely, for example.
117
- #
118
- # If the operation still fails the (last) error is then re-raised.
119
- #
120
- # This is really just a convenient wrapper for Attempt.new + Attempt#attempt.
121
- #
122
- # Example:
123
- #
124
- # # Make 3 attempts to connect to the database, 60 seconds apart.
125
- # attempt{ DBI.connect(dsn, user, passwd) }
126
- #
127
- def attempt(**kwargs, &block)
128
- object = Attempt.new(kwargs)
129
- object.attempt(&block)
130
- end
113
+ # :call-seq:
114
+ # attempt(tries: 3, interval: 60, timeout: 10){ # some op }
115
+ #
116
+ # Attempt to perform the operation in the provided block up to +tries+
117
+ # times, sleeping +interval+ between each try. By default the number
118
+ # of tries defaults to 3, the interval defaults to 60 seconds, and there
119
+ # is no timeout specified.
120
+ #
121
+ # If +timeout+ is provided then the operation is wrapped in a Timeout
122
+ # block as well. This is handy for those rare occasions when an IO
123
+ # connection could hang indefinitely, for example.
124
+ #
125
+ # If the operation still fails the (last) error is then re-raised.
126
+ #
127
+ # This is really just a convenient wrapper for Attempt.new + Attempt#attempt.
128
+ #
129
+ # Example:
130
+ #
131
+ # # Make 3 attempts to connect to the database, 60 seconds apart.
132
+ # attempt{ DBI.connect(dsn, user, passwd) }
133
+ #
134
+ def attempt(**kwargs, &block)
135
+ object = Attempt.new(**kwargs)
136
+ object.attempt(&block)
137
+ end
131
138
  end
@@ -0,0 +1,67 @@
1
+ #####################################################################
2
+ # attempt_spec.rb
3
+ #
4
+ # Tests for the attempt library. You should run this test case via
5
+ # the 'rake test' Rakefile task (or just 'rake').
6
+ #
7
+ # TODO: Test that an Attempt::Warning is raised.
8
+ #####################################################################
9
+ require 'rspec'
10
+ require 'attempt'
11
+ require 'stringio'
12
+
13
+ RSpec.describe Attempt do
14
+ before(:all) do
15
+ $stderr = StringIO.new
16
+ end
17
+
18
+ before do
19
+ @tries = 2
20
+ @interval = 0.1
21
+ @timeout = 0.1
22
+ $value = 0
23
+ end
24
+
25
+ example "version constant is set to expected value" do
26
+ expect(Attempt::VERSION).to eq('0.6.2')
27
+ expect(Attempt::VERSION).to be_frozen
28
+ end
29
+
30
+ example "attempt works as expected without arguments" do
31
+ expect{ attempt{ 2 + 2 } }.not_to raise_error
32
+ end
33
+
34
+ example "attempt retries the number of times specified" do
35
+ expect{ attempt(tries: @tries){ $value += 1; raise if $value < 2 } }.not_to raise_error
36
+ expect($value).to eq(2)
37
+ end
38
+
39
+ example "attempt retries the number of times specified with interval" do
40
+ expect{
41
+ attempt(tries: @tries, interval: @interval){ $value += 1; raise if $value < 2 }
42
+ }.not_to raise_error
43
+ expect($value).to eq(2)
44
+ end
45
+
46
+ example "attempt retries the number of times specified with interval and timeout" do
47
+ expect{
48
+ attempt(tries: @tries, interval: @interval, timeout: @timeout){ $value += 1; raise if $value < 2 }
49
+ }.not_to raise_error
50
+ end
51
+
52
+ example "attempt raises a timeout error if timeout value is exceeded" do
53
+ expect{ attempt(tries: 1, interval: 1, timeout: @timeout){ sleep 5 } }.to raise_error(Timeout::Error)
54
+ end
55
+
56
+ example "attempt raises exception as expected" do
57
+ expect{ attempt(tries: 2, interval: 2){ raise } }.to raise_error(RuntimeError)
58
+ end
59
+
60
+ after do
61
+ $after = 0
62
+ end
63
+
64
+ after(:all) do
65
+ $stderr = STDERR
66
+ end
67
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attempt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -35,8 +35,22 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date:
38
+ date: 2022-06-02 00:00:00.000000000 Z
39
39
  dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: rake
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
40
54
  - !ruby/object:Gem::Dependency
41
55
  name: structured_warnings
42
56
  requirement: !ruby/object:Gem::Requirement
@@ -66,19 +80,19 @@ dependencies:
66
80
  - !ruby/object:Gem::Version
67
81
  version: 0.0.5
68
82
  - !ruby/object:Gem::Dependency
69
- name: test-unit
83
+ name: rspec
70
84
  requirement: !ruby/object:Gem::Requirement
71
85
  requirements:
72
- - - ">="
86
+ - - "~>"
73
87
  - !ruby/object:Gem::Version
74
- version: '0'
75
- type: :development
88
+ version: '3.9'
89
+ type: :runtime
76
90
  prerelease: false
77
91
  version_requirements: !ruby/object:Gem::Requirement
78
92
  requirements:
79
- - - ">="
93
+ - - "~>"
80
94
  - !ruby/object:Gem::Version
81
- version: '0'
95
+ version: '3.9'
82
96
  description: |2
83
97
  The attempt library provides a thin wrapper for the typical
84
98
  begin/rescue/sleep/retry dance. Use this in order to robustly
@@ -88,30 +102,24 @@ description: |2
88
102
  email: djberg96@gmail.com
89
103
  executables: []
90
104
  extensions: []
91
- extra_rdoc_files:
92
- - README
93
- - CHANGES
94
- - MANIFEST
105
+ extra_rdoc_files: []
95
106
  files:
107
+ - CHANGES.md
108
+ - Gemfile
96
109
  - LICENSE
97
- - test
98
- - test/test_attempt.rb
99
- - CHANGES
100
- - MANIFEST
101
- - README
110
+ - MANIFEST.md
111
+ - README.md
102
112
  - Rakefile
103
- - certs
113
+ - attempt.gemspec
104
114
  - certs/djberg96_pub.pem
105
- - lib
106
115
  - lib/attempt.rb
107
- - Gemfile
108
- - attempt.gemspec
116
+ - spec/attempt_spec.rb
109
117
  homepage: https://github.com/djberg96/attempt
110
118
  licenses:
111
119
  - Apache-2.0
112
120
  metadata:
113
- changelog_uri: https://github.com/djberg96/attempt/blob/master/CHANGES
114
- source_code_uri: https://github.com/djberg96/attempt/blob/master/lib/attempt.rb
121
+ changelog_uri: https://github.com/djberg96/attempt/blob/main/CHANGES.md
122
+ source_code_uri: https://github.com/djberg96/attempt/blob/main/lib/attempt.rb
115
123
  bug_tracker_uri: https://github.com/djberg96/attempt/issues
116
124
  wiki_uri: https://github.com/djberg96/attempt/wiki
117
125
  post_install_message:
@@ -129,9 +137,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
137
  - !ruby/object:Gem::Version
130
138
  version: '0'
131
139
  requirements: []
132
- rubygems_version: 3.1.4
140
+ rubygems_version: 3.3.15
133
141
  signing_key:
134
142
  specification_version: 4
135
143
  summary: A thin wrapper for begin + rescue + sleep + retry
136
144
  test_files:
137
- - test/test_attempt.rb
145
+ - spec/attempt_spec.rb
metadata.gz.sig CHANGED
Binary file
data/README DELETED
@@ -1,72 +0,0 @@
1
- == Description
2
- A thin wrapper for begin + rescue + sleep + retry.
3
-
4
- == Installation
5
- gem install attempt
6
-
7
- == Synopsis
8
- require 'attempt'
9
-
10
- # Attempt to ftp to some host, trying 3 times with 30 seconds between
11
- # attempts before finally raising an error.
12
-
13
- attempt(tries: 3, interval: 30){
14
- Net::FTP.open(host, user, passwd){ ... }
15
- }
16
-
17
- # Or, do things the long way...
18
- code = Attempt.new do |a|
19
- a.tries = 3
20
- a.interval = 30
21
- end
22
-
23
- code.attempt{
24
- Net::FTP.open(host, user, passwd){ ... }
25
- }
26
-
27
- == Known Bugs
28
- None that I'm aware of. If you find any bugs, please log them on the
29
- project page at:
30
-
31
- https://github.com/djberg96/attempt
32
-
33
- == Caveats
34
- Use with caution. Specifically, make sure you aren't inadvertantly
35
- wrapping code that already performs sleep + retry. Otherwise, you'll
36
- end up with a series of nested retry's that could take much longer to
37
- work than you expect.
38
-
39
- Also, this library uses the timeout library internally, which has some
40
- known issues. See Future Plans, below.
41
-
42
- As of version 0.3.0, this library requires structured_warnings 0.3.0 or
43
- later. This is necessary because of changes in Ruby 2.4.
44
-
45
- Update: I've switched from the timeout library in the standard library to
46
- the safe_timeout library which should improve things. In addition, the
47
- structured_warnings library requirement is now 0.4.0 or later in order to
48
- work with Ruby 2.7.
49
-
50
- == Future Plans
51
- Add the ability to set an absolute maximum number of seconds to prevent
52
- nested sleep/retry from delaying attempts longer than expected.
53
-
54
- Replace the timeout library with a self selecting pipe if possible.
55
-
56
- == Acknowledgements
57
- This library is partially based on Mark Fowler's 'Attempt' Perl module.
58
-
59
- == Warranty
60
- This package is provided "as is" and without any express or
61
- implied warranties, including, without limitation, the implied
62
- warranties of merchantability and fitness for a particular purpose.
63
-
64
- == License
65
- Artistic 2.0
66
-
67
- == Copyright
68
- (C) 2006-2020, Daniel J. Berger
69
- All Rights Reserved
70
-
71
- == Author
72
- Daniel J. Berger
data/test/test_attempt.rb DELETED
@@ -1,69 +0,0 @@
1
- #####################################################################
2
- # test_attempt.rb
3
- #
4
- # Test case for the attempt library. You should run this test case
5
- # via the 'rake test' Rakefile task.
6
- #
7
- # TODO: Test that an Attempt::Warning is raised.
8
- #####################################################################
9
- require 'test-unit'
10
- require 'attempt'
11
- require 'stringio'
12
-
13
- class TC_Attempt < Test::Unit::TestCase
14
- def self.startup
15
- $stderr = StringIO.new
16
- end
17
-
18
- def setup
19
- @tries = 2
20
- @interval = 0.1
21
- @timeout = 0.1
22
- $value = 0
23
- end
24
-
25
- test "version constant is set to expected value" do
26
- assert_equal('0.5.1', Attempt::VERSION)
27
- assert_true(Attempt::VERSION.frozen?)
28
- end
29
-
30
- test "attempt works as expected without arguments" do
31
- assert_nothing_raised{ attempt{ 2 + 2 } }
32
- end
33
-
34
- test "attempt retries the number of times specified" do
35
- assert_nothing_raised{ attempt(tries: @tries){ $value += 1; raise if $value < 2 } }
36
- assert_equal(2, $value)
37
- end
38
-
39
- test "attempt retries the number of times specified with interval" do
40
- assert_nothing_raised{
41
- attempt(tries: @tries, interval: @interval){ $value += 1; raise if $value < 2 }
42
- }
43
- end
44
-
45
- test "attempt retries the number of times specified with interval and timeout" do
46
- assert_nothing_raised{
47
- attempt(tries: @tries, interval: @interval, timeout: @timeout){ $value += 1; raise if $value < 2 }
48
- }
49
- end
50
-
51
- test "attempt raises a timeout error if timeout value is exceeded" do
52
- assert_raises(Timeout::Error){ attempt(tries: 1, interval: 1, timeout: @timeout){ sleep 5 } }
53
- end
54
-
55
- test "attempt raises exception as expected" do
56
- assert_raises(RuntimeError){ attempt(tries: 2, interval: 2){ raise } }
57
- end
58
-
59
- def teardown
60
- @tries = nil
61
- @interval = nil
62
- @timeout = nil
63
- $value = 0
64
- end
65
-
66
- def self.shutdown
67
- $stderr = STDERR
68
- end
69
- end