kametori 0.0.1 → 0.0.2
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.
- data/lib/kametori/version.rb +1 -1
- data/lib/kametori.rb +33 -1
- metadata +1 -1
data/lib/kametori/version.rb
CHANGED
data/lib/kametori.rb
CHANGED
@@ -1,5 +1,37 @@
|
|
1
1
|
require "kametori/version"
|
2
2
|
|
3
3
|
module Kametori
|
4
|
-
#
|
4
|
+
# exception classes
|
5
|
+
class Error < RuntimeError
|
6
|
+
end
|
7
|
+
class Timeout < RuntimeError
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def limits=(limits)
|
13
|
+
raise Error if !limits.is_a? Array
|
14
|
+
@limits = limits
|
15
|
+
end
|
16
|
+
|
17
|
+
def limits
|
18
|
+
@limits
|
19
|
+
end
|
20
|
+
|
21
|
+
def benchmark_scenario(scenario, options={})
|
22
|
+
under_test = @limits.find{ |limit| limit[:tag] == scenario.tag}
|
23
|
+
return nil if under_test.nil?
|
24
|
+
before = Time.now
|
25
|
+
yield if block_given?
|
26
|
+
after = Time.now
|
27
|
+
elapsed = after - before
|
28
|
+
if options[:raise]
|
29
|
+
if ( elapsed > under_test[:limit])
|
30
|
+
raise Timeout
|
31
|
+
end
|
32
|
+
end
|
33
|
+
elapsed
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
5
37
|
end
|