resque-loner 1.0.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,230 @@
1
+ require 'test_helper'
2
+
3
+ context "Multiple plugins with multiple hooks" do
4
+ include PerformJob
5
+
6
+ module Plugin1
7
+ def before_perform_record_history1(history)
8
+ history << :before1
9
+ end
10
+ def after_perform_record_history1(history)
11
+ history << :after1
12
+ end
13
+ end
14
+
15
+ module Plugin2
16
+ def before_perform_record_history2(history)
17
+ history << :before2
18
+ end
19
+ def after_perform_record_history2(history)
20
+ history << :after2
21
+ end
22
+ end
23
+
24
+ class ::ManyBeforesJob
25
+ extend Plugin1
26
+ extend Plugin2
27
+ def self.perform(history)
28
+ history << :perform
29
+ end
30
+ end
31
+
32
+ test "hooks of each type are executed in alphabetical order" do
33
+ result = perform_job(ManyBeforesJob, history=[])
34
+ assert_equal true, result, "perform returned true"
35
+ assert_equal [:before1, :before2, :perform, :after1, :after2], history
36
+ end
37
+ end
38
+
39
+ context "Resque::Plugin ordering before_perform" do
40
+ include PerformJob
41
+
42
+ module BeforePerformPlugin
43
+ def before_perform1(history)
44
+ history << :before_perform1
45
+ end
46
+ end
47
+
48
+ class ::JobPluginsTestBeforePerformJob
49
+ extend BeforePerformPlugin
50
+ def self.perform(history)
51
+ history << :perform
52
+ end
53
+ def self.before_perform(history)
54
+ history << :before_perform
55
+ end
56
+ end
57
+
58
+ test "before_perform hooks are executed in order" do
59
+ result = perform_job(JobPluginsTestBeforePerformJob, history=[])
60
+ assert_equal true, result, "perform returned true"
61
+ assert_equal [:before_perform, :before_perform1, :perform], history
62
+ end
63
+ end
64
+
65
+ context "Resque::Plugin ordering after_perform" do
66
+ include PerformJob
67
+
68
+ module AfterPerformPlugin
69
+ def after_perform_record_history(history)
70
+ history << :after_perform1
71
+ end
72
+ end
73
+
74
+ class ::JobPluginsTestAfterPerformJob
75
+ extend AfterPerformPlugin
76
+ def self.perform(history)
77
+ history << :perform
78
+ end
79
+ def self.after_perform(history)
80
+ history << :after_perform
81
+ end
82
+ end
83
+
84
+ test "after_perform hooks are executed in order" do
85
+ result = perform_job(JobPluginsTestAfterPerformJob, history=[])
86
+ assert_equal true, result, "perform returned true"
87
+ assert_equal [:perform, :after_perform, :after_perform1], history
88
+ end
89
+ end
90
+
91
+ context "Resque::Plugin ordering around_perform" do
92
+ include PerformJob
93
+
94
+ module AroundPerformPlugin1
95
+ def around_perform1(history)
96
+ history << :around_perform_plugin1
97
+ yield
98
+ end
99
+ end
100
+
101
+ class ::AroundPerformJustPerformsJob
102
+ extend AroundPerformPlugin1
103
+ def self.perform(history)
104
+ history << :perform
105
+ end
106
+ end
107
+
108
+ test "around_perform hooks are executed before the job" do
109
+ result = perform_job(AroundPerformJustPerformsJob, history=[])
110
+ assert_equal true, result, "perform returned true"
111
+ assert_equal [:around_perform_plugin1, :perform], history
112
+ end
113
+
114
+ class ::JobPluginsTestAroundPerformJob
115
+ extend AroundPerformPlugin1
116
+ def self.perform(history)
117
+ history << :perform
118
+ end
119
+ def self.around_perform(history)
120
+ history << :around_perform
121
+ yield
122
+ end
123
+ end
124
+
125
+ test "around_perform hooks are executed in order" do
126
+ result = perform_job(JobPluginsTestAroundPerformJob, history=[])
127
+ assert_equal true, result, "perform returned true"
128
+ assert_equal [:around_perform, :around_perform_plugin1, :perform], history
129
+ end
130
+
131
+ module AroundPerformPlugin2
132
+ def around_perform2(history)
133
+ history << :around_perform_plugin2
134
+ yield
135
+ end
136
+ end
137
+
138
+ class ::AroundPerformJob2
139
+ extend AroundPerformPlugin1
140
+ extend AroundPerformPlugin2
141
+ def self.perform(history)
142
+ history << :perform
143
+ end
144
+ def self.around_perform(history)
145
+ history << :around_perform
146
+ yield
147
+ end
148
+ end
149
+
150
+ test "many around_perform are executed in order" do
151
+ result = perform_job(AroundPerformJob2, history=[])
152
+ assert_equal true, result, "perform returned true"
153
+ assert_equal [:around_perform, :around_perform_plugin1, :around_perform_plugin2, :perform], history
154
+ end
155
+
156
+ module AroundPerformDoesNotYield
157
+ def around_perform0(history)
158
+ history << :around_perform0
159
+ end
160
+ end
161
+
162
+ class ::AroundPerformJob3
163
+ extend AroundPerformPlugin1
164
+ extend AroundPerformPlugin2
165
+ extend AroundPerformDoesNotYield
166
+ def self.perform(history)
167
+ history << :perform
168
+ end
169
+ def self.around_perform(history)
170
+ history << :around_perform
171
+ yield
172
+ end
173
+ end
174
+
175
+ test "the job is aborted if an around_perform hook does not yield" do
176
+ result = perform_job(AroundPerformJob3, history=[])
177
+ assert_equal false, result, "perform returned false"
178
+ assert_equal [:around_perform, :around_perform0], history
179
+ end
180
+
181
+ module AroundPerformGetsJobResult
182
+ @@result = nil
183
+ def last_job_result
184
+ @@result
185
+ end
186
+
187
+ def around_perform_gets_job_result(*args)
188
+ @@result = yield
189
+ end
190
+ end
191
+
192
+ class ::AroundPerformJobWithReturnValue < GoodJob
193
+ extend AroundPerformGetsJobResult
194
+ end
195
+
196
+ test "the job is aborted if an around_perform hook does not yield" do
197
+ result = perform_job(AroundPerformJobWithReturnValue, 'Bob')
198
+ assert_equal true, result, "perform returned true"
199
+ assert_equal 'Good job, Bob', AroundPerformJobWithReturnValue.last_job_result
200
+ end
201
+ end
202
+
203
+ context "Resque::Plugin ordering on_failure" do
204
+ include PerformJob
205
+
206
+ module OnFailurePlugin
207
+ def on_failure1(exception, history)
208
+ history << "#{exception.message} plugin"
209
+ end
210
+ end
211
+
212
+ class ::FailureJob
213
+ extend OnFailurePlugin
214
+ def self.perform(history)
215
+ history << :perform
216
+ raise StandardError, "oh no"
217
+ end
218
+ def self.on_failure(exception, history)
219
+ history << exception.message
220
+ end
221
+ end
222
+
223
+ test "on_failure hooks are executed in order" do
224
+ history = []
225
+ assert_raises StandardError do
226
+ perform_job(FailureJob, history)
227
+ end
228
+ assert_equal [:perform, "oh no", "oh no plugin"], history
229
+ end
230
+ end
@@ -0,0 +1,116 @@
1
+ require 'test_helper'
2
+
3
+ context "Resque::Plugin finding hooks" do
4
+ module SimplePlugin
5
+ extend self
6
+ def before_perform1; end
7
+ def before_perform; end
8
+ def before_perform2; end
9
+ def after_perform1; end
10
+ def after_perform; end
11
+ def after_perform2; end
12
+ def perform; end
13
+ def around_perform1; end
14
+ def around_perform; end
15
+ def around_perform2; end
16
+ def on_failure1; end
17
+ def on_failure; end
18
+ def on_failure2; end
19
+ end
20
+
21
+ test "before_perform hooks are found and sorted" do
22
+ assert_equal ["before_perform", "before_perform1", "before_perform2"], Resque::Plugin.before_hooks(SimplePlugin).map {|m| m.to_s}
23
+ end
24
+
25
+ test "after_perform hooks are found and sorted" do
26
+ assert_equal ["after_perform", "after_perform1", "after_perform2"], Resque::Plugin.after_hooks(SimplePlugin).map {|m| m.to_s}
27
+ end
28
+
29
+ test "around_perform hooks are found and sorted" do
30
+ assert_equal ["around_perform", "around_perform1", "around_perform2"], Resque::Plugin.around_hooks(SimplePlugin).map {|m| m.to_s}
31
+ end
32
+
33
+ test "on_failure hooks are found and sorted" do
34
+ assert_equal ["on_failure", "on_failure1", "on_failure2"], Resque::Plugin.failure_hooks(SimplePlugin).map {|m| m.to_s}
35
+ end
36
+ end
37
+
38
+ context "Resque::Plugin linting" do
39
+ module ::BadBefore
40
+ def self.before_perform; end
41
+ end
42
+ module ::BadAfter
43
+ def self.after_perform; end
44
+ end
45
+ module ::BadAround
46
+ def self.around_perform; end
47
+ end
48
+ module ::BadFailure
49
+ def self.on_failure; end
50
+ end
51
+
52
+ test "before_perform must be namespaced" do
53
+ begin
54
+ Resque::Plugin.lint(BadBefore)
55
+ assert false, "should have failed"
56
+ rescue Resque::Plugin::LintError => e
57
+ assert_equal "BadBefore.before_perform is not namespaced", e.message
58
+ end
59
+ end
60
+
61
+ test "after_perform must be namespaced" do
62
+ begin
63
+ Resque::Plugin.lint(BadAfter)
64
+ assert false, "should have failed"
65
+ rescue Resque::Plugin::LintError => e
66
+ assert_equal "BadAfter.after_perform is not namespaced", e.message
67
+ end
68
+ end
69
+
70
+ test "around_perform must be namespaced" do
71
+ begin
72
+ Resque::Plugin.lint(BadAround)
73
+ assert false, "should have failed"
74
+ rescue Resque::Plugin::LintError => e
75
+ assert_equal "BadAround.around_perform is not namespaced", e.message
76
+ end
77
+ end
78
+
79
+ test "on_failure must be namespaced" do
80
+ begin
81
+ Resque::Plugin.lint(BadFailure)
82
+ assert false, "should have failed"
83
+ rescue Resque::Plugin::LintError => e
84
+ assert_equal "BadFailure.on_failure is not namespaced", e.message
85
+ end
86
+ end
87
+
88
+ module GoodBefore
89
+ def self.before_perform1; end
90
+ end
91
+ module GoodAfter
92
+ def self.after_perform1; end
93
+ end
94
+ module GoodAround
95
+ def self.around_perform1; end
96
+ end
97
+ module GoodFailure
98
+ def self.on_failure1; end
99
+ end
100
+
101
+ test "before_perform1 is an ok name" do
102
+ Resque::Plugin.lint(GoodBefore)
103
+ end
104
+
105
+ test "after_perform1 is an ok name" do
106
+ Resque::Plugin.lint(GoodAfter)
107
+ end
108
+
109
+ test "around_perform1 is an ok name" do
110
+ Resque::Plugin.lint(GoodAround)
111
+ end
112
+
113
+ test "on_failure1 is an ok name" do
114
+ Resque::Plugin.lint(GoodFailure)
115
+ end
116
+ end
@@ -0,0 +1,115 @@
1
+ # Redis configuration file example
2
+
3
+ # By default Redis does not run as a daemon. Use 'yes' if you need it.
4
+ # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
5
+ daemonize yes
6
+
7
+ # When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
8
+ # You can specify a custom pid file location here.
9
+ pidfile ./test/redis-test.pid
10
+
11
+ # Accept connections on the specified port, default is 6379
12
+ port 9736
13
+
14
+ # If you want you can bind a single interface, if the bind option is not
15
+ # specified all the interfaces will listen for connections.
16
+ #
17
+ # bind 127.0.0.1
18
+
19
+ # Close the connection after a client is idle for N seconds (0 to disable)
20
+ timeout 300
21
+
22
+ # Save the DB on disk:
23
+ #
24
+ # save <seconds> <changes>
25
+ #
26
+ # Will save the DB if both the given number of seconds and the given
27
+ # number of write operations against the DB occurred.
28
+ #
29
+ # In the example below the behaviour will be to save:
30
+ # after 900 sec (15 min) if at least 1 key changed
31
+ # after 300 sec (5 min) if at least 10 keys changed
32
+ # after 60 sec if at least 10000 keys changed
33
+ save 900 1
34
+ save 300 10
35
+ save 60 10000
36
+
37
+ # The filename where to dump the DB
38
+ dbfilename dump.rdb
39
+
40
+ # For default save/load DB in/from the working directory
41
+ # Note that you must specify a directory not a file name.
42
+ dir ./test/
43
+
44
+ # Set server verbosity to 'debug'
45
+ # it can be one of:
46
+ # debug (a lot of information, useful for development/testing)
47
+ # notice (moderately verbose, what you want in production probably)
48
+ # warning (only very important / critical messages are logged)
49
+ loglevel debug
50
+
51
+ # Specify the log file name. Also 'stdout' can be used to force
52
+ # the demon to log on the standard output. Note that if you use standard
53
+ # output for logging but daemonize, logs will be sent to /dev/null
54
+ logfile stdout
55
+
56
+ # Set the number of databases. The default database is DB 0, you can select
57
+ # a different one on a per-connection basis using SELECT <dbid> where
58
+ # dbid is a number between 0 and 'databases'-1
59
+ databases 16
60
+
61
+ ################################# REPLICATION #################################
62
+
63
+ # Master-Slave replication. Use slaveof to make a Redis instance a copy of
64
+ # another Redis server. Note that the configuration is local to the slave
65
+ # so for example it is possible to configure the slave to save the DB with a
66
+ # different interval, or to listen to another port, and so on.
67
+
68
+ # slaveof <masterip> <masterport>
69
+
70
+ ################################## SECURITY ###################################
71
+
72
+ # Require clients to issue AUTH <PASSWORD> before processing any other
73
+ # commands. This might be useful in environments in which you do not trust
74
+ # others with access to the host running redis-server.
75
+ #
76
+ # This should stay commented out for backward compatibility and because most
77
+ # people do not need auth (e.g. they run their own servers).
78
+
79
+ # requirepass foobared
80
+
81
+ ################################### LIMITS ####################################
82
+
83
+ # Set the max number of connected clients at the same time. By default there
84
+ # is no limit, and it's up to the number of file descriptors the Redis process
85
+ # is able to open. The special value '0' means no limts.
86
+ # Once the limit is reached Redis will close all the new connections sending
87
+ # an error 'max number of clients reached'.
88
+
89
+ # maxclients 128
90
+
91
+ # Don't use more memory than the specified amount of bytes.
92
+ # When the memory limit is reached Redis will try to remove keys with an
93
+ # EXPIRE set. It will try to start freeing keys that are going to expire
94
+ # in little time and preserve keys with a longer time to live.
95
+ # Redis will also try to remove objects from free lists if possible.
96
+ #
97
+ # If all this fails, Redis will start to reply with errors to commands
98
+ # that will use more memory, like SET, LPUSH, and so on, and will continue
99
+ # to reply to most read-only commands like GET.
100
+ #
101
+ # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
102
+ # 'state' server or cache, not as a real DB. When Redis is used as a real
103
+ # database the memory usage will grow over the weeks, it will be obvious if
104
+ # it is going to use too much memory in the long run, and you'll have the time
105
+ # to upgrade. With maxmemory after the limit is reached you'll start to get
106
+ # errors for write operations, and this may even lead to DB inconsistency.
107
+
108
+ # maxmemory <bytes>
109
+
110
+ ############################### ADVANCED CONFIG ###############################
111
+
112
+ # Glue small output buffers together in order to send small replies in a
113
+ # single TCP packet. Uses a bit more CPU but most of the times it is a win
114
+ # in terms of number of queries per second. Use 'yes' if unsure.
115
+ glueoutputbuf yes