timberline 0.3.1 → 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.
@@ -1,114 +0,0 @@
1
- require 'test_helper'
2
-
3
- class QueueTest < Test::Unit::TestCase
4
- a "newly instantiated Queue" do
5
- before do
6
- clear_test_db
7
- @queue = Timberline::Queue.new("test_queue")
8
- end
9
-
10
- it "saves the passed-in string as its queue name" do
11
- assert_equal "test_queue", @queue.queue_name
12
- end
13
-
14
- it "saves its existence in timberline_queue_names" do
15
- assert_equal true, Timberline.redis.sismember("timberline_queue_names", "test_queue")
16
- end
17
-
18
- it "has a length of 0" do
19
- assert_equal 0, @queue.length
20
- end
21
-
22
- it "starts in an unpaused state" do
23
- assert_equal false, @queue.paused?
24
- end
25
-
26
- it "allows itself to be paused and unpaused" do
27
- @queue.pause
28
- assert_equal true, @queue.paused?
29
- @queue.unpause
30
- assert_equal false, @queue.paused?
31
- end
32
-
33
- it "has a default read_timeout of 0" do
34
- assert_equal 0, @queue.read_timeout
35
- end
36
-
37
- it "responds nil to a pop request after the read_timeout occurs" do
38
- # Let's set the read_timeout to 1 in order for this test to return
39
- @queue.instance_variable_set("@read_timeout", 1)
40
- assert_equal nil, @queue.pop
41
- end
42
-
43
- it "puts an item on the queue when that item is pushed" do
44
- test_item = "Test Queue Item"
45
- assert_equal 1, @queue.push(test_item)
46
- end
47
-
48
- it "wraps an item in an envelope when that item is pushed" do
49
- test_item = "Test Queue Item"
50
- assert_equal 1, @queue.push(test_item)
51
- data = @queue.pop
52
- assert_kind_of Timberline::Envelope, data
53
- assert_equal test_item, data.contents
54
- end
55
-
56
- it "doesn't wrap an envelope that gets pushed in another envelope" do
57
- test_item = "Test Queue Item"
58
- env = Timberline::Envelope.new
59
- env.contents = test_item
60
- assert_equal 1, @queue.push(env)
61
- data = @queue.pop
62
- assert_kind_of Timberline::Envelope, data
63
- assert_equal test_item, data.contents
64
- end
65
-
66
- it "removes everything associated with the queue when delete! is called" do
67
- test_item = "Test Queue Item"
68
- assert_equal 1, @queue.push(test_item)
69
- Timberline.redis[@queue.attr("test")] = "test"
70
- Timberline.redis[@queue.attr("foo")] = "foo"
71
- Timberline.redis[@queue.attr("bar")] = "bar"
72
-
73
- @queue.delete!
74
- assert_equal nil, Timberline.redis[@queue.attr("test")]
75
- assert_equal nil, Timberline.redis[@queue.attr("test")]
76
- assert_equal nil, Timberline.redis[@queue.attr("test")]
77
- assert_equal nil, Timberline.redis[@queue.queue_name]
78
- assert_equal false, Timberline.redis.sismember("timberline_queue_names","test_queue")
79
- end
80
-
81
- it "uses any passed-in metadata to push when building the envelope" do
82
- @queue.push("Howdy kids.", { :special_notes => "Super-awesome."})
83
- assert_equal 1, @queue.length
84
- data = @queue.pop
85
- assert_equal "Howdy kids.", data.contents
86
- assert_equal "Super-awesome.", data.special_notes
87
- end
88
-
89
- end
90
-
91
- a "Queue with one item" do
92
- before do
93
- clear_test_db
94
- @test_item = "Test Queue Item"
95
- @queue = Timberline::Queue.new("test_queue")
96
- @queue.push(@test_item)
97
- end
98
-
99
- it "has a length of 1" do
100
- assert_equal 1, @queue.length
101
- end
102
-
103
- it "responds to pop with the one item" do
104
- assert_equal @test_item, @queue.pop.contents
105
- end
106
-
107
- it "responds nil to a second pop" do
108
- # Let's set the read_timeout to 1 in order for this test to return
109
- @queue.instance_variable_set("@read_timeout", 1)
110
- assert_equal @test_item, @queue.pop.contents
111
- assert_equal nil, @queue.pop
112
- end
113
- end
114
- end
@@ -1,143 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TimberlineTest < Test::Unit::TestCase
4
- a "Freshly set up Timberline" do
5
- before do
6
- reset_timberline
7
- end
8
-
9
- it "creates a new queue when asked if it doesn't exist" do
10
- queue = Timberline.queue("test_queue")
11
- assert_kind_of Timberline::Queue, queue
12
- assert_equal queue, Timberline.instance_variable_get("@queue_list")["test_queue"]
13
- end
14
-
15
- it "doesn't create a new queue if a queue by the same name already exists" do
16
- queue = Timberline.queue("test_queue")
17
- new_queue = Timberline.queue("test_queue")
18
- assert_equal queue, new_queue
19
- end
20
-
21
- it "creates a new queue as necessary when 'push' is called and pushes the item" do
22
- Timberline.push("test_queue", "Howdy kids.")
23
- queue = Timberline.queue("test_queue")
24
- assert_equal 1, queue.length
25
- assert_equal "Howdy kids.", queue.pop.contents
26
- end
27
-
28
- it "logs the existence of the queue so that other managers can see it" do
29
- queue = Timberline.queue("test_queue")
30
- assert_equal 1, Timberline.all_queues.size
31
- assert_equal "test_queue", Timberline.all_queues.first.queue_name
32
- end
33
-
34
- it "saves a passed-in redis namespace" do
35
- redis = Redis.new
36
- redisns = Redis::Namespace.new("timberline", redis)
37
- Timberline.redis = redisns
38
- assert_equal redisns, Timberline.redis
39
- end
40
-
41
- it "Converts a standard redis server into a namespace" do
42
- redis = Redis.new
43
- Timberline.redis = redis
44
- assert_equal Redis::Namespace, Timberline.redis.class
45
- assert_equal redis, Timberline.redis.instance_variable_get("@redis")
46
- end
47
-
48
- it "generates a redis namespace on request if one isn't present" do
49
- assert_equal Redis::Namespace, Timberline.redis.class
50
- end
51
-
52
- it "uses a default namespace of 'timberline'" do
53
- assert_equal "timberline", Timberline.redis.namespace
54
- end
55
-
56
- it "can be configured" do
57
- Timberline.config do |c|
58
- c.database = 3
59
- end
60
-
61
- assert_equal 3, Timberline.instance_variable_get("@config").database
62
- end
63
-
64
- it "uses a pre-defined namespace name if configured" do
65
- Timberline.config do |c|
66
- c.namespace = "skyline"
67
- end
68
-
69
- assert_equal "skyline", Timberline.redis.namespace
70
- end
71
-
72
- it "properly configures Redis" do
73
- @logger = Logger.new STDERR
74
- Timberline.config do |c|
75
- c.host = "localhost"
76
- c.timeout = 10
77
- c.database = 3
78
- c.logger = @logger
79
- end
80
-
81
- redis = Timberline.redis
82
-
83
- assert_equal "localhost", redis.client.host
84
- assert_equal 10, redis.client.timeout
85
- assert_equal 3, redis.client.db
86
- assert_equal @logger, redis.client.logger
87
-
88
- end
89
-
90
- it "allows you to retry a job that has failed" do
91
- Timberline.push("test_queue", "Howdy kids.")
92
- queue = Timberline.queue("test_queue")
93
- data = queue.pop
94
-
95
- assert_equal 0, queue.length
96
-
97
- assert_raises Timberline::ItemRetried do
98
- Timberline.retry_item(data)
99
- end
100
-
101
- assert_equal 1, queue.length
102
-
103
- data = queue.pop
104
- assert_equal 1, data.retries
105
- assert_kind_of Time, Time.at(data.last_tried_at)
106
- end
107
-
108
- it "will continue retrying until we pass the max retries (defaults to 5)" do
109
- Timberline.push("test_queue", "Howdy kids.")
110
- queue = Timberline.queue("test_queue")
111
- data = queue.pop
112
-
113
- 5.times do |i|
114
- assert_raises Timberline::ItemRetried do
115
- Timberline.retry_item(data)
116
- end
117
- assert_equal 1, queue.length
118
- data = queue.pop
119
- assert_equal i + 1, data.retries
120
- end
121
-
122
- assert_raises Timberline::ItemErrored do
123
- Timberline.retry_item(data)
124
- end
125
- assert_equal 0, queue.length
126
- assert_equal 1, Timberline.error_queue.length
127
- end
128
-
129
- it "will allow you to directly error out a job" do
130
- Timberline.push("test_queue", "Howdy kids.")
131
- queue = Timberline.queue("test_queue")
132
- data = queue.pop
133
-
134
- assert_raises Timberline::ItemErrored do
135
- Timberline.error_item(data)
136
- end
137
- assert_equal 1, Timberline.error_queue.length
138
- data = Timberline.error_queue.pop
139
- assert_kind_of Time, Time.at(data.fatal_error_at)
140
- end
141
-
142
- end
143
- end
File without changes