Merge lp:~brianaker/gearmand/worker-background-test into lp:gearmand

Proposed by Brian Aker on 2013-06-11
Status: Merged
Merged at revision: 766
Proposed branch: lp:~brianaker/gearmand/worker-background-test
Merge into: lp:gearmand
Diff against target: 91 lines (+74/-0)
1 file modified
tests/libgearman-1.0/worker_test.cc (+74/-0)
To merge this branch: bzr merge lp:~brianaker/gearmand/worker-background-test
Reviewer Review Type Date Requested Status
Tangent Trunk 2013-06-11 Pending
Review via email: mp+168656@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 'tests/libgearman-1.0/worker_test.cc'
2--- tests/libgearman-1.0/worker_test.cc 2013-06-10 22:49:06 +0000
3+++ tests/libgearman-1.0/worker_test.cc 2013-06-11 12:33:33 +0000
4@@ -483,6 +483,79 @@
5 }
6 #pragma GCC diagnostic pop
7
8+#pragma GCC diagnostic push
9+#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
10+static test_return_t job_order_background_TEST(void *)
11+{
12+ libgearman::Client client(libtest::default_port());
13+ ASSERT_EQ(true, gearman_client_set_server_option(&client, test_literal_param("exceptions")));
14+ gearman_client_add_options(&client, GEARMAN_CLIENT_EXCEPTION);
15+ gearman_client_add_options(&client, GEARMAN_CLIENT_GENERATE_UNIQUE);
16+
17+ libgearman::Worker worker(libtest::default_port());
18+ ASSERT_EQ(gearman_worker_register(&worker, __func__, 0), GEARMAN_SUCCESS);
19+
20+ std::vector<gearman_task_st*> tasks;
21+ const uint32_t order_seed= __LINE__;
22+ uint32_t spaces= 0;
23+ for (uint32_t x= order_seed +10; x != order_seed; --x)
24+ {
25+ gearman_return_t ret;
26+ char buffer[30];
27+ memset(buffer, 0, sizeof(buffer));
28+ int buffer_length= snprintf(buffer, sizeof(buffer), "%u", x);
29+ for (uint32_t y= 0; y <= spaces; ++y)
30+ {
31+ buffer[buffer_length +y]= ' ';
32+ }
33+ ++spaces;
34+ gearman_task_st* task= gearman_client_add_task_background(&client,
35+ NULL, // task
36+ NULL, // context
37+ __func__, // function_name,
38+ NULL, // unique
39+ buffer, // workload
40+ size_t(buffer_length +1 +spaces), // length of workload
41+ &ret);
42+ ASSERT_EQ(GEARMAN_SUCCESS, ret);
43+ ASSERT_TRUE(task);
44+ tasks.push_back(task);
45+ }
46+
47+ {
48+ gearman_return_t ret;
49+ do {
50+ ret= gearman_client_run_tasks(&client);
51+ } while (gearman_continue(ret));
52+ ASSERT_EQ(GEARMAN_SUCCESS, ret);
53+ }
54+
55+ for (std::vector<gearman_task_st*>::iterator iter= tasks.begin();
56+ iter != tasks.end(); ++iter)
57+ {
58+ if (gearman_task_return(*iter) != GEARMAN_UNKNOWN_STATE)
59+ {
60+ Error << ":" << gearman_task_error(*iter) << ":";
61+ Error << ":" << gearman_strerror(gearman_task_return(*iter)) << ":";
62+ }
63+ ASSERT_EQ(GEARMAN_UNKNOWN_STATE, gearman_task_return(*iter));
64+ ASSERT_NULL(gearman_task_error(*iter));
65+ }
66+
67+ for (uint32_t x= 0; x < 10; ++x)
68+ {
69+ gearman_return_t ret;
70+ gearman_job_st* job= gearman_worker_grab_job(&worker, NULL, &ret);
71+ (void)job;
72+ ASSERT_TRUE(job);
73+ ASSERT_EQ(GEARMAN_SUCCESS, ret);
74+ ASSERT_EQ(GEARMAN_SUCCESS, gearman_job_send_exception(job, test_literal_param("returned exception")));
75+ }
76+
77+ return TEST_SUCCESS;
78+}
79+#pragma GCC diagnostic pop
80+
81 static test_return_t echo_max_test(void *)
82 {
83 libgearman::Worker worker(libtest::default_port());;
84@@ -1449,6 +1522,7 @@
85 {"gearman_job_send_exception()", 0, gearman_job_send_exception_TEST },
86 {"gearman_job_send_exception(mass)", 0, gearman_job_send_exception_mass_TEST },
87 {"job order", 0, job_order_TEST },
88+ {"job background order", 0, job_order_background_TEST },
89 {"echo_max", 0, echo_max_test },
90 {"abandoned_worker", 0, abandoned_worker_test },
91 {0, 0, 0}

Subscribers

People subscribed via source and target branches

to all changes: