Merge lp:~clint-fewbar/ubuntu/precise/zookeeper/run-unit-tests into lp:ubuntu/precise/zookeeper

Proposed by Clint Byrum
Status: Merged
Merge reported by: James Page
Merged at revision: not available
Proposed branch: lp:~clint-fewbar/ubuntu/precise/zookeeper/run-unit-tests
Merge into: lp:ubuntu/precise/zookeeper
Diff against target: 400 lines (+340/-1)
7 files modified
.pc/applied-patches (+1/-0)
.pc/fix-broken-c-client-unittest.patch/src/c/tests/TestZookeeperInit.cc (+301/-0)
debian/changelog (+9/-0)
debian/patches/fix-broken-c-client-unittest.patch (+20/-0)
debian/patches/series (+1/-0)
debian/rules (+7/-0)
src/c/tests/TestZookeeperInit.cc (+1/-1)
To merge this branch: bzr merge lp:~clint-fewbar/ubuntu/precise/zookeeper/run-unit-tests
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+87822@code.launchpad.net

Description of the change

Runs the unit tests that make sense (zkpython's is a bit broken for automated running) on package build. This is to support the ZK MIR.

To post a comment you must log in.
Revision history for this message
Clint Byrum (clint-fewbar) wrote :

Heh, and now I just saw where you've already added more elaborate code to do this into debian/rules, but commented out.

The C patch is necessary, but it looks like maybe your code has some other things that I hadn't thought of.

Revision history for this message
James Page (james-page) wrote :

Included ages ago!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.pc/applied-patches'
2--- .pc/applied-patches 2011-12-01 15:03:53 +0000
3+++ .pc/applied-patches 2012-01-06 22:06:25 +0000
4@@ -2,3 +2,4 @@
5 debian/patch-build-system
6 fixes/ZOOKEEPER-705
7 fixes/ZOOKEEPER-1033
8+fix-broken-c-client-unittest.patch
9
10=== added directory '.pc/fix-broken-c-client-unittest.patch'
11=== added directory '.pc/fix-broken-c-client-unittest.patch/src'
12=== added directory '.pc/fix-broken-c-client-unittest.patch/src/c'
13=== added directory '.pc/fix-broken-c-client-unittest.patch/src/c/tests'
14=== added file '.pc/fix-broken-c-client-unittest.patch/src/c/tests/TestZookeeperInit.cc'
15--- .pc/fix-broken-c-client-unittest.patch/src/c/tests/TestZookeeperInit.cc 1970-01-01 00:00:00 +0000
16+++ .pc/fix-broken-c-client-unittest.patch/src/c/tests/TestZookeeperInit.cc 2012-01-06 22:06:25 +0000
17@@ -0,0 +1,301 @@
18+/**
19+ * Licensed to the Apache Software Foundation (ASF) under one
20+ * or more contributor license agreements. See the NOTICE file
21+ * distributed with this work for additional information
22+ * regarding copyright ownership. The ASF licenses this file
23+ * to you under the Apache License, Version 2.0 (the
24+ * "License"); you may not use this file except in compliance
25+ * with the License. You may obtain a copy of the License at
26+ *
27+ * http://www.apache.org/licenses/LICENSE-2.0
28+ *
29+ * Unless required by applicable law or agreed to in writing, software
30+ * distributed under the License is distributed on an "AS IS" BASIS,
31+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32+ * See the License for the specific language governing permissions and
33+ * limitations under the License.
34+ */
35+
36+#include <cppunit/extensions/HelperMacros.h>
37+#include <sys/types.h>
38+#include <netinet/in.h>
39+#include <errno.h>
40+
41+#include "Util.h"
42+#include "LibCMocks.h"
43+#include "ZKMocks.h"
44+
45+#ifdef THREADED
46+#include "PthreadMocks.h"
47+#else
48+class MockPthreadsNull;
49+#endif
50+
51+using namespace std;
52+
53+class Zookeeper_init : public CPPUNIT_NS::TestFixture
54+{
55+ CPPUNIT_TEST_SUITE(Zookeeper_init);
56+ CPPUNIT_TEST(testBasic);
57+ CPPUNIT_TEST(testAddressResolution);
58+ CPPUNIT_TEST(testMultipleAddressResolution);
59+ CPPUNIT_TEST(testNullAddressString);
60+ CPPUNIT_TEST(testEmptyAddressString);
61+ CPPUNIT_TEST(testOneSpaceAddressString);
62+ CPPUNIT_TEST(testTwoSpacesAddressString);
63+ CPPUNIT_TEST(testInvalidAddressString1);
64+ CPPUNIT_TEST(testInvalidAddressString2);
65+ CPPUNIT_TEST(testNonexistentHost);
66+ CPPUNIT_TEST(testOutOfMemory_init);
67+ CPPUNIT_TEST(testOutOfMemory_getaddrs1);
68+#if !defined(__CYGWIN__) // not valid for cygwin
69+ CPPUNIT_TEST(testOutOfMemory_getaddrs2);
70+#endif
71+ CPPUNIT_TEST(testPermuteAddrsList);
72+ CPPUNIT_TEST_SUITE_END();
73+ zhandle_t *zh;
74+ MockPthreadsNull* pthreadMock;
75+ static void watcher(zhandle_t *, int , int , const char *,void*){}
76+ FILE *logfile;
77+public:
78+ Zookeeper_init():zh(0),pthreadMock(0){
79+ logfile = openlogfile("Zookeeper_init");
80+ }
81+
82+ ~Zookeeper_init() {
83+ if (logfile) {
84+ fflush(logfile);
85+ fclose(logfile);
86+ logfile = 0;
87+ }
88+ }
89+
90+ void setUp()
91+ {
92+ zoo_set_log_stream(logfile);
93+
94+ zoo_deterministic_conn_order(0);
95+#ifdef THREADED
96+ // disable threading
97+ pthreadMock=new MockPthreadZKNull;
98+#endif
99+ zh=0;
100+ }
101+
102+ void tearDown()
103+ {
104+ zookeeper_close(zh);
105+#ifdef THREADED
106+ delete pthreadMock;
107+#endif
108+ }
109+
110+ void testBasic()
111+ {
112+ const string EXPECTED_HOST("127.0.0.1:2121");
113+ const int EXPECTED_ADDRS_COUNT =1;
114+ const int EXPECTED_RECV_TIMEOUT=10000;
115+ clientid_t cid;
116+ memset(&cid,0xFE,sizeof(cid));
117+
118+ zh=zookeeper_init(EXPECTED_HOST.c_str(),watcher,EXPECTED_RECV_TIMEOUT,
119+ &cid,(void*)1,0);
120+
121+ CPPUNIT_ASSERT(zh!=0);
122+ CPPUNIT_ASSERT(zh->fd == -1);
123+ CPPUNIT_ASSERT(zh->hostname!=0);
124+ CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDRS_COUNT,zh->addrs_count);
125+ CPPUNIT_ASSERT_EQUAL(EXPECTED_HOST,string(zh->hostname));
126+ CPPUNIT_ASSERT(zh->state == 0);
127+ CPPUNIT_ASSERT(zh->context == (void*)1);
128+ CPPUNIT_ASSERT_EQUAL(EXPECTED_RECV_TIMEOUT,zh->recv_timeout);
129+ CPPUNIT_ASSERT(zh->watcher == watcher);
130+ CPPUNIT_ASSERT(zh->connect_index==0);
131+ CPPUNIT_ASSERT(zh->primer_buffer.buffer==zh->primer_storage_buffer);
132+ CPPUNIT_ASSERT(zh->primer_buffer.curr_offset ==0);
133+ CPPUNIT_ASSERT(zh->primer_buffer.len == sizeof(zh->primer_storage_buffer));
134+ CPPUNIT_ASSERT(zh->primer_buffer.next == 0);
135+ CPPUNIT_ASSERT(zh->last_zxid ==0);
136+ CPPUNIT_ASSERT(memcmp(&zh->client_id,&cid,sizeof(cid))==0);
137+
138+#ifdef THREADED
139+ // thread specific checks
140+ adaptor_threads* adaptor=(adaptor_threads*)zh->adaptor_priv;
141+ CPPUNIT_ASSERT(adaptor!=0);
142+ CPPUNIT_ASSERT(pthreadMock->pthread_createCounter==2);
143+ CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(adaptor->io));
144+ CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(adaptor->completion));
145+ CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(&zh->to_process.lock));
146+ CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(&zh->to_send.lock));
147+ CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(&zh->sent_requests.lock));
148+ CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(&zh->completions_to_process.lock));
149+ CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(&zh->sent_requests.cond));
150+ CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(&zh->completions_to_process.cond));
151+#endif
152+ }
153+ void testAddressResolution()
154+ {
155+ const char EXPECTED_IPS[][4]={{127,0,0,1}};
156+ const int EXPECTED_ADDRS_COUNT =COUNTOF(EXPECTED_IPS);
157+
158+ zoo_deterministic_conn_order(1);
159+ zh=zookeeper_init("127.0.0.1:2121",0,10000,0,0,0);
160+
161+ CPPUNIT_ASSERT(zh!=0);
162+ CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDRS_COUNT,zh->addrs_count);
163+ for(int i=0;i<zh->addrs_count;i++){
164+ sockaddr_in* addr=(struct sockaddr_in*)&zh->addrs[i];
165+ CPPUNIT_ASSERT(memcmp(EXPECTED_IPS[i],&addr->sin_addr,sizeof(addr->sin_addr))==0);
166+ CPPUNIT_ASSERT_EQUAL(2121,(int)ntohs(addr->sin_port));
167+ }
168+ }
169+ void testMultipleAddressResolution()
170+ {
171+ const string EXPECTED_HOST("127.0.0.1:2121,127.0.0.2:3434");
172+ const char EXPECTED_IPS[][4]={{127,0,0,1},{127,0,0,2}};
173+ const int EXPECTED_ADDRS_COUNT =COUNTOF(EXPECTED_IPS);
174+
175+ zoo_deterministic_conn_order(1);
176+ zh=zookeeper_init(EXPECTED_HOST.c_str(),0,1000,0,0,0);
177+
178+ CPPUNIT_ASSERT(zh!=0);
179+ CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDRS_COUNT,zh->addrs_count);
180+
181+ for(int i=0;i<zh->addrs_count;i++){
182+ sockaddr_in* addr=(struct sockaddr_in*)&zh->addrs[i];
183+ CPPUNIT_ASSERT(memcmp(EXPECTED_IPS[i],&addr->sin_addr,sizeof(addr->sin_addr))==0);
184+ if(i<1)
185+ CPPUNIT_ASSERT_EQUAL(2121,(int)ntohs(addr->sin_port));
186+ else
187+ CPPUNIT_ASSERT_EQUAL(3434,(int)ntohs(addr->sin_port));
188+ }
189+ }
190+ void testMultipleAddressWithSpace()
191+ {
192+ const string EXPECTED_HOST("127.0.0.1:2121, 127.0.0.2:3434");
193+ const char EXPECTED_IPS[][4]={{127,0,0,1},{127,0,0,2}};
194+ const int EXPECTED_ADDRS_COUNT =COUNTOF(EXPECTED_IPS);
195+
196+ zoo_deterministic_conn_order(1);
197+ zh=zookeeper_init(EXPECTED_HOST.c_str(),0,1000,0,0,0);
198+
199+ CPPUNIT_ASSERT(zh!=0);
200+ CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDRS_COUNT,zh->addrs_count);
201+
202+ for(int i=0;i<zh->addrs_count;i++){
203+ sockaddr_in* addr=(struct sockaddr_in*)&zh->addrs[i];
204+ CPPUNIT_ASSERT(memcmp(EXPECTED_IPS[i],&addr->sin_addr,sizeof(addr->sin_addr))==0);
205+ if(i<1)
206+ CPPUNIT_ASSERT_EQUAL(2121,(int)ntohs(addr->sin_port));
207+ else
208+ CPPUNIT_ASSERT_EQUAL(3434,(int)ntohs(addr->sin_port));
209+ }
210+ }
211+ void testNullAddressString()
212+ {
213+ zh=zookeeper_init(NULL,0,0,0,0,0);
214+ CPPUNIT_ASSERT(zh==0);
215+ CPPUNIT_ASSERT_EQUAL(EINVAL,errno);
216+ }
217+ void testEmptyAddressString()
218+ {
219+ const string INVALID_HOST("");
220+ zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0);
221+ CPPUNIT_ASSERT(zh==0);
222+ CPPUNIT_ASSERT_EQUAL(EINVAL,errno);
223+ }
224+ void testOneSpaceAddressString()
225+ {
226+ const string INVALID_HOST(" ");
227+ zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0);
228+ CPPUNIT_ASSERT(zh==0);
229+ CPPUNIT_ASSERT_EQUAL(EINVAL,errno);
230+ }
231+ void testTwoSpacesAddressString()
232+ {
233+ const string INVALID_HOST(" ");
234+ zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0);
235+ CPPUNIT_ASSERT(zh==0);
236+ CPPUNIT_ASSERT_EQUAL(EINVAL,errno);
237+ }
238+ void testInvalidAddressString1()
239+ {
240+ const string INVALID_HOST("host1");
241+ zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0);
242+ CPPUNIT_ASSERT(zh==0);
243+ CPPUNIT_ASSERT_EQUAL(EINVAL,errno);
244+ }
245+ void testInvalidAddressString2()
246+ {
247+ const string INVALID_HOST("host1:1111+host:123");
248+ zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0);
249+ CPPUNIT_ASSERT(zh==0);
250+ CPPUNIT_ASSERT_EQUAL(ENOENT,errno);
251+ }
252+ void testNonexistentHost()
253+ {
254+ const string EXPECTED_HOST("host1.blabadibla.bla.:1111");
255+
256+ zh=zookeeper_init(EXPECTED_HOST.c_str(),0,0,0,0,0);
257+
258+ CPPUNIT_ASSERT(zh==0);
259+ //With the switch to thread safe getaddrinfo, we don't get
260+ //these global variables
261+ //CPPUNIT_ASSERT_EQUAL(EINVAL,errno);
262+ //CPPUNIT_ASSERT_EQUAL(HOST_NOT_FOUND,h_errno);
263+ }
264+ void testOutOfMemory_init()
265+ {
266+ Mock_calloc mock;
267+ mock.callsBeforeFailure=0; // fail first calloc in init()
268+
269+ zh=zookeeper_init("ahost:123",watcher,10000,0,0,0);
270+
271+ CPPUNIT_ASSERT(zh==0);
272+ CPPUNIT_ASSERT_EQUAL(ENOMEM,errno);
273+ }
274+ void testOutOfMemory_getaddrs1()
275+ {
276+ Mock_realloc reallocMock;
277+ reallocMock.callsBeforeFailure=0; // fail on first call to realloc
278+
279+ zh=zookeeper_init("127.0.0.1:123",0,0,0,0,0);
280+
281+ CPPUNIT_ASSERT(zh==0);
282+ CPPUNIT_ASSERT_EQUAL(ENOMEM,errno);
283+ }
284+ void testOutOfMemory_getaddrs2()
285+ {
286+ Mock_realloc reallocMock;
287+ reallocMock.callsBeforeFailure=1; // fail on the second call to realloc
288+
289+ zh=zookeeper_init("127.0.0.1:123,127.0.0.2:123,127.0.0.3:123,127.0.0.4:123,127.0.0.5:123,127.0.0.6:123,127.0.0.7:123,127.0.0.8:123,127.0.0.9:123,127.0.0.10:123,127.0.0.11:123,127.0.0.12:123,127.0.0.13:123,127.0.0.14:123,127.0.0.15:123,127.0.0.16:123,127.0.0.17:123",0,0,0,0,0);
290+
291+ CPPUNIT_ASSERT(zh==0);
292+ CPPUNIT_ASSERT_EQUAL(ENOMEM,errno);
293+ }
294+ void testPermuteAddrsList()
295+ {
296+ const char EXPECTED[][5]={"\0\0\0\0","\1\1\1\1","\2\2\2\2","\3\3\3\3"};
297+ const int EXPECTED_ADDR_COUNT=COUNTOF(EXPECTED);
298+
299+ const int RAND_SEQ[]={0,1,2,3,1,3,2,0,-1};
300+ const int RAND_SIZE=COUNTOF(RAND_SEQ);
301+ Mock_random randomMock;
302+ randomMock.randomReturns.assign(RAND_SEQ,RAND_SEQ+RAND_SIZE-1);
303+ zh=zookeeper_init("0.0.0.0:123,1.1.1.1:123,2.2.2.2:123,3.3.3.3:123",0,1000,0,0,0);
304+
305+ CPPUNIT_ASSERT(zh!=0);
306+ CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDR_COUNT,zh->addrs_count);
307+ const string EXPECTED_SEQ("3210");
308+ char ACTUAL_SEQ[EXPECTED_ADDR_COUNT+1]; ACTUAL_SEQ[EXPECTED_ADDR_COUNT]=0;
309+ for(int i=0;i<zh->addrs_count;i++){
310+ sockaddr_in* addr=(struct sockaddr_in*)&zh->addrs[i];
311+ // match the first byte of the EXPECTED and of the actual address
312+ ACTUAL_SEQ[i]=((char*)&addr->sin_addr)[0]+'0';
313+ }
314+ CPPUNIT_ASSERT_EQUAL(EXPECTED_SEQ,string(ACTUAL_SEQ));
315+ }
316+};
317+
318+CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_init);
319
320=== modified file 'debian/changelog'
321--- debian/changelog 2011-12-01 15:03:53 +0000
322+++ debian/changelog 2012-01-06 22:06:25 +0000
323@@ -1,3 +1,12 @@
324+zookeeper (3.3.4+dfsg1-1ubuntu1) UNRELEASED; urgency=low
325+
326+ * d/patches/fix-broken-c-client-test.patch: Fixes the unit test so it
327+ will pass with EINVAL which is the correct error. (LP: #912935)
328+ * d/rules: fail package build on failure of C client unit test or of
329+ main zookeper java unit test suite.
330+
331+ -- Clint Byrum <clint@ubuntu.com> Fri, 06 Jan 2012 13:58:23 -0800
332+
333 zookeeper (3.3.4+dfsg1-1) unstable; urgency=low
334
335 [ James Page ]
336
337=== added file 'debian/patches/fix-broken-c-client-unittest.patch'
338--- debian/patches/fix-broken-c-client-unittest.patch 1970-01-01 00:00:00 +0000
339+++ debian/patches/fix-broken-c-client-unittest.patch 2012-01-06 22:06:25 +0000
340@@ -0,0 +1,20 @@
341+Description: Loosens C client unit test to allow multiple errors
342+ The test incorrectly assumes that ENOENT will eb returned on a clearly
343+ incorrectly formatted hostname. Some other C library implementations
344+ may do this, so we accept ENOENT or EINVAL.
345+Author: Clint Byrum <clint@ubuntu.com>
346+Bug: https://issues.apache.org/jira/browse/ZOOKEEPER-1353
347+Bug-Ubuntu: http://pad.lv/912935
348+Forwarded: yes
349+
350+--- zookeeper-3.3.4+dfsg1.orig/src/c/tests/TestZookeeperInit.cc
351++++ zookeeper-3.3.4+dfsg1/src/c/tests/TestZookeeperInit.cc
352+@@ -230,7 +230,7 @@ public:
353+ const string INVALID_HOST("host1:1111+host:123");
354+ zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0);
355+ CPPUNIT_ASSERT(zh==0);
356+- CPPUNIT_ASSERT_EQUAL(ENOENT,errno);
357++ CPPUNIT_ASSERT((ENOENT|EINVAL) & errno);
358+ }
359+ void testNonexistentHost()
360+ {
361
362=== modified file 'debian/patches/series'
363--- debian/patches/series 2011-12-01 15:03:53 +0000
364+++ debian/patches/series 2012-01-06 22:06:25 +0000
365@@ -2,3 +2,4 @@
366 debian/patch-build-system
367 fixes/ZOOKEEPER-705
368 fixes/ZOOKEEPER-1033
369+fix-broken-c-client-unittest.patch
370
371=== modified file 'debian/rules'
372--- debian/rules 2011-12-01 15:03:53 +0000
373+++ debian/rules 2012-01-06 22:06:25 +0000
374@@ -8,6 +8,13 @@
375 %:
376 dh $@ --with javahelper --with python2
377
378+override_dh_auto_test:
379+ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
380+ make -C src/c check
381+ cd src/c ; CLASSPATH=/usr/share/java/log4j-1.2.jar ./zktest-mt
382+ ant test
383+endif
384+
385 override_dh_auto_build:
386 # TODO exclude the fatjar contrib from upstream tarball and include the rest contrib
387 mkdir -p build/test/classes
388
389=== modified file 'src/c/tests/TestZookeeperInit.cc'
390--- src/c/tests/TestZookeeperInit.cc 2010-04-27 13:52:30 +0000
391+++ src/c/tests/TestZookeeperInit.cc 2012-01-06 22:06:25 +0000
392@@ -230,7 +230,7 @@
393 const string INVALID_HOST("host1:1111+host:123");
394 zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0);
395 CPPUNIT_ASSERT(zh==0);
396- CPPUNIT_ASSERT_EQUAL(ENOENT,errno);
397+ CPPUNIT_ASSERT((ENOENT|EINVAL) & errno);
398 }
399 void testNonexistentHost()
400 {

Subscribers

People subscribed via source and target branches

to all changes: