Merge lp:~brianaker/gearmand/fork-tests into lp:gearmand
- fork-tests
- Merge into 1.2
Status: | Merged |
---|---|
Merged at revision: | 793 |
Proposed branch: | lp:~brianaker/gearmand/fork-tests |
Merge into: | lp:gearmand |
Diff against target: |
627 lines (+266/-30) 17 files modified
.bzrignore (+3/-0) configure.ac (+11/-1) libgearman-server/plugins/protocol/gear/protocol.cc (+1/-1) libgearman/check.cc (+25/-4) libgearman/connection.cc (+12/-6) libgearman/error.cc (+12/-8) libgearman/interface/packet.hpp (+16/-1) libgearman/log.hpp (+1/-1) libgearman/packet.cc (+1/-2) libgearman/universal.cc (+6/-3) libtest/main.cc (+1/-1) libtest/run.gdb (+1/-0) libtest/stream.h (+7/-2) tests/libgearman-1.0/client_test.cc (+7/-0) tests/libgearman-1.0/fork.cc (+118/-0) tests/libgearman-1.0/fork.h (+42/-0) tests/libgearman-1.0/include.am (+2/-0) |
To merge this branch: | bzr merge lp:~brianaker/gearmand/fork-tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tangent Trunk | Pending | ||
Review via email:
|
Commit message
Description of the change
Merge
- 784. By Tangent.Org Continuous Integration
-
Merge lp:~brianaker/gearmand/fix-ssl-valgrind Build: jenkins-
Gearmand- 663 - 785. By Tangent.Org Continuous Integration
-
Merge https:/
/code.launchpad .net/~brianaker /gearmand/ gearman_ connection_ create- cleanup Build: jenkins- Gearmand- 664 - 786. By Tangent.Org Continuous Integration
-
Merge https:/
/code.launchpad .net/~brianaker /gearmand/ redis-fix/ Build: jenkins- Gearmand- 666 - 787. By Tangent.Org Continuous Integration
-
Merge lp:~brianaker/gearmand/exception-testing Build: jenkins-
Gearmand- 672 - 788. By Tangent.Org Continuous Integration
-
Merge p:~brianaker/
gearmand/ remove- job-on- exception Build: jenkins- Gearmand- 676 - 789. By Tangent.Org Continuous Integration
-
Merge lp:~brianaker/gearmand/protocol-check Build: jenkins-
Gearmand- 682 - 790. By Tangent.Org Continuous Integration
-
Merge lp:~brianaker/gearmand/waitpid Build: jenkins-
Gearmand- 684 - 791. By Tangent.Org Continuous Integration
-
Merge lp:~brianaker/gearmand/connection Build: jenkins-
Gearmand- 685 - 792. By Tangent.Org Continuous Integration
-
Merge lp:~brianaker/gearmand/connection Build: jenkins-
Gearmand- 686 - 793. By Brian Aker
-
Fork check.
- 794. By Brian Aker
-
Add diagnostics.
- 795. By Brian Aker
-
Fix for fork test.
Preview Diff
1 | === modified file '.bzrignore' |
2 | --- .bzrignore 2013-06-27 21:23:13 +0000 |
3 | +++ .bzrignore 2013-06-30 02:51:26 +0000 |
4 | @@ -117,3 +117,6 @@ |
5 | examples/wc_worker |
6 | tmp_chroot |
7 | tests/protocol |
8 | +libgearman/command.hpp |
9 | +libgearman/error_code.hpp |
10 | +TAGS |
11 | |
12 | === modified file 'configure.ac' |
13 | --- configure.ac 2013-06-06 18:29:24 +0000 |
14 | +++ configure.ac 2013-06-30 02:51:26 +0000 |
15 | @@ -187,6 +187,7 @@ |
16 | AC_REPLACE_FNMATCH |
17 | AC_CHECK_FUNCS([accept4]) |
18 | AC_CHECK_FUNCS([dup2]) |
19 | +AC_CHECK_FUNCS([fork]) |
20 | AC_CHECK_FUNCS([gettimeofday]) |
21 | AC_CHECK_FUNCS([memchr]) |
22 | AC_CHECK_FUNCS([memmove]) |
23 | @@ -223,7 +224,15 @@ |
24 | LT_LIB_M |
25 | |
26 | # Check for CyaSSL |
27 | -AX_CHECK_LIBRARY([CYASSL],[cyassl/ssl.h],[cyassl]) |
28 | +AC_DEFUN([AX_ENABLE_SSL], |
29 | + [AC_PREREQ([2.63])dnl |
30 | + AC_ARG_ENABLE([SSL], |
31 | + [AS_HELP_STRING([--enable-ssl], |
32 | + [Enable ssl support for Gearman --enable-debug (yes|no) @<:@default=no@:>@])], |
33 | + [AX_CHECK_LIBRARY([CYASSL],[cyassl/ssl.h],[cyassl])], |
34 | + [AC_MSG_WARN([ssl will not be enabled])]) |
35 | + ]) |
36 | +AX_ENABLE_SSL |
37 | #AC_SUBST([CYASSL]) |
38 | #AC_SUBST([CYASSL_LIB]) |
39 | AX_ENABLE_LIBMEMCACHED |
40 | @@ -288,6 +297,7 @@ |
41 | echo " * Building with libpq $ac_cv_libpq" |
42 | echo " * Building with tokyocabinet $ac_enable_libtokyocabinet" |
43 | echo " * Building with libmysql $found_mysql" |
44 | +echo " * SSL enabled: $enable_SSL" |
45 | echo " * make -j: $enable_jobserver" |
46 | echo " * VCS checkout: $ac_cv_vcs_checkout" |
47 | echo "" |
48 | |
49 | === modified file 'libgearman-server/plugins/protocol/gear/protocol.cc' |
50 | --- libgearman-server/plugins/protocol/gear/protocol.cc 2013-06-05 21:59:31 +0000 |
51 | +++ libgearman-server/plugins/protocol/gear/protocol.cc 2013-06-30 02:51:26 +0000 |
52 | @@ -230,7 +230,7 @@ |
53 | } |
54 | } |
55 | |
56 | - if (packet->command == GEARMAN_COMMAND_ECHO_RES) |
57 | + if (packet->command == GEARMAN_COMMAND_ECHO_RES or packet->command == GEARMAN_COMMAND_ECHO_REQ) |
58 | { |
59 | gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM, |
60 | "GEAR length: %" PRIu64 " gearmand_command_t: %s echo: %.*s", |
61 | |
62 | === modified file 'libgearman/check.cc' |
63 | --- libgearman/check.cc 2013-05-05 07:29:30 +0000 |
64 | +++ libgearman/check.cc 2013-06-30 02:51:26 +0000 |
65 | @@ -41,6 +41,8 @@ |
66 | |
67 | #include "libgearman/error_code.h" |
68 | |
69 | +#include <algorithm> |
70 | + |
71 | EchoCheck::EchoCheck(gearman_universal_st& universal_, |
72 | const void *workload_, const size_t workload_size_) : |
73 | _universal(universal_), |
74 | @@ -56,10 +58,29 @@ |
75 | return gearman_error(_universal, GEARMAN_INVALID_COMMAND, "Wrong command sent in response to ECHO request"); |
76 | } |
77 | |
78 | - if (con->_packet.data_size != _workload_size or |
79 | - memcmp(_workload, con->_packet.data, _workload_size)) |
80 | - { |
81 | - return gearman_error(_universal, GEARMAN_ECHO_DATA_CORRUPTION, "corruption during echo"); |
82 | + size_t compared= std::min(con->_packet.size(), _workload_size); |
83 | + |
84 | + if (compared != _workload_size or compared != con->_packet.size()) |
85 | + { |
86 | + // If the workload_size is smaller |
87 | + if (memcmp(_workload, con->_packet.value(), compared) == 0) |
88 | + { |
89 | + return gearman_universal_set_error(_universal, GEARMAN_ECHO_DATA_CORRUPTION, GEARMAN_AT, |
90 | + "Truncation occured, Expected %u, received %u", |
91 | + uint32_t(_workload_size), uint32_t(con->_packet.data_size)); |
92 | + } |
93 | + |
94 | + return gearman_universal_set_error(_universal, GEARMAN_ECHO_DATA_CORRUPTION, GEARMAN_AT, |
95 | + "Expected data was not received, expected %u, received %u", |
96 | + uint32_t(_workload_size), uint32_t(con->_packet.data_size)); |
97 | + } |
98 | + assert(compared == _workload_size); |
99 | + |
100 | + if (memcmp(_workload, con->_packet.value(), compared)) |
101 | + { |
102 | + return gearman_universal_set_error(_universal, GEARMAN_ECHO_DATA_CORRUPTION, GEARMAN_AT, |
103 | + "Data sent was not what was received %u == %u == %u", |
104 | + uint32_t(_workload_size), uint32_t(con->_packet.data_size), uint32_t(compared)); |
105 | } |
106 | |
107 | return GEARMAN_SUCCESS; |
108 | |
109 | === modified file 'libgearman/connection.cc' |
110 | --- libgearman/connection.cc 2013-06-28 05:25:57 +0000 |
111 | +++ libgearman/connection.cc 2013-06-30 02:51:26 +0000 |
112 | @@ -433,8 +433,10 @@ |
113 | |
114 | if (gearman_failed(ret)) |
115 | { |
116 | + assert(universal.error_code()); |
117 | + assert(universal.error()); |
118 | gearman_packet_free(&message); |
119 | - return gearman_error(universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "gearman_packet_create_args()"); |
120 | + return universal.error_code(); |
121 | } |
122 | |
123 | PUSH_BLOCKING(universal); |
124 | @@ -442,8 +444,10 @@ |
125 | ret= _send_packet(message, true); |
126 | if (gearman_failed(ret)) |
127 | { |
128 | + assert(universal.error_code()); |
129 | + assert(universal.error()); |
130 | gearman_packet_free(&message); |
131 | - return gearman_error(universal, ret, "Failed to send server-options packet"); |
132 | + return universal.error_code(); |
133 | } |
134 | |
135 | options.packet_in_use= true; |
136 | @@ -718,7 +722,7 @@ |
137 | { |
138 | type|= SOCK_NONBLOCK; |
139 | } |
140 | - |
141 | + |
142 | fd= socket(addrinfo_next->ai_family, type, addrinfo_next->ai_protocol); |
143 | } |
144 | |
145 | @@ -946,11 +950,12 @@ |
146 | return NULL; |
147 | } |
148 | |
149 | + // This should not fail |
150 | _recv_packet= gearman_packet_create(universal, packet_arg); |
151 | assert(_recv_packet == &packet_arg); |
152 | if (_recv_packet == NULL) |
153 | { |
154 | - ret= gearman_error(universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "gearman_packet_create()"); |
155 | + ret= gearman_error(universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "Programmer error, gearman_packet_create() failed which should not be possible"); |
156 | return NULL; |
157 | } |
158 | |
159 | @@ -974,6 +979,7 @@ |
160 | } |
161 | else if (ret != GEARMAN_IO_WAIT) |
162 | { |
163 | + assert(universal.error_code()); |
164 | close_socket(); |
165 | return NULL; |
166 | } |
167 | @@ -1025,8 +1031,8 @@ |
168 | while (recv_data_size) |
169 | { |
170 | (void)receive_data(static_cast<uint8_t *>(const_cast<void *>(packet_arg.data)) + |
171 | - recv_data_offset, |
172 | - packet_arg.data_size -recv_data_offset, ret); |
173 | + recv_data_offset, |
174 | + packet_arg.data_size -recv_data_offset, ret); |
175 | if (gearman_failed(ret)) |
176 | { |
177 | return NULL; |
178 | |
179 | === modified file 'libgearman/error.cc' |
180 | --- libgearman/error.cc 2013-05-12 21:37:25 +0000 |
181 | +++ libgearman/error.cc 2013-06-30 02:51:26 +0000 |
182 | @@ -48,6 +48,9 @@ |
183 | #include <cstdio> |
184 | #include <cstring> |
185 | |
186 | +#include <sys/types.h> |
187 | +#include <unistd.h> |
188 | + |
189 | static void correct_from_errno(gearman_universal_st& universal) |
190 | { |
191 | if (universal.error_code() == GEARMAN_ERRNO) |
192 | @@ -93,9 +96,9 @@ |
193 | const char *position, |
194 | const char *format, ...) |
195 | { |
196 | - if (rc == GEARMAN_SUCCESS) |
197 | + if (rc == GEARMAN_SUCCESS or rc == GEARMAN_IO_WAIT) |
198 | { |
199 | - return GEARMAN_SUCCESS; |
200 | + return universal._error.rc= rc; |
201 | } |
202 | |
203 | va_list args; |
204 | @@ -115,7 +118,8 @@ |
205 | universal._error.last_error[GEARMAN_MAX_ERROR_SIZE -1]= 0; |
206 | } |
207 | |
208 | - length= snprintf(universal._error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) %s -> %s", function, gearman_strerror(universal._error.rc), last_error, position); |
209 | + length= snprintf(universal._error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) %s -> %s pid(%u)", |
210 | + function, gearman_strerror(universal._error.rc), last_error, position, getpid()); |
211 | if (length > int(GEARMAN_MAX_ERROR_SIZE) or length < 0) |
212 | { |
213 | assert(length > int(GEARMAN_MAX_ERROR_SIZE)); |
214 | @@ -139,19 +143,19 @@ |
215 | { |
216 | if (rc == GEARMAN_SUCCESS or rc == GEARMAN_IO_WAIT) |
217 | { |
218 | - return rc; |
219 | + return universal._error.rc= rc; |
220 | } |
221 | |
222 | universal._error.rc= rc; |
223 | correct_from_errno(universal); |
224 | |
225 | - int length= snprintf(universal._error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) -> %s", func, gearman_strerror(rc), position); |
226 | + int length= snprintf(universal._error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) -> %s pid(%u)", |
227 | + func, gearman_strerror(rc), position, getpid()); |
228 | if (length > int(GEARMAN_MAX_ERROR_SIZE) or length < 0) |
229 | { |
230 | assert(length > int(GEARMAN_MAX_ERROR_SIZE)); |
231 | assert(length < 0); |
232 | universal._error.last_error[GEARMAN_MAX_ERROR_SIZE -1]= 0; |
233 | - return GEARMAN_ARGUMENT_TOO_LARGE; |
234 | } |
235 | |
236 | gearman_log_error(universal, |
237 | @@ -200,11 +204,11 @@ |
238 | int length; |
239 | if (message) |
240 | { |
241 | - length= snprintf(universal._error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) %s -> %s", function, errmsg_ptr, message, position); |
242 | + length= snprintf(universal._error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) %s -> %s pid(%d)", function, errmsg_ptr, message, position, getpid()); |
243 | } |
244 | else |
245 | { |
246 | - length= snprintf(universal._error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) -> %s", function, errmsg_ptr, position); |
247 | + length= snprintf(universal._error.last_error, GEARMAN_MAX_ERROR_SIZE, "%s(%s) -> %s pid(%d)", function, errmsg_ptr, position, getpid()); |
248 | } |
249 | |
250 | if (length > int(GEARMAN_MAX_ERROR_SIZE) or length < 0) |
251 | |
252 | === modified file 'libgearman/interface/packet.hpp' |
253 | --- libgearman/interface/packet.hpp 2013-06-27 04:56:49 +0000 |
254 | +++ libgearman/interface/packet.hpp 2013-06-30 02:51:26 +0000 |
255 | @@ -102,7 +102,12 @@ |
256 | return false; |
257 | } |
258 | |
259 | - const char* value(size_t& length_) |
260 | + size_t size() const |
261 | + { |
262 | + return data_size; |
263 | + } |
264 | + |
265 | + const char* value(size_t& length_) const |
266 | { |
267 | length_= data_size; |
268 | |
269 | @@ -114,6 +119,16 @@ |
270 | return NULL; |
271 | } |
272 | |
273 | + const char* value() const |
274 | + { |
275 | + if (data_size) |
276 | + { |
277 | + return (const char*)data; |
278 | + } |
279 | + |
280 | + return NULL; |
281 | + } |
282 | + |
283 | void reset() |
284 | { |
285 | if (args != args_buffer and args) |
286 | |
287 | === modified file 'libgearman/log.hpp' |
288 | --- libgearman/log.hpp 2013-05-12 20:30:19 +0000 |
289 | +++ libgearman/log.hpp 2013-06-30 02:51:26 +0000 |
290 | @@ -65,7 +65,7 @@ |
291 | /** |
292 | * Log an info message, see gearman_log() for argument details. |
293 | */ |
294 | -void gearman_log_info(gearman_universal_st& gearman, const char *format, ...); |
295 | +void gearman_log_info(gearman_universal_st&, const char *format, ...); |
296 | |
297 | /** |
298 | * Log a debug message, see gearman_log() for argument details. |
299 | |
300 | === modified file 'libgearman/packet.cc' |
301 | --- libgearman/packet.cc 2013-06-11 06:48:11 +0000 |
302 | +++ libgearman/packet.cc 2013-06-30 02:51:26 +0000 |
303 | @@ -383,8 +383,7 @@ |
304 | if (packet->command == GEARMAN_COMMAND_TEXT || |
305 | packet->command >= GEARMAN_COMMAND_MAX) |
306 | { |
307 | - gearman_error(*packet->universal, GEARMAN_INVALID_COMMAND, "invalid command value"); |
308 | - return GEARMAN_INVALID_COMMAND; |
309 | + return gearman_error(*packet->universal, GEARMAN_INVALID_COMMAND, "invalid command value"); |
310 | } |
311 | |
312 | memcpy(&tmp, packet->args + 8, 4); |
313 | |
314 | === modified file 'libgearman/universal.cc' |
315 | --- libgearman/universal.cc 2013-06-14 22:43:33 +0000 |
316 | +++ libgearman/universal.cc 2013-06-30 02:51:26 +0000 |
317 | @@ -362,7 +362,7 @@ |
318 | gearman_return_t local_ret= gearman_kill(gearman_universal_id(universal), GEARMAN_INTERRUPT); |
319 | if (gearman_failed(local_ret)) |
320 | { |
321 | - return GEARMAN_SHUTDOWN; |
322 | + return gearman_gerror(universal, GEARMAN_SHUTDOWN); |
323 | } |
324 | |
325 | return GEARMAN_SHUTDOWN_GRACEFUL; |
326 | @@ -370,7 +370,7 @@ |
327 | |
328 | if (read_length == 0) |
329 | { |
330 | - return GEARMAN_SHUTDOWN; |
331 | + return gearman_gerror(universal, GEARMAN_SHUTDOWN); |
332 | } |
333 | |
334 | #if 0 |
335 | @@ -542,7 +542,10 @@ |
336 | gearman_packet_st *packet_ptr= con->receiving(con->_packet, ret, true); |
337 | if (packet_ptr == NULL) |
338 | { |
339 | - assert(&con->_packet == universal.packet_list); |
340 | + if (ret != GEARMAN_NOT_CONNECTED and ret != GEARMAN_LOST_CONNECTION) |
341 | + { |
342 | + assert(&con->_packet == universal.packet_list); |
343 | + } |
344 | con->options.packet_in_use= false; |
345 | break; |
346 | } |
347 | |
348 | === modified file 'libtest/main.cc' |
349 | --- libtest/main.cc 2013-06-05 21:59:31 +0000 |
350 | +++ libtest/main.cc 2013-06-30 02:51:26 +0000 |
351 | @@ -2,7 +2,7 @@ |
352 | * |
353 | * Data Differential YATL (i.e. libtest) library |
354 | * |
355 | - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ |
356 | + * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ |
357 | * |
358 | * Redistribution and use in source and binary forms, with or without |
359 | * modification, are permitted provided that the following conditions are |
360 | |
361 | === modified file 'libtest/run.gdb' |
362 | --- libtest/run.gdb 2013-05-03 06:03:28 +0000 |
363 | +++ libtest/run.gdb 2013-06-30 02:51:26 +0000 |
364 | @@ -2,6 +2,7 @@ |
365 | set logging overwrite on |
366 | set environment LIBTEST_IN_GDB=1 |
367 | #set ASAN_OPTIONS=abort_on_error=1 |
368 | +set detach-on-fork on |
369 | handle SIGVTALRM stop |
370 | run |
371 | thread apply all bt |
372 | |
373 | === modified file 'libtest/stream.h' |
374 | --- libtest/stream.h 2013-06-02 05:10:20 +0000 |
375 | +++ libtest/stream.h 2013-06-30 02:51:26 +0000 |
376 | @@ -42,6 +42,9 @@ |
377 | #include <ctime> |
378 | #include <ostream> |
379 | |
380 | +#include <sys/types.h> |
381 | +#include <unistd.h> |
382 | + |
383 | namespace libtest { |
384 | namespace stream { |
385 | |
386 | @@ -65,7 +68,8 @@ |
387 | << ":" |
388 | << line_number |
389 | << ": in " |
390 | - << func << "() " |
391 | + << func << "() pid(" |
392 | + << getpid() << ") " |
393 | << s.str() |
394 | << std::endl; |
395 | } |
396 | @@ -97,7 +101,8 @@ |
397 | << ":" |
398 | << line_number |
399 | << ": in " |
400 | - << func << "() " |
401 | + << func << "() pid(" |
402 | + << getpid() << ") " |
403 | << s.str() |
404 | << std::endl; |
405 | } |
406 | |
407 | === modified file 'tests/libgearman-1.0/client_test.cc' |
408 | --- tests/libgearman-1.0/client_test.cc 2013-06-05 21:59:31 +0000 |
409 | +++ tests/libgearman-1.0/client_test.cc 2013-06-30 02:51:26 +0000 |
410 | @@ -75,6 +75,7 @@ |
411 | #include "tests/execute.h" |
412 | #include "tests/gearman_client_do_job_handle.h" |
413 | #include "tests/gearman_execute_partition.h" |
414 | +#include "tests/libgearman-1.0/fork.h" |
415 | #include "tests/protocol.h" |
416 | #include "tests/regression.h" |
417 | #include "tests/task.h" |
418 | @@ -2139,6 +2140,11 @@ |
419 | return TEST_SUCCESS; |
420 | } |
421 | |
422 | +test_st client_fork_TESTS[] ={ |
423 | + {"fork()", 0, check_client_fork_TEST }, |
424 | + {0, 0, 0} |
425 | +}; |
426 | + |
427 | test_st gearman_client_add_server_TESTS[] ={ |
428 | {"gearman_client_add_server(localhost)", 0, gearman_client_add_server_localhost_TEST }, |
429 | {"gearman_client_add_server(empty quote)", 0, gearman_client_add_server_empty_quote_TEST }, |
430 | @@ -2496,6 +2502,7 @@ |
431 | {"gearman_execute_partition(GEARMAN_CLIENT_FREE_TASKS)", partition_free_SETUP, 0, gearman_execute_partition_tests}, |
432 | {"gearman_command_t", 0, 0, gearman_command_t_tests}, |
433 | {"coalescence", 0, 0, coalescence_TESTS}, |
434 | + {"fork", fork_SETUP, 0, client_fork_TESTS }, |
435 | {"loop", 0, 0, loop_TESTS}, |
436 | {"limits", 0, 0, limit_tests }, |
437 | {"client-logging", pre_logging, 0, tests_log_TESTS }, |
438 | |
439 | === added file 'tests/libgearman-1.0/fork.cc' |
440 | --- tests/libgearman-1.0/fork.cc 1970-01-01 00:00:00 +0000 |
441 | +++ tests/libgearman-1.0/fork.cc 2013-06-30 02:51:26 +0000 |
442 | @@ -0,0 +1,118 @@ |
443 | +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
444 | + * |
445 | + * Gearmand client and server library. |
446 | + * |
447 | + * Copyright (C) 2013 Data Differential, http://datadifferential.com/ |
448 | + * All rights reserved. |
449 | + * |
450 | + * Redistribution and use in source and binary forms, with or without |
451 | + * modification, are permitted provided that the following conditions are |
452 | + * met: |
453 | + * |
454 | + * * Redistributions of source code must retain the above copyright |
455 | + * notice, this list of conditions and the following disclaimer. |
456 | + * |
457 | + * * Redistributions in binary form must reproduce the above |
458 | + * copyright notice, this list of conditions and the following disclaimer |
459 | + * in the documentation and/or other materials provided with the |
460 | + * distribution. |
461 | + * |
462 | + * * The names of its contributors may not be used to endorse or |
463 | + * promote products derived from this software without specific prior |
464 | + * written permission. |
465 | + * |
466 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
467 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
468 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
469 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
470 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
471 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
472 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
473 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
474 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
475 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
476 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
477 | + * |
478 | + */ |
479 | + |
480 | +#include "gear_config.h" |
481 | + |
482 | +#include <libtest/test.hpp> |
483 | + |
484 | +#include "libgearman/client.hpp" |
485 | + |
486 | +using namespace org::gearmand; |
487 | +using namespace libtest; |
488 | + |
489 | +#include <cassert> |
490 | +#include <cstdio> |
491 | +#include <cstdlib> |
492 | +#include <cstring> |
493 | +#include <ctime> |
494 | +#include <iostream> |
495 | +#include <vector> |
496 | + |
497 | +test_return_t fork_SETUP(void*) |
498 | +{ |
499 | + return TEST_SUCCESS; |
500 | +} |
501 | + |
502 | +test_return_t check_client_fork_TEST(void*) |
503 | +{ |
504 | + test_skip_valgrind(); |
505 | + |
506 | + libgearman::Client client(libtest::default_port()); |
507 | + |
508 | +#ifdef HAVE_FORK |
509 | + { |
510 | + ASSERT_EQ(GEARMAN_SUCCESS, gearman_client_echo(&client, test_literal_param("begin all forked"))); |
511 | + pid_t child= fork(); |
512 | + |
513 | + switch (child) |
514 | + { |
515 | + case -1: |
516 | + FAIL("fork() failed with %s", strerror(errno)); |
517 | + |
518 | + case 0: |
519 | + { |
520 | + gearman_return_t ret; |
521 | + if (gearman_failed(ret= gearman_client_echo(&client, test_literal_param("child forked")))) |
522 | + { |
523 | + Error << gearman_client_error(&client); |
524 | + exit(int(ret)); |
525 | + } |
526 | + exit(0); |
527 | + } |
528 | + |
529 | + default: |
530 | + { |
531 | + int exit_code= EXIT_FAILURE; |
532 | + int status; |
533 | + if (waitpid(child, &status, 0) == -1) |
534 | + { |
535 | + FAIL("waitpid() failed with %s", strerror(errno)); |
536 | + } |
537 | + else |
538 | + { |
539 | + if (WIFEXITED(status)) |
540 | + { |
541 | + exit_code= WEXITSTATUS(status); |
542 | + } |
543 | + |
544 | + if (WIFSIGNALED(status)) |
545 | + { |
546 | + FAIL("child was killed by signal %s", strsignal(WTERMSIG(status))); |
547 | + } |
548 | + ASSERT_EQ(EXIT_SUCCESS, exit_code); |
549 | + } |
550 | + |
551 | + ASSERT_EQ(GEARMAN_LOST_CONNECTION, gearman_client_echo(&client, test_literal_param("parent forked"))); |
552 | + } |
553 | + } |
554 | + return TEST_SUCCESS; |
555 | + } |
556 | +#else |
557 | + |
558 | + return TEST_SKIPPED; |
559 | +#endif // HAVE_FORK |
560 | +} |
561 | |
562 | === added file 'tests/libgearman-1.0/fork.h' |
563 | --- tests/libgearman-1.0/fork.h 1970-01-01 00:00:00 +0000 |
564 | +++ tests/libgearman-1.0/fork.h 2013-06-30 02:51:26 +0000 |
565 | @@ -0,0 +1,42 @@ |
566 | +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
567 | + * |
568 | + * Gearmand client and server library. |
569 | + * |
570 | + * Copyright (C) 2013 Data Differential, http://datadifferential.com/ |
571 | + * All rights reserved. |
572 | + * |
573 | + * Redistribution and use in source and binary forms, with or without |
574 | + * modification, are permitted provided that the following conditions are |
575 | + * met: |
576 | + * |
577 | + * * Redistributions of source code must retain the above copyright |
578 | + * notice, this list of conditions and the following disclaimer. |
579 | + * |
580 | + * * Redistributions in binary form must reproduce the above |
581 | + * copyright notice, this list of conditions and the following disclaimer |
582 | + * in the documentation and/or other materials provided with the |
583 | + * distribution. |
584 | + * |
585 | + * * The names of its contributors may not be used to endorse or |
586 | + * promote products derived from this software without specific prior |
587 | + * written permission. |
588 | + * |
589 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
590 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
591 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
592 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
593 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
594 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
595 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
596 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
597 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
598 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
599 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
600 | + * |
601 | + */ |
602 | + |
603 | +#pragma once |
604 | + |
605 | +test_return_t fork_SETUP(void*); |
606 | + |
607 | +test_return_t check_client_fork_TEST(void*); |
608 | |
609 | === modified file 'tests/libgearman-1.0/include.am' |
610 | --- tests/libgearman-1.0/include.am 2013-05-16 17:11:24 +0000 |
611 | +++ tests/libgearman-1.0/include.am 2013-06-30 02:51:26 +0000 |
612 | @@ -1,6 +1,7 @@ |
613 | # vim:ft=automake |
614 | |
615 | noinst_HEADERS+= tests/libgearman-1.0/client_test.h |
616 | +noinst_HEADERS+= tests/libgearman-1.0/fork.h |
617 | noinst_HEADERS+= tests/libgearman-1.0/gearman_client_job_status_by_unique.h |
618 | noinst_HEADERS+= tests/libgearman-1.0/multi_client_test.h |
619 | |
620 | @@ -19,6 +20,7 @@ |
621 | tests_libgearman_1_0_client_test_SOURCES+= tests/libgearman-1.0/do.cc |
622 | tests_libgearman_1_0_client_test_SOURCES+= tests/libgearman-1.0/do_background.cc |
623 | tests_libgearman_1_0_client_test_SOURCES+= tests/libgearman-1.0/execute.cc |
624 | +tests_libgearman_1_0_client_test_SOURCES+= tests/libgearman-1.0/fork.cc |
625 | tests_libgearman_1_0_client_test_SOURCES+= tests/libgearman-1.0/gearman_client_do_job_handle.cc |
626 | tests_libgearman_1_0_client_test_SOURCES+= tests/libgearman-1.0/gearman_client_job_status_by_unique.cc |
627 | tests_libgearman_1_0_client_test_SOURCES+= tests/libgearman-1.0/gearman_execute_partition.cc |