Merge lp:~brianaker/gearmand/test-reply into lp:gearmand

Proposed by Brian Aker on 2013-09-16
Status: Merged
Merged at revision: 874
Proposed branch: lp:~brianaker/gearmand/test-reply
Merge into: lp:gearmand
Diff against target: 313 lines (+137/-17)
8 files modified
ChangeLog (+1/-0)
libgearman-1.0/client.h (+3/-0)
libgearman/client.cc (+15/-13)
libgearman/log.cc (+5/-0)
libgearman/worker.cc (+8/-0)
tests/libgearman-1.0/worker_test.cc (+92/-4)
tests/start_worker.cc (+2/-0)
tests/start_worker.h (+11/-0)
To merge this branch: bzr merge lp:~brianaker/gearmand/test-reply
Reviewer Review Type Date Requested Status
Tangent Trunk 2013-09-16 Pending
Review via email: mp+185706@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2013-09-05 23:41:08 +0000
3+++ ChangeLog 2013-09-16 06:07:37 +0000
4@@ -3,6 +3,7 @@
5 * Improve compile time.
6 * Fix for NOOP failure (bad worker causes early exit of loop).
7 * Fix for postgres (use INFORMATION_SCHEMA).
8+* Added gearman_client_has_active_tasks() so that you can see if a client has active tasks that it is working on.
9
10 1.1.9 Fri Aug 2 02:39:25 EDT 2013
11 * Added gearman_task_is_finished()
12
13=== modified file 'libgearman-1.0/client.h'
14--- libgearman-1.0/client.h 2012-11-19 10:43:50 +0000
15+++ libgearman-1.0/client.h 2013-09-16 06:07:37 +0000
16@@ -713,6 +713,9 @@
17 GEARMAN_API
18 bool gearman_client_has_tasks(const gearman_client_st *client);
19
20+GEARMAN_API
21+bool gearman_client_has_active_tasks(gearman_client_st *client);
22+
23 /** @} */
24
25 #ifdef __cplusplus
26
27=== modified file 'libgearman/client.cc'
28--- libgearman/client.cc 2013-08-20 09:27:42 +0000
29+++ libgearman/client.cc 2013-09-16 06:07:37 +0000
30@@ -712,26 +712,28 @@
31 return count;
32 }
33
34-#if 0
35-static bool _active_tasks(gearman_client_st *client_shell)
36+bool gearman_client_has_active_tasks(gearman_client_st *client_shell)
37 {
38- assert(client_shell);
39- gearman_task_st *search= client_shell->impl()->task_list;
40-
41- if (not search)
42- return false;
43-
44- do
45+ if (client_shell and client_shell->impl())
46 {
47- if (gearman_task_is_active(search))
48+ Client* client= client_shell->impl();
49+
50+ if (client->task_list and client->task_list->impl())
51 {
52- return true;
53+ gearman_task_st* search= client->task_list;
54+
55+ do
56+ {
57+ if (gearman_task_is_active(search))
58+ {
59+ return true;
60+ }
61+ } while ((search= search->impl()->next));
62 }
63- } while ((search= search->next));
64+ }
65
66 return false;
67 }
68-#endif
69
70 const char *gearman_client_do_job_handle(gearman_client_st *self)
71 {
72
73=== modified file 'libgearman/log.cc'
74--- libgearman/log.cc 2013-05-12 21:37:25 +0000
75+++ libgearman/log.cc 2013-09-16 06:07:37 +0000
76@@ -98,6 +98,7 @@
77
78 void gearman_log_debug(gearman_universal_st& gearman, const char *format, ...)
79 {
80+#if defined(DEBUG) && DEBUG
81 va_list args;
82
83 if (gearman.verbose >= GEARMAN_VERBOSE_DEBUG)
84@@ -106,5 +107,9 @@
85 __logger(gearman, GEARMAN_VERBOSE_DEBUG, format, args);
86 va_end(args);
87 }
88+#else
89+ (void)gearman;
90+ (void)format;
91+#endif
92 }
93 #pragma GCC diagnostic pop
94
95=== modified file 'libgearman/worker.cc'
96--- libgearman/worker.cc 2013-08-31 03:16:21 +0000
97+++ libgearman/worker.cc 2013-09-16 06:07:37 +0000
98@@ -47,6 +47,8 @@
99
100 #include "libgearman/assert.hpp"
101
102+#include "libgearman/log.hpp"
103+
104 #include <cstdio>
105 #include <cstdlib>
106 #include <cstring>
107@@ -847,6 +849,11 @@
108 return NULL;
109 }
110
111+ if (worker->job()->impl()->assigned.command == GEARMAN_COMMAND_NOOP)
112+ {
113+ gearman_log_debug(worker->universal, "Recieved NOOP");
114+ }
115+
116 if (worker->job()->impl()->assigned.command == GEARMAN_COMMAND_JOB_ASSIGN or
117 worker->job()->impl()->assigned.command == GEARMAN_COMMAND_JOB_ASSIGN_ALL or
118 worker->job()->impl()->assigned.command == GEARMAN_COMMAND_JOB_ASSIGN_UNIQ)
119@@ -1124,6 +1131,7 @@
120 switch (worker->work_function->callback(worker->work_job(),
121 static_cast<void *>(worker->work_function->context)))
122 {
123+ // @todo look at this from a "what should we do" view.
124 case GEARMAN_FUNCTION_INVALID_ARGUMENT:
125 // worker returned an invalid response, gearman_return_t
126 case GEARMAN_FUNCTION_FATAL:
127
128=== modified file 'tests/libgearman-1.0/worker_test.cc'
129--- tests/libgearman-1.0/worker_test.cc 2013-09-15 22:55:59 +0000
130+++ tests/libgearman-1.0/worker_test.cc 2013-09-16 06:07:37 +0000
131@@ -673,7 +673,7 @@
132
133 // The idea is to return GEARMAN_ERROR until we hit limit, then return
134 // GEARMAN_SUCCESS
135-static gearman_return_t GEARMAN_ERROR_worker(gearman_job_st* job, void *context)
136+static gearman_return_t GEARMAN_ERROR_limit_worker(gearman_job_st* job, void *context)
137 {
138 assert(gearman_job_workload_size(job) == 0);
139 assert(gearman_job_workload(job) == NULL);
140@@ -694,6 +694,13 @@
141 return GEARMAN_SUCCESS;
142 }
143
144+static gearman_return_t GEARMAN_ERROR_worker(gearman_job_st*, void* context)
145+{
146+ size_t *ret= (size_t*)context;
147+ *ret= (*ret) +1;
148+ return GEARMAN_ERROR;
149+}
150+
151 static gearman_return_t error_return_worker(gearman_job_st* job, void *)
152 {
153 assert(sizeof(gearman_return_t) == gearman_job_workload_size(job));
154@@ -778,13 +785,91 @@
155 return TEST_SUCCESS;
156 }
157
158+static test_return_t GEARMAN_ERROR_check_retry_TEST(void *)
159+{
160+ libgearman::Client client(libtest::default_port());
161+ ASSERT_EQ(GEARMAN_SUCCESS, gearman_client_echo(&client, test_literal_param(__func__)));
162+
163+ size_t count= 0;
164+ gearman_function_t GEARMAN_ERROR_FN= gearman_function_create(GEARMAN_ERROR_worker);
165+ std::auto_ptr<worker_handle_st> handle(test_worker_start(libtest::default_port(),
166+ NULL,
167+ __func__,
168+ GEARMAN_ERROR_FN,
169+ &count,
170+ gearman_worker_options_t(),
171+ 0)); // timeout
172+
173+ gearman_task_st *task= gearman_execute(&client,
174+ test_literal_param(__func__),
175+ NULL, 0, // unique
176+ NULL, // gearman_task_attr_t
177+ NULL, // gearman_argument_t
178+ NULL); // context
179+ ASSERT_NOT_NULL(task);
180+
181+ gearman_return_t ret;
182+ do {
183+ ret= gearman_client_run_tasks(&client);
184+ ASSERT_TRUE(gearman_success(ret) or ret == GEARMAN_IO_WAIT);
185+ } while (gearman_client_has_active_tasks(&client));
186+
187+ ASSERT_EQ(GEARMAN_WORK_FAIL, gearman_task_return(task));
188+ ASSERT_EQ(count, 30);
189+
190+ return TEST_SUCCESS;
191+}
192+
193+static test_return_t GEARMAN_ERROR_always_return_TEST(void *)
194+{
195+ libgearman::Client client(libtest::default_port());
196+ ASSERT_EQ(GEARMAN_SUCCESS, gearman_client_echo(&client, test_literal_param(__func__)));
197+
198+ size_t count= 0;
199+ gearman_function_t GEARMAN_ERROR_FN= gearman_function_create(GEARMAN_ERROR_worker);
200+ std::auto_ptr<worker_handle_st> handle(test_worker_start(libtest::default_port(),
201+ NULL,
202+ __func__,
203+ GEARMAN_ERROR_FN,
204+ &count,
205+ gearman_worker_options_t(),
206+ 0)); // timeout
207+
208+ std::vector<gearman_task_st*> tasks;
209+ for (size_t x= 0; x < 24; x++)
210+ {
211+ gearman_task_st *task= gearman_execute(&client,
212+ test_literal_param(__func__),
213+ NULL, 0, // unique
214+ NULL, // gearman_task_attr_t
215+ NULL, // gearman_argument_t
216+ NULL); // context
217+ test_truth(task);
218+ tasks.push_back(task);
219+ }
220+
221+ gearman_return_t ret;
222+ do {
223+ ret= gearman_client_run_tasks(&client);
224+ ASSERT_TRUE(gearman_success(ret) or ret == GEARMAN_IO_WAIT);
225+ } while (gearman_client_has_active_tasks(&client));
226+
227+ for (std::vector<gearman_task_st*>::iterator iter= tasks.begin(); iter != tasks.end(); iter++)
228+ {
229+ ASSERT_TRUE(*iter);
230+ ASSERT_EQ(GEARMAN_WORK_FAIL, gearman_task_return(*iter));
231+ }
232+
233+ return TEST_SUCCESS;
234+}
235+
236 static test_return_t GEARMAN_ERROR_return_TEST(void *)
237 {
238 libgearman::Client client(libtest::default_port());
239 ASSERT_EQ(GEARMAN_SUCCESS, gearman_client_echo(&client, test_literal_param(__func__)));
240
241 size_t count= 0;
242- gearman_function_t GEARMAN_ERROR_FN= gearman_function_create(GEARMAN_ERROR_worker);
243+ gearman_function_t GEARMAN_ERROR_FN= gearman_function_create(GEARMAN_ERROR_limit_worker);
244 std::auto_ptr<worker_handle_st> handle(test_worker_start(libtest::default_port(),
245 NULL,
246 __func__,
247@@ -1705,10 +1790,11 @@
248
249 static void *world_create(server_startup_st& servers, test_return_t&)
250 {
251- ASSERT_TRUE(server_startup(servers, "gearmand", libtest::default_port(), NULL));
252+ const char *argv[]= { "--job-retries=30", NULL };
253+ ASSERT_TRUE(server_startup(servers, "gearmand", libtest::default_port(), argv));
254
255 second_port= libtest::get_free_port();
256- ASSERT_TRUE(server_startup(servers, "gearmand", second_port, NULL));
257+ ASSERT_TRUE(server_startup(servers, "gearmand", second_port, argv));
258
259 return &servers;
260 }
261@@ -1740,6 +1826,8 @@
262 {"gearman_return_t worker return coverage", 0, error_return_TEST },
263 {"gearman_return_t GEARMAN_FAIL worker coverage", 0, GEARMAN_FAIL_return_TEST },
264 {"gearman_return_t GEARMAN_ERROR worker coverage", 0, GEARMAN_ERROR_return_TEST },
265+ {"gearman_return_t GEARMAN_ERROR worker always errors", 0, GEARMAN_ERROR_always_return_TEST },
266+ {"gearman_return_t GEARMAN_ERROR worker always errors check retry", 0, GEARMAN_ERROR_check_retry_TEST },
267 {"gearman_client_run_tasks()", 0, gearman_client_run_tasks_increase_TEST },
268 {"gearman_client_run_tasks() GEARMAN_CLIENT_NON_BLOCKING", 0, gearman_client_run_tasks_increase_GEARMAN_CLIENT_NON_BLOCKING_TEST },
269 {"gearman_client_run_tasks() chunked", 0, gearman_client_run_tasks_increase_chunk_TEST },
270
271=== modified file 'tests/start_worker.cc'
272--- tests/start_worker.cc 2013-07-24 10:58:57 +0000
273+++ tests/start_worker.cc 2013-09-16 06:07:37 +0000
274@@ -224,6 +224,7 @@
275
276 if (ret != GEARMAN_SUCCESS and ret != GEARMAN_INVALID_ARGUMENT and ret != GEARMAN_WORK_FAIL)
277 {
278+ context->handle->error();
279 #if 0
280 Error << context->function_name << ": " << gearman_strerror(ret) << ": " << gearman_worker_error(&worker);
281 #endif
282@@ -276,6 +277,7 @@
283 worker_handle_st::worker_handle_st() :
284 failed_startup(false),
285 _shutdown(false),
286+ _error_count(0),
287 _worker_id(gearman_id_t()),
288 _sync_point(2)
289 {
290
291=== modified file 'tests/start_worker.h'
292--- tests/start_worker.h 2013-04-03 04:16:08 +0000
293+++ tests/start_worker.h 2013-09-16 06:07:37 +0000
294@@ -66,8 +66,19 @@
295 volatile bool failed_startup;
296 boost::shared_ptr<libtest::thread::Thread> _thread;
297
298+ void error(gearman_return_t)
299+ {
300+ _error_count++;
301+ }
302+
303+ bool error()
304+ {
305+ return _error_count;
306+ }
307+
308 private:
309 bool _shutdown;
310+ uint64_t _error_count;
311 libtest::thread::Mutex _shutdown_lock;
312 gearman_id_t _worker_id;
313 libtest::thread::Barrier _sync_point;

Subscribers

People subscribed via source and target branches

to all changes: