timeout-interrupt 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +2 -15
- data/README.md +1 -1
- data/Rakefile +3 -40
- data/lib/timeout_interrupt.rb +7 -23
- data/timeout-interrupt.gemspec +28 -66
- metadata +48 -73
- data/.document +0 -5
- data/Gemfile.lock +0 -52
- data/test/helper.rb +0 -23
- data/test/test_ruby-timeout-interrupt.rb +0 -162
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5392e2634dba25bda8fc76725212aa44a15d2f4162beb60e10a17ee82e655b11
|
4
|
+
data.tar.gz: 07efedfea6f6aa995f6b239b2960d8da07d1845769580ed3853fa60397ea1842
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 734548b8dc8e64227e1efa5dfdbe4b9b95cb86ae47dd0d1aad87ec50575f5706319d50df2c57e362c2517efc35c17797379a37cc4ab283cf8a43ecf3569e65e0
|
7
|
+
data.tar.gz: 6b2f7432900414d2b19276251deb5932ade594adb8b39cabba62c17017e49f1052119efff231b625fd5d6c711982ae805fde0812c61163c7c18ead8e62e34836
|
data/.gitignore
ADDED
data/Gemfile
CHANGED
@@ -1,15 +1,2 @@
|
|
1
|
-
source "
|
2
|
-
|
3
|
-
gem 'ffi-libc'
|
4
|
-
|
5
|
-
# Add dependencies to develop your gem here.
|
6
|
-
# Include everything needed to run rake, tests, features, etc.
|
7
|
-
group :development do
|
8
|
-
gem "shoulda"
|
9
|
-
gem "yard"
|
10
|
-
gem "redcarpet"
|
11
|
-
gem "rdoc"
|
12
|
-
gem "bundler"
|
13
|
-
gem "jeweler"
|
14
|
-
gem "simplecov"
|
15
|
-
end
|
1
|
+
source "https://rubygems.org"
|
2
|
+
gemspec
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,46 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "timeout-interrupt"
|
18
|
-
gem.homepage = "http://github.com/DenisKnauf/ruby-timeout-interrupt"
|
19
|
-
gem.license = "LGPLv3"
|
20
|
-
gem.summary = %Q{"Interrupts systemcalls too."}
|
21
|
-
gem.description = %Q{Timeout-lib, which interrupts everything, also systemcalls. It uses libc-alarm.}
|
22
|
-
gem.email = "Denis.Knauf@gmail.com"
|
23
|
-
gem.authors = ["Denis Knauf"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
task :default => :spec
|
27
3
|
|
28
4
|
require 'rake/testtask'
|
29
|
-
Rake::TestTask.new
|
5
|
+
Rake::TestTask.new :test do |test|
|
30
6
|
test.libs << 'lib' << 'test'
|
31
7
|
test.pattern = 'test/**/test_*.rb'
|
32
8
|
test.verbose = true
|
33
9
|
end
|
34
|
-
|
35
|
-
#require 'simplecov'
|
36
|
-
#Rcov::RcovTask.new do |test|
|
37
|
-
#test.libs << 'test'
|
38
|
-
#test.pattern = 'test/**/test_*.rb'
|
39
|
-
#test.verbose = true
|
40
|
-
#test.rcov_opts << '--exclude "gems/*"'
|
41
|
-
#end
|
42
|
-
|
43
|
-
task :default => :test
|
44
|
-
|
45
|
-
require 'yard'
|
46
|
-
YARD::Rake::YardocTask.new
|
data/lib/timeout_interrupt.rb
CHANGED
@@ -1,23 +1,6 @@
|
|
1
1
|
require 'ffi/libc'
|
2
2
|
require 'timeout'
|
3
3
|
|
4
|
-
# Provided by ffi-libc-lib and extended by this library, if needed.
|
5
|
-
# Older version of ffi-libc does not provide {FFI::LibC.alarm}
|
6
|
-
module FFI
|
7
|
-
module LibC
|
8
|
-
# @!method alarm(seconds)
|
9
|
-
# Sets an alarm. After `seconds` it will send an ALRM-signal to this process.
|
10
|
-
#
|
11
|
-
# Predefined alarm will be reset and will forget.
|
12
|
-
# @note Older implementations of ffi-libc does not provide {alarm}, but we need it.
|
13
|
-
# So we detect, if it is not provided and attach it.
|
14
|
-
# @param seconds [0] Clears alarm.
|
15
|
-
# @param seconds [Integer] How many seconds should be waited, before ALRM-signal should be send?
|
16
|
-
# @return (nil)
|
17
|
-
attach_function :alarm, [:uint], :uint unless FFI::LibC.respond_to? :alarm
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
4
|
# Helper module for `TimeoutInterrupt`
|
22
5
|
# @see TimeoutInterrupt
|
23
6
|
module TimeoutInterruptSingleton
|
@@ -51,7 +34,7 @@ module TimeoutInterruptSingleton
|
|
51
34
|
# @return [nil]
|
52
35
|
def raise_if_sb_timed_out
|
53
36
|
return if self.timeouts.empty?
|
54
|
-
|
37
|
+
_key, (at, bt, exception) = self.timeouts.min_by {|_key,(at,_bt,_ex)| at }
|
55
38
|
return if Time.now < at
|
56
39
|
raise exception, 'execution expired', bt
|
57
40
|
end
|
@@ -66,7 +49,7 @@ module TimeoutInterruptSingleton
|
|
66
49
|
else
|
67
50
|
raise_if_sb_timed_out
|
68
51
|
Signal.trap 'ALRM', &method( :alarm_trap)
|
69
|
-
|
52
|
+
_key, (at, _bt) = timeouts.min_by {|_key,(at,_bt)| at }
|
70
53
|
FFI::LibC.alarm (at - Time.now).to_i + 1
|
71
54
|
end
|
72
55
|
nil
|
@@ -76,9 +59,9 @@ module TimeoutInterruptSingleton
|
|
76
59
|
#
|
77
60
|
# @param seconds [0] No timeout, so block can take any time.
|
78
61
|
# @param seconds [Integer] In `seconds` Seconds, it should raise a timeout, if not finished.
|
79
|
-
# @param seconds [nil] If
|
80
|
-
#
|
81
|
-
# @param exception [
|
62
|
+
# @param seconds [nil] If this and no block given, it will call {setup} for checking and
|
63
|
+
# preparing _next_ known timeout.
|
64
|
+
# @param exception [exception] which exception will be raised if timed out?
|
82
65
|
# @param exception [nil] `TimeoutInterrupt::Error` will be used to raise.
|
83
66
|
# @param block [Proc] Will be called and should finish its work before it timed out.
|
84
67
|
# @param block [nil] Nothing will happen, instead it will return a Proc,
|
@@ -87,7 +70,8 @@ module TimeoutInterruptSingleton
|
|
87
70
|
# Or if not, it will return a Proc, which will expect a Proc if called.
|
88
71
|
# This Proc has no arguments and will prepare a timeout, like if you had given a block.
|
89
72
|
#
|
90
|
-
# You can rescue `Timeout::Error`, instead `TimeoutInterrupt::Error`,
|
73
|
+
# You can rescue `Timeout::Error`, instead `TimeoutInterrupt::Error`,
|
74
|
+
# it is a subclass of `Timeout::Error`.
|
91
75
|
#
|
92
76
|
# It will call your given block, which has `seconds` seconds to end.
|
93
77
|
# If you want to prepare a timeout, which should be used many times,
|
data/timeout-interrupt.gemspec
CHANGED
@@ -1,71 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "timeout-interrupt"
|
3
|
+
spec.version = "0.4.0"
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
spec.authors = ["Denis Knauf"]
|
6
|
+
spec.description = "Timeout-lib, which interrupts everything, also systemcalls. It uses libc-alarm."
|
7
|
+
spec.email = ["git+timeout-interrupt@denkn.at"]
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
s.date = "2013-03-14"
|
13
|
-
s.description = "Timeout-lib, which interrupts everything, also systemcalls. It uses libc-alarm."
|
14
|
-
s.email = "Denis.Knauf@gmail.com"
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE.txt",
|
17
|
-
"README.md"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
"Gemfile",
|
22
|
-
"Gemfile.lock",
|
23
|
-
"LICENSE.txt",
|
24
|
-
"README.md",
|
25
|
-
"Rakefile",
|
26
|
-
"VERSION",
|
27
|
-
"lib/timeout_interrupt.rb",
|
28
|
-
"test/helper.rb",
|
29
|
-
"test/test_ruby-timeout-interrupt.rb",
|
30
|
-
"timeout-interrupt.gemspec"
|
31
|
-
]
|
32
|
-
s.homepage = "http://github.com/DenisKnauf/ruby-timeout-interrupt"
|
33
|
-
s.licenses = ["LGPLv3"]
|
34
|
-
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version = "1.8.11"
|
36
|
-
s.summary = "\"Interrupts systemcalls too.\""
|
9
|
+
spec.summary = "\"Interrupts systemcalls too.\""
|
10
|
+
spec.licenses = ["LGPLv3"]
|
37
11
|
|
38
|
-
|
39
|
-
|
12
|
+
spec.homepage = "https://git.denkn.at/deac/ruby-timeout-interrupt"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.1.0")
|
40
14
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
54
|
-
s.add_dependency(%q<redcarpet>, [">= 0"])
|
55
|
-
s.add_dependency(%q<rdoc>, [">= 0"])
|
56
|
-
s.add_dependency(%q<bundler>, [">= 0"])
|
57
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
58
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
59
|
-
end
|
60
|
-
else
|
61
|
-
s.add_dependency(%q<ffi-libc>, [">= 0"])
|
62
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
63
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
64
|
-
s.add_dependency(%q<redcarpet>, [">= 0"])
|
65
|
-
s.add_dependency(%q<rdoc>, [">= 0"])
|
66
|
-
s.add_dependency(%q<bundler>, [">= 0"])
|
67
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
68
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
69
|
-
end
|
70
|
-
end
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
17
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "bin"
|
25
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
71
27
|
|
28
|
+
spec.add_runtime_dependency 'ffi-libc', '>= 0.1.1'
|
29
|
+
spec.add_development_dependency 'test-unit'
|
30
|
+
spec.add_development_dependency 'shoulda'
|
31
|
+
spec.add_development_dependency 'rake'
|
32
|
+
spec.add_development_dependency 'bundler'
|
33
|
+
end
|
metadata
CHANGED
@@ -1,149 +1,124 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timeout-interrupt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Denis Knauf
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-12-12 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: ffi-libc
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 0.1.1
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.1
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement:
|
28
|
-
none: false
|
28
|
+
name: test-unit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: yard
|
38
|
-
requirement: &75104250 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
|
-
- -
|
38
|
+
- - ">="
|
42
39
|
- !ruby/object:Gem::Version
|
43
40
|
version: '0'
|
44
|
-
type: :development
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *75104250
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
49
|
-
requirement:
|
50
|
-
none: false
|
42
|
+
name: shoulda
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
51
44
|
requirements:
|
52
|
-
- -
|
45
|
+
- - ">="
|
53
46
|
- !ruby/object:Gem::Version
|
54
47
|
version: '0'
|
55
48
|
type: :development
|
56
49
|
prerelease: false
|
57
|
-
version_requirements:
|
58
|
-
- !ruby/object:Gem::Dependency
|
59
|
-
name: rdoc
|
60
|
-
requirement: &75103530 !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
62
51
|
requirements:
|
63
|
-
- -
|
52
|
+
- - ">="
|
64
53
|
- !ruby/object:Gem::Version
|
65
54
|
version: '0'
|
66
|
-
type: :development
|
67
|
-
prerelease: false
|
68
|
-
version_requirements: *75103530
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
-
requirement:
|
72
|
-
none: false
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
73
58
|
requirements:
|
74
|
-
- -
|
59
|
+
- - ">="
|
75
60
|
- !ruby/object:Gem::Version
|
76
61
|
version: '0'
|
77
62
|
type: :development
|
78
63
|
prerelease: false
|
79
|
-
version_requirements:
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
name: jeweler
|
82
|
-
requirement: &75102780 !ruby/object:Gem::Requirement
|
83
|
-
none: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
84
65
|
requirements:
|
85
|
-
- -
|
66
|
+
- - ">="
|
86
67
|
- !ruby/object:Gem::Version
|
87
68
|
version: '0'
|
88
|
-
type: :development
|
89
|
-
prerelease: false
|
90
|
-
version_requirements: *75102780
|
91
69
|
- !ruby/object:Gem::Dependency
|
92
|
-
name:
|
93
|
-
requirement:
|
94
|
-
none: false
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
95
72
|
requirements:
|
96
|
-
- -
|
73
|
+
- - ">="
|
97
74
|
- !ruby/object:Gem::Version
|
98
75
|
version: '0'
|
99
76
|
type: :development
|
100
77
|
prerelease: false
|
101
|
-
version_requirements:
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
102
83
|
description: Timeout-lib, which interrupts everything, also systemcalls. It uses libc-alarm.
|
103
|
-
email:
|
84
|
+
email:
|
85
|
+
- git+timeout-interrupt@denkn.at
|
104
86
|
executables: []
|
105
87
|
extensions: []
|
106
|
-
extra_rdoc_files:
|
107
|
-
- LICENSE.txt
|
108
|
-
- README.md
|
88
|
+
extra_rdoc_files: []
|
109
89
|
files:
|
110
|
-
- .
|
90
|
+
- ".gitignore"
|
111
91
|
- Gemfile
|
112
|
-
- Gemfile.lock
|
113
92
|
- LICENSE.txt
|
114
93
|
- README.md
|
115
94
|
- Rakefile
|
116
95
|
- VERSION
|
117
96
|
- lib/timeout_interrupt.rb
|
118
|
-
- test/helper.rb
|
119
|
-
- test/test_ruby-timeout-interrupt.rb
|
120
97
|
- timeout-interrupt.gemspec
|
121
|
-
homepage:
|
98
|
+
homepage: https://git.denkn.at/deac/ruby-timeout-interrupt
|
122
99
|
licenses:
|
123
100
|
- LGPLv3
|
101
|
+
metadata:
|
102
|
+
homepage_uri: https://git.denkn.at/deac/ruby-timeout-interrupt
|
103
|
+
source_code_uri: https://git.denkn.at/deac/ruby-timeout-interrupt
|
104
|
+
changelog_uri: https://git.denkn.at/deac/ruby-timeout-interrupt
|
124
105
|
post_install_message:
|
125
106
|
rdoc_options: []
|
126
107
|
require_paths:
|
127
108
|
- lib
|
128
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
110
|
requirements:
|
131
|
-
- -
|
111
|
+
- - ">="
|
132
112
|
- !ruby/object:Gem::Version
|
133
|
-
version:
|
134
|
-
segments:
|
135
|
-
- 0
|
136
|
-
hash: -714401361
|
113
|
+
version: 2.1.0
|
137
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
-
none: false
|
139
115
|
requirements:
|
140
|
-
- -
|
116
|
+
- - ">="
|
141
117
|
- !ruby/object:Gem::Version
|
142
118
|
version: '0'
|
143
119
|
requirements: []
|
144
|
-
|
145
|
-
rubygems_version: 1.8.11
|
120
|
+
rubygems_version: 3.1.2
|
146
121
|
signing_key:
|
147
|
-
specification_version:
|
148
|
-
summary:
|
122
|
+
specification_version: 4
|
123
|
+
summary: '"Interrupts systemcalls too."'
|
149
124
|
test_files: []
|
data/.document
DELETED
data/Gemfile.lock
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activesupport (3.2.12)
|
5
|
-
i18n (~> 0.6)
|
6
|
-
multi_json (~> 1.0)
|
7
|
-
bourne (1.1.2)
|
8
|
-
mocha (= 0.10.5)
|
9
|
-
ffi (1.1.0)
|
10
|
-
ffi-libc (0.0.5)
|
11
|
-
ffi (>= 0.6.0, <= 1.1.0)
|
12
|
-
git (1.2.5)
|
13
|
-
i18n (0.6.4)
|
14
|
-
jeweler (1.8.4)
|
15
|
-
bundler (~> 1.0)
|
16
|
-
git (>= 1.2.5)
|
17
|
-
rake
|
18
|
-
rdoc
|
19
|
-
json (1.7.7)
|
20
|
-
metaclass (0.0.1)
|
21
|
-
mocha (0.10.5)
|
22
|
-
metaclass (~> 0.0.1)
|
23
|
-
multi_json (1.6.1)
|
24
|
-
rake (10.0.3)
|
25
|
-
rdoc (4.0.0)
|
26
|
-
json (~> 1.4)
|
27
|
-
redcarpet (2.2.2)
|
28
|
-
shoulda (3.3.2)
|
29
|
-
shoulda-context (~> 1.0.1)
|
30
|
-
shoulda-matchers (~> 1.4.1)
|
31
|
-
shoulda-context (1.0.2)
|
32
|
-
shoulda-matchers (1.4.2)
|
33
|
-
activesupport (>= 3.0.0)
|
34
|
-
bourne (~> 1.1.2)
|
35
|
-
simplecov (0.7.1)
|
36
|
-
multi_json (~> 1.0)
|
37
|
-
simplecov-html (~> 0.7.1)
|
38
|
-
simplecov-html (0.7.1)
|
39
|
-
yard (0.8.5.2)
|
40
|
-
|
41
|
-
PLATFORMS
|
42
|
-
ruby
|
43
|
-
|
44
|
-
DEPENDENCIES
|
45
|
-
bundler
|
46
|
-
ffi-libc
|
47
|
-
jeweler
|
48
|
-
rdoc
|
49
|
-
redcarpet
|
50
|
-
shoulda
|
51
|
-
simplecov
|
52
|
-
yard
|
data/test/helper.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
|
-
|
13
|
-
require 'timeout'
|
14
|
-
require 'benchmark'
|
15
|
-
require 'ffi/libc'
|
16
|
-
|
17
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
|
-
|
20
|
-
require 'timeout_interrupt'
|
21
|
-
|
22
|
-
class Test::Unit::TestCase
|
23
|
-
end
|
@@ -1,162 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestRubyTimeoutInterrupt < Test::Unit::TestCase
|
4
|
-
def blocking
|
5
|
-
t = FFI::LibC.fopen '/dev/ptmx', 'r'
|
6
|
-
b = FFI::LibC.malloc 1025
|
7
|
-
s = FFI::LibC.fread b, 1, 1024, t
|
8
|
-
ensure
|
9
|
-
FFI::LibC.fclose t if t
|
10
|
-
FFI::LibC.free b if b
|
11
|
-
end
|
12
|
-
|
13
|
-
def assert_no_defined_timeout_yet
|
14
|
-
assert TimeoutInterruptSingleton.timeouts.empty?, "For testing, no timeout should be defined, yet!"
|
15
|
-
end
|
16
|
-
|
17
|
-
def print_timeouts pre
|
18
|
-
puts "#{pre}: < #{TimeoutInterruptSingleton.timeouts.map {|k,(a,_b,_e)| "#{k.inspect}: #{a.strftime '%H:%M:%S'} (#{a-Time.now})" }.join ', '} >"
|
19
|
-
end
|
20
|
-
|
21
|
-
# For testing raising scoped Timeout.
|
22
|
-
class TimeoutError < Exception
|
23
|
-
end
|
24
|
-
# For testing raising scoped TimeoutInterrupt.
|
25
|
-
class TimeoutInterruptError < Exception
|
26
|
-
end
|
27
|
-
|
28
|
-
context "Long really blocking calls" do
|
29
|
-
should "not be interrupted by the old Timeout" do
|
30
|
-
time = Benchmark.realtime do
|
31
|
-
assert_nothing_raised TimeoutError, "Unexpected time out. Your Ruby implementation can time out with old Timeout? You need not TimeoutInterrupt. But it is ok. You can ignore this Error. :)" do
|
32
|
-
assert_raise TimeoutInterruptError, "Ohoh. TimeoutInterrupt should be raised." do
|
33
|
-
TimeoutInterrupt.timeout 5, TimeoutInterruptError do
|
34
|
-
Timeout.timeout 1, TimeoutError do
|
35
|
-
blocking
|
36
|
-
assert false, "Should be unreachable!"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
assert 3 < time, "Did timeout!"
|
43
|
-
end
|
44
|
-
|
45
|
-
should "be interrupted by the new TimeoutInterrupt" do
|
46
|
-
time = Benchmark.realtime do
|
47
|
-
assert_raise TimeoutInterrupt::Error, "It should be timed out, why it did not raise TimeoutInterrupt::Error?" do
|
48
|
-
TimeoutInterrupt.timeout 1 do
|
49
|
-
blocking
|
50
|
-
assert false, "Should be unreachable!"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
assert 3 > time, "Did not interrupt."
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
should "interrupt scoped timeout, but not time out the outer timeout" do
|
59
|
-
assert_no_defined_timeout_yet
|
60
|
-
assert_raise TimeoutInterruptError, "It should be timed out, why it did not raise TimeoutInterruptError?" do
|
61
|
-
assert_nothing_raised Timeout::Error, "Oh, outer timeout was timed out. Your machine must be slow, or there is a bug" do
|
62
|
-
TimeoutInterrupt.timeout 10 do
|
63
|
-
TimeoutInterrupt.timeout 1, TimeoutInterruptError do
|
64
|
-
Kernel.sleep 2
|
65
|
-
end
|
66
|
-
assert false, "Should be unreachable!"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
assert TimeoutInterruptSingleton.timeouts.empty?, "There are timeouts defined, yet!"
|
71
|
-
end
|
72
|
-
|
73
|
-
should "clear timeouts, if not timed out, too." do
|
74
|
-
assert_no_defined_timeout_yet
|
75
|
-
TimeoutInterrupt.timeout(10) {}
|
76
|
-
assert TimeoutInterruptSingleton.timeouts.empty?, "There are timeouts defined, yet!"
|
77
|
-
end
|
78
|
-
|
79
|
-
class CustomException <Exception
|
80
|
-
end
|
81
|
-
|
82
|
-
should "raise custom exception." do
|
83
|
-
assert_raise CustomException, "Custom exceptions do not work." do
|
84
|
-
TimeoutInterrupt.timeout 1, CustomException do
|
85
|
-
sleep 2
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context "A prepared timeout (Proc)" do
|
91
|
-
should "be returned by calling timeout without a block" do
|
92
|
-
assert_no_defined_timeout_yet
|
93
|
-
assert TimeoutInterrupt.timeout(10).kind_of?( Proc), "Did not return a Proc."
|
94
|
-
end
|
95
|
-
|
96
|
-
should "run with once given timeout" do
|
97
|
-
assert_no_defined_timeout_yet
|
98
|
-
to = TimeoutInterrupt.timeout 10
|
99
|
-
called = false
|
100
|
-
to.call { called = true }
|
101
|
-
assert called, "Did not called."
|
102
|
-
end
|
103
|
-
|
104
|
-
should "raise custom exception" do
|
105
|
-
assert_raise CustomException, "Custom exceptions do not work." do
|
106
|
-
prepared = TimeoutInterrupt.timeout 1, CustomException
|
107
|
-
prepared.call { sleep 2 }
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
should "not be scopeable, without manualy setup after rescue and 2 time outs at once" do
|
112
|
-
prepared = TimeoutInterrupt.timeout 1
|
113
|
-
assert_no_defined_timeout_yet
|
114
|
-
called = false
|
115
|
-
prepared.call do
|
116
|
-
assert_raise TimeoutInterrupt::Error, 'It should time out after one second, but it did not.' do
|
117
|
-
prepared.call { 2; sleep 2 }
|
118
|
-
end
|
119
|
-
called = true
|
120
|
-
end
|
121
|
-
assert called, "It's true, it should be called, also if not expected."
|
122
|
-
end
|
123
|
-
|
124
|
-
should "be scopeable, with manualy setup after rescue, also if 2 time outs at once." do
|
125
|
-
prepared = TimeoutInterrupt.timeout 1
|
126
|
-
assert_no_defined_timeout_yet
|
127
|
-
prepared.call do
|
128
|
-
assert_raise TimeoutInterrupt::Error, 'It should time out after one second, but it did not.' do
|
129
|
-
prepared.call { sleep 2 }
|
130
|
-
end
|
131
|
-
assert_raise TimeoutInterrupt::Error, 'Manualy called timeout setup did not raise.' do
|
132
|
-
TimeoutInterrupt.timeout
|
133
|
-
end
|
134
|
-
assert true, "Should never be reached."
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
class IncludeModuleTest
|
140
|
-
include TimeoutInterrupt
|
141
|
-
def please_timeout after
|
142
|
-
timeout after do
|
143
|
-
sleep after+10
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
context "Included module" do
|
149
|
-
should "provide timeout too" do
|
150
|
-
assert_raise TimeoutInterrupt::Error, "Included timeout can not be used?" do
|
151
|
-
IncludeModuleTest.new.please_timeout 2
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
should "not timeout, if timeout is 0" do
|
157
|
-
assert_nothing_raised TimeoutInterrupt::Error, "Unexpected Timed out." do
|
158
|
-
# should never timeout (we can not wait infinity seconds, so only 5)
|
159
|
-
TimeoutInterrupt.timeout( 0) { sleep 5 }
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|