glutton_ratelimit 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,20 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
-
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- require 'glutton_ratelimit'
7
-
8
- class Test::Unit::TestCase
9
- end
10
-
11
- def timed_run ratelimiter, passes = 1
12
- before_last_invocation = 0
13
- start_time = Time.now
14
- (passes * ratelimiter.executions + 1).times do |n|
15
- ratelimiter.wait
16
- before_last_invocation = Time.now
17
- yield
18
- end
19
- before_last_invocation - start_time
20
- end
21
-
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'glutton_ratelimit'
7
+
8
+ class Test::Unit::TestCase
9
+ end
10
+
11
+ def timed_run ratelimiter, passes = 1
12
+ before_last_invocation = 0
13
+ start_time = Time.now
14
+ ratelimiter.times(passes * ratelimiter.executions + 1) do
15
+ before_last_invocation = Time.now
16
+ yield
17
+ end
18
+ before_last_invocation - start_time
19
+ end
20
+
@@ -1,15 +1,15 @@
1
- require 'helper'
2
- require 'testing_module.rb'
3
-
4
- class TestGluttonRatelimitAveragedThrottle < Test::Unit::TestCase
5
- include TestingModule
6
-
7
- def setup
8
- @testClass = GluttonRatelimit::AveragedThrottle
9
- end
10
-
11
- def test_object_creations
12
- rl = @testClass.new 1, 1
13
- assert_instance_of GluttonRatelimit::AveragedThrottle, rl
14
- end
15
- end
1
+ require 'helper'
2
+ require 'testing_module.rb'
3
+
4
+ class TestGluttonRatelimitAveragedThrottle < Test::Unit::TestCase
5
+ include TestingModule
6
+
7
+ def setup
8
+ @testClass = GluttonRatelimit::AveragedThrottle
9
+ end
10
+
11
+ def test_object_creations
12
+ rl = @testClass.new 1, 1
13
+ assert_instance_of GluttonRatelimit::AveragedThrottle, rl
14
+ end
15
+ end
@@ -1,15 +1,15 @@
1
- require 'helper'
2
- require 'testing_module.rb'
3
-
4
- class TestGluttonRatelimitBurstyRingBuffer < Test::Unit::TestCase
5
- include TestingModule
6
-
7
- def setup
8
- @testClass = GluttonRatelimit::BurstyRingBuffer
9
- end
10
-
11
- def test_object_creations
12
- rl = @testClass.new 1, 1
13
- assert_instance_of GluttonRatelimit::BurstyRingBuffer, rl
14
- end
15
- end
1
+ require 'helper'
2
+ require 'testing_module.rb'
3
+
4
+ class TestGluttonRatelimitBurstyRingBuffer < Test::Unit::TestCase
5
+ include TestingModule
6
+
7
+ def setup
8
+ @testClass = GluttonRatelimit::BurstyRingBuffer
9
+ end
10
+
11
+ def test_object_creations
12
+ rl = @testClass.new 1, 1
13
+ assert_instance_of GluttonRatelimit::BurstyRingBuffer, rl
14
+ end
15
+ end
@@ -1,15 +1,15 @@
1
- require 'helper'
2
- require 'testing_module.rb'
3
-
4
- class TestGluttonRatelimitBurtyTokenBucket < Test::Unit::TestCase
5
- include TestingModule
6
-
7
- def setup
8
- @testClass = GluttonRatelimit::BurstyTokenBucket
9
- end
10
-
11
- def test_object_creations
12
- rl = @testClass.new 1, 1
13
- assert_instance_of GluttonRatelimit::BurstyTokenBucket, rl
14
- end
15
- end
1
+ require 'helper'
2
+ require 'testing_module.rb'
3
+
4
+ class TestGluttonRatelimitBurtyTokenBucket < Test::Unit::TestCase
5
+ include TestingModule
6
+
7
+ def setup
8
+ @testClass = GluttonRatelimit::BurstyTokenBucket
9
+ end
10
+
11
+ def test_object_creations
12
+ rl = @testClass.new 1, 1
13
+ assert_instance_of GluttonRatelimit::BurstyTokenBucket, rl
14
+ end
15
+ end
@@ -1,67 +1,69 @@
1
- module TestingModule
2
- # This module assumes use as a mixin within
3
- # a test class which defines @testClass.
4
-
5
- def test_120_tasks_every_second_with_ms_task
6
- min_time = 1
7
- rl = @testClass.new 120, min_time
8
- delta = timed_run(rl) { sleep 0.001 }
9
- #puts "#{delta} >? #{min_time}"
10
- assert delta > min_time
11
- end
12
-
13
- def test_120_tasks_every_quarter_second_with_ms_task
14
- min_time = 0.25
15
- rl = @testClass.new 120, min_time
16
- delta = timed_run(rl) { sleep 0.001 }
17
- #puts "#{delta} >? #{min_time}"
18
- assert delta > min_time
19
- end
20
-
21
- def test_120_tasks_every_second_with_cenisecond_task
22
- min_time = 1
23
- rl = @testClass.new 120, min_time
24
- delta = timed_run(rl) { sleep 0.01 }
25
- #puts "#{delta} >? #{min_time}"
26
- assert delta > min_time
27
- end
28
-
29
- def test_50_tasks_every_second_with_fast_task
30
- min_time = 1
31
- rl = @testClass.new 50, min_time
32
- delta = timed_run(rl) { sleep 0 }
33
- #puts "#{delta} >? #{min_time}"
34
- assert delta > min_time
35
- end
36
-
37
- def test_1_task_every_1_seconds_with_1_second_task
38
- min_time = 1
39
- rl = @testClass.new 1, min_time
40
- delta = timed_run(rl) { sleep 1 }
41
- #puts "#{delta} >? #{min_time}"
42
- assert delta > min_time
43
- end
44
-
45
- def test_5_tasks_every_quarter_second_four_runs_with_ms_task
46
- min_time = 0.25
47
- rl = @testClass.new 1, min_time
48
- delta = timed_run(rl, 4) { sleep 0.001 }
49
- #puts "#{delta} >? #{min_time}"
50
- assert delta > min_time * 4
51
- end
52
-
53
- def test_120_tasks_every_half_second_two_runs_with_no_task
54
- min_time = 0.5
55
- rl = @testClass.new 120, min_time
56
- delta = timed_run(rl, 2) { sleep 0 }
57
- assert delta > min_time * 2
58
- end
59
-
60
- def test_10_tasks_every_1_seconds_two_runs_with_short_rnd_task
61
- min_time = 1
62
- rl = @testClass.new 10, min_time
63
- delta = timed_run(rl, 2) { sleep(0.2 * rand) }
64
- assert delta > min_time * 2
65
- end
66
-
67
- end
1
+ module TestingModule
2
+ # This module assumes use as a mixin within
3
+ # a test class which defines @testClass.
4
+
5
+ def test_120_tasks_every_second_with_ms_task
6
+ min_time = 1
7
+ rl = @testClass.new 120, min_time
8
+ delta = timed_run(rl) { sleep 0.001 }
9
+ #puts "#{delta} >? #{min_time}"
10
+ assert delta >= min_time
11
+ end
12
+
13
+ def test_120_tasks_every_quarter_second_with_ms_task
14
+ min_time = 0.25
15
+ rl = @testClass.new 120, min_time
16
+ delta = timed_run(rl) { sleep 0.001 }
17
+ #puts "#{delta} >? #{min_time}"
18
+ assert delta >= min_time
19
+ end
20
+
21
+ def test_120_tasks_every_second_with_cenisecond_task
22
+ min_time = 1
23
+ rl = @testClass.new 120, min_time
24
+ delta = timed_run(rl) { sleep 0.01 }
25
+ #puts "#{delta} >? #{min_time}"
26
+ assert delta >= min_time
27
+ end
28
+
29
+ def test_50_tasks_every_second_with_no_task
30
+ min_time = 1
31
+ rl = @testClass.new 50, min_time
32
+ delta = timed_run(rl) { sleep 0 }
33
+ #puts "#{delta} >? #{min_time}"
34
+ # Allowed to be off by 0.5% since there is no task time.
35
+ assert((delta / min_time) > 0.995)
36
+ end
37
+
38
+ def test_1_task_every_1_seconds_with_1_second_task
39
+ min_time = 1
40
+ rl = @testClass.new 1, min_time
41
+ delta = timed_run(rl) { sleep 1 }
42
+ #puts "#{delta} >? #{min_time}"
43
+ assert delta >= min_time
44
+ end
45
+
46
+ def test_5_tasks_every_quarter_second_four_runs_with_ms_task
47
+ min_time = 0.25
48
+ rl = @testClass.new 1, min_time
49
+ delta = timed_run(rl, 4) { sleep 0.001 }
50
+ #puts "#{delta} >? #{min_time}"
51
+ assert delta >= min_time * 4
52
+ end
53
+
54
+ def test_120_tasks_every_half_second_two_runs_with_no_task
55
+ min_time = 0.5
56
+ rl = @testClass.new 120, min_time
57
+ delta = timed_run(rl, 2) { sleep 0 }
58
+ # Allowed to be off by 0.5% since there is no task time.
59
+ assert((delta / (min_time * 2)) > 0.995)
60
+ end
61
+
62
+ def test_10_tasks_every_1_seconds_two_runs_with_short_rnd_task
63
+ min_time = 1
64
+ rl = @testClass.new 10, min_time
65
+ delta = timed_run(rl, 2) { sleep(0.2 * rand) }
66
+ assert delta >= min_time * 2
67
+ end
68
+
69
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glutton_ratelimit
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 23
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 1
8
+ - 2
8
9
  - 0
9
- version: 0.1.0
10
+ version: 0.2.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Wally Glutton
@@ -14,8 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-10 00:00:00 -05:00
18
- default_executable:
18
+ date: 2011-06-30 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: A Ruby library for limiting the number of times a method can be invoked within a specified time period.
@@ -29,7 +29,6 @@ extra_rdoc_files:
29
29
  - README.rdoc
30
30
  files:
31
31
  - .document
32
- - .gitignore
33
32
  - LICENSE
34
33
  - README.rdoc
35
34
  - Rakefile
@@ -46,41 +45,38 @@ files:
46
45
  - test/test_glutton_ratelimit_bursty_ring_buffer.rb
47
46
  - test/test_glutton_ratelimit_bursty_token_bucket.rb
48
47
  - test/testing_module.rb
49
- has_rdoc: true
50
48
  homepage: http://github.com/stungeye/glutton_ratelimit
51
49
  licenses: []
52
50
 
53
51
  post_install_message:
54
- rdoc_options:
55
- - --charset=UTF-8
52
+ rdoc_options: []
53
+
56
54
  require_paths:
57
55
  - lib
58
56
  required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
59
58
  requirements:
60
59
  - - ">="
61
60
  - !ruby/object:Gem::Version
61
+ hash: 3
62
62
  segments:
63
63
  - 0
64
64
  version: "0"
65
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
66
67
  requirements:
67
68
  - - ">="
68
69
  - !ruby/object:Gem::Version
70
+ hash: 3
69
71
  segments:
70
72
  - 0
71
73
  version: "0"
72
74
  requirements: []
73
75
 
74
76
  rubyforge_project:
75
- rubygems_version: 1.3.6
77
+ rubygems_version: 1.8.5
76
78
  signing_key:
77
79
  specification_version: 3
78
80
  summary: Simple Ruby library for self-imposed rater-limiting.
79
- test_files:
80
- - test/test_glutton_ratelimit_averaged_throttle.rb
81
- - test/helper.rb
82
- - test/test_glutton_ratelimit_bursty_ring_buffer.rb
83
- - test/testing_module.rb
84
- - test/test_glutton_ratelimit_bursty_token_bucket.rb
85
- - examples/limit_instance_methods.rb
86
- - examples/simple_manual.rb
81
+ test_files: []
82
+
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC