Skip to content

Commit 364baaf

Browse files
committed
Problem: dafka_consumer tests are hard to understand
Solution: Use the cucumber-c library to run gherkin feature files against step definitions implemented by dafka. The first step definitions that was implemented are those for testing the STORE-HELLO and CONSUMER-HELLO protocol commands for the dafka consumer.
1 parent e6fb6c4 commit 364baaf

16 files changed

+508
-22
lines changed

.gitignore

+5-4
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ src/dafka_console_producer
2626
src/dafka_console_consumer
2727
src/dafka_stored
2828
src/dafka_towerd
29-
src/dafka_perf_store
3029
src/dafka_perf_consumer
30+
src/dafka_perf_store
31+
src/dafka_consumer_step_defs
3132
src/dafka_selftest
3233
*.exe
3334
*.out
3435
*.app
3536
core
3637

3738
# Distcheck workspace and archives
38-
dafka-*/
39-
dafka-*.tar.gz
40-
dafka-*.zip
39+
/dafka-*/
40+
/dafka-*.tar.gz
41+
/dafka-*.zip
4142

4243
# Man pages
4344
doc/*.1

CMakeLists.txt

+75-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ enable_testing()
1414
set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
1515
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
1616
# Select flags
17-
SET(CMAKE_C_FLAGS_RELEASE "-O3")
17+
if(MSVC)
18+
SET(CMAKE_C_FLAGS_RELEASE "/O2")
19+
else()
20+
SET(CMAKE_C_FLAGS_RELEASE "-O3")
21+
endif()
1822

1923
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules)
2024

@@ -84,15 +88,17 @@ file(WRITE "${PROJECT_BINARY_DIR}/platform.h.in" "
8488

8589
configure_file("${PROJECT_BINARY_DIR}/platform.h.in" "${PROJECT_BINARY_DIR}/platform.h")
8690

87-
#The MSVC C compiler is too out of date,
88-
#so the sources have to be compiled as c++
89-
if (MSVC)
90-
enable_language(CXX)
91-
file(GLOB sources "${SOURCE_DIR}/src/*.c")
92-
set_source_files_properties(
93-
${sources}
94-
PROPERTIES LANGUAGE CXX
95-
)
91+
if (WIN32)
92+
#The MSVC C compiler is too out of date,
93+
#so the sources have to be compiled as c++
94+
if (MSVC AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
95+
enable_language(CXX)
96+
file(GLOB sources "${SOURCE_DIR}/src/*.c")
97+
set_source_files_properties(
98+
${sources}
99+
PROPERTIES LANGUAGE CXX
100+
)
101+
endif()
96102
set(MORE_LIBRARIES ws2_32 Rpcrt4 Iphlpapi)
97103
endif()
98104

@@ -168,6 +174,23 @@ ELSE (LEVELDB_FOUND)
168174
message( FATAL_ERROR "leveldb not found." )
169175
ENDIF (LEVELDB_FOUND)
170176

177+
########################################################################
178+
# CUCUMBER dependency
179+
########################################################################
180+
find_package(cucumber REQUIRED)
181+
IF (CUCUMBER_FOUND)
182+
include_directories(${CUCUMBER_INCLUDE_DIRS})
183+
list(APPEND MORE_LIBRARIES ${CUCUMBER_LIBRARIES})
184+
IF (PC_CUCUMBER_FOUND)
185+
set(pkg_config_names_private "${pkg_config_names_private} cucumber")
186+
list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_CUCUMBER_STATIC_LDFLAGS})
187+
ELSE (PC_CUCUMBER_FOUND)
188+
set(pkg_config_libs_private "${pkg_config_libs_private} -lcucumber")
189+
ENDIF (PC_CUCUMBER_FOUND)
190+
ELSE (CUCUMBER_FOUND)
191+
message( FATAL_ERROR "cucumber not found." )
192+
ENDIF (CUCUMBER_FOUND)
193+
171194
########################################################################
172195
# version
173196
########################################################################
@@ -400,6 +423,7 @@ target_link_libraries(
400423
${LIBZMQ_LIBRARIES}
401424
${CZMQ_LIBRARIES}
402425
${LEVELDB_LIBRARIES}
426+
${CUCUMBER_LIBRARIES}
403427
${OPTIONAL_LIBRARIES}
404428
)
405429
endif()
@@ -410,6 +434,7 @@ target_link_libraries(
410434
${LIBZMQ_LIBRARIES}
411435
${CZMQ_LIBRARIES}
412436
${LEVELDB_LIBRARIES}
437+
${CUCUMBER_LIBRARIES}
413438
${OPTIONAL_LIBRARIES}
414439
${OPTIONAL_LIBRARIES_STATIC}
415440
)
@@ -428,6 +453,7 @@ target_link_libraries(
428453
${LIBZMQ_LIBRARIES}
429454
${CZMQ_LIBRARIES}
430455
${LEVELDB_LIBRARIES}
456+
${CUCUMBER_LIBRARIES}
431457
${OPTIONAL_LIBRARIES}
432458
)
433459
endif()
@@ -438,6 +464,7 @@ target_link_libraries(
438464
${LIBZMQ_LIBRARIES}
439465
${CZMQ_LIBRARIES}
440466
${LEVELDB_LIBRARIES}
467+
${CUCUMBER_LIBRARIES}
441468
${OPTIONAL_LIBRARIES}
442469
${OPTIONAL_LIBRARIES_STATIC}
443470
)
@@ -456,6 +483,7 @@ target_link_libraries(
456483
${LIBZMQ_LIBRARIES}
457484
${CZMQ_LIBRARIES}
458485
${LEVELDB_LIBRARIES}
486+
${CUCUMBER_LIBRARIES}
459487
${OPTIONAL_LIBRARIES}
460488
)
461489
endif()
@@ -466,6 +494,7 @@ target_link_libraries(
466494
${LIBZMQ_LIBRARIES}
467495
${CZMQ_LIBRARIES}
468496
${LEVELDB_LIBRARIES}
497+
${CUCUMBER_LIBRARIES}
469498
${OPTIONAL_LIBRARIES}
470499
${OPTIONAL_LIBRARIES_STATIC}
471500
)
@@ -484,6 +513,7 @@ target_link_libraries(
484513
${LIBZMQ_LIBRARIES}
485514
${CZMQ_LIBRARIES}
486515
${LEVELDB_LIBRARIES}
516+
${CUCUMBER_LIBRARIES}
487517
${OPTIONAL_LIBRARIES}
488518
)
489519
endif()
@@ -494,6 +524,7 @@ target_link_libraries(
494524
${LIBZMQ_LIBRARIES}
495525
${CZMQ_LIBRARIES}
496526
${LEVELDB_LIBRARIES}
527+
${CUCUMBER_LIBRARIES}
497528
${OPTIONAL_LIBRARIES}
498529
${OPTIONAL_LIBRARIES_STATIC}
499530
)
@@ -512,6 +543,7 @@ target_link_libraries(
512543
${LIBZMQ_LIBRARIES}
513544
${CZMQ_LIBRARIES}
514545
${LEVELDB_LIBRARIES}
546+
${CUCUMBER_LIBRARIES}
515547
${OPTIONAL_LIBRARIES}
516548
)
517549
endif()
@@ -522,6 +554,7 @@ target_link_libraries(
522554
${LIBZMQ_LIBRARIES}
523555
${CZMQ_LIBRARIES}
524556
${LEVELDB_LIBRARIES}
557+
${CUCUMBER_LIBRARIES}
525558
${OPTIONAL_LIBRARIES}
526559
${OPTIONAL_LIBRARIES_STATIC}
527560
)
@@ -537,6 +570,7 @@ target_link_libraries(
537570
${LIBZMQ_LIBRARIES}
538571
${CZMQ_LIBRARIES}
539572
${LEVELDB_LIBRARIES}
573+
${CUCUMBER_LIBRARIES}
540574
${OPTIONAL_LIBRARIES}
541575
)
542576
endif()
@@ -547,6 +581,34 @@ target_link_libraries(
547581
${LIBZMQ_LIBRARIES}
548582
${CZMQ_LIBRARIES}
549583
${LEVELDB_LIBRARIES}
584+
${CUCUMBER_LIBRARIES}
585+
${OPTIONAL_LIBRARIES}
586+
${OPTIONAL_LIBRARIES_STATIC}
587+
)
588+
endif()
589+
add_executable(
590+
dafka_consumer_step_defs
591+
"${SOURCE_DIR}/src/dafka_consumer_step_defs.c"
592+
)
593+
if (TARGET dafka)
594+
target_link_libraries(
595+
dafka_consumer_step_defs
596+
dafka
597+
${LIBZMQ_LIBRARIES}
598+
${CZMQ_LIBRARIES}
599+
${LEVELDB_LIBRARIES}
600+
${CUCUMBER_LIBRARIES}
601+
${OPTIONAL_LIBRARIES}
602+
)
603+
endif()
604+
if (NOT TARGET dafka AND TARGET dafka-static)
605+
target_link_libraries(
606+
dafka_consumer_step_defs
607+
dafka-static
608+
${LIBZMQ_LIBRARIES}
609+
${CZMQ_LIBRARIES}
610+
${LEVELDB_LIBRARIES}
611+
${CUCUMBER_LIBRARIES}
550612
${OPTIONAL_LIBRARIES}
551613
${OPTIONAL_LIBRARIES_STATIC}
552614
)
@@ -562,6 +624,7 @@ target_link_libraries(
562624
${LIBZMQ_LIBRARIES}
563625
${CZMQ_LIBRARIES}
564626
${LEVELDB_LIBRARIES}
627+
${CUCUMBER_LIBRARIES}
565628
${OPTIONAL_LIBRARIES}
566629
)
567630
endif()
@@ -572,6 +635,7 @@ target_link_libraries(
572635
${LIBZMQ_LIBRARIES}
573636
${CZMQ_LIBRARIES}
574637
${LEVELDB_LIBRARIES}
638+
${CUCUMBER_LIBRARIES}
575639
${OPTIONAL_LIBRARIES}
576640
${OPTIONAL_LIBRARIES_STATIC}
577641
)
@@ -676,6 +740,7 @@ set(cmake_generated ${PROJECT_BINARY_DIR}/CMakeCache.txt
676740
${PROJECT_BINARY_DIR}/src/dafka_towerd
677741
${PROJECT_BINARY_DIR}/src/dafka_perf_consumer
678742
${PROJECT_BINARY_DIR}/src/dafka_perf_store
743+
${PROJECT_BINARY_DIR}/src/dafka_consumer_step_defs
679744
${PROJECT_BINARY_DIR}/src/dafka_selftest
680745
)
681746

Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ RUN make
1919
RUN make install
2020
RUN ldconfig
2121

22+
WORKDIR /tmp
23+
RUN git clone --quiet https://github.com/sappo/cucumber-c cucumber
24+
WORKDIR /tmp/cucumber
25+
RUN ./autogen.sh 2> /dev/null
26+
RUN ./configure --quiet --without-docs
27+
RUN make
28+
RUN make install
29+
RUN ldconfig
30+
2231
WORKDIR /tmp
2332
RUN git clone --quiet https://github.com/zeromq/dafka dafka
2433
WORKDIR /tmp/dafka

Findcucumber.cmake

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
################################################################################
2+
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3+
# Read the zproject/README.md for information about making permanent changes. #
4+
################################################################################
5+
6+
if (NOT MSVC)
7+
include(FindPkgConfig)
8+
pkg_check_modules(PC_CUCUMBER "cucumber")
9+
if (PC_CUCUMBER_FOUND)
10+
# add CFLAGS from pkg-config file, e.g. draft api.
11+
add_definitions(${PC_CUCUMBER_CFLAGS} ${PC_CUCUMBER_CFLAGS_OTHER})
12+
# some libraries install the headers is a subdirectory of the include dir
13+
# returned by pkg-config, so use a wildcard match to improve chances of finding
14+
# headers and SOs.
15+
set(PC_CUCUMBER_INCLUDE_HINTS ${PC_CUCUMBER_INCLUDE_DIRS} ${PC_CUCUMBER_INCLUDE_DIRS}/*)
16+
set(PC_CUCUMBER_LIBRARY_HINTS ${PC_CUCUMBER_LIBRARY_DIRS} ${PC_CUCUMBER_LIBRARY_DIRS}/*)
17+
endif(PC_CUCUMBER_FOUND)
18+
endif (NOT MSVC)
19+
20+
find_path (
21+
CUCUMBER_INCLUDE_DIRS
22+
NAMES cucumber_c.h
23+
HINTS ${PC_CUCUMBER_INCLUDE_HINTS}
24+
)
25+
26+
find_library (
27+
CUCUMBER_LIBRARIES
28+
NAMES cucumber
29+
HINTS ${PC_CUCUMBER_LIBRARY_HINTS}
30+
)
31+
32+
include(FindPackageHandleStandardArgs)
33+
34+
find_package_handle_standard_args(
35+
CUCUMBER
36+
REQUIRED_VARS CUCUMBER_LIBRARIES CUCUMBER_INCLUDE_DIRS
37+
)
38+
mark_as_advanced(
39+
CUCUMBER_FOUND
40+
CUCUMBER_LIBRARIES CUCUMBER_INCLUDE_DIRS
41+
)
42+
43+
################################################################################
44+
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
45+
# Read the zproject/README.md for information about making permanent changes. #
46+
################################################################################

Makefile.am

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ AM_CPPFLAGS = \
1010
${libzmq_CFLAGS} \
1111
${czmq_CFLAGS} \
1212
${leveldb_CFLAGS} \
13+
${cucumber_CFLAGS} \
1314
-I$(srcdir)/include
1415

15-
project_libs = ${libzmq_LIBS} ${czmq_LIBS} ${leveldb_LIBS}
16+
project_libs = ${libzmq_LIBS} ${czmq_LIBS} ${leveldb_LIBS} ${cucumber_LIBS}
1617

1718
SUBDIRS = doc
1819
SUBDIRS += include
@@ -36,6 +37,7 @@ EXTRA_DIST += \
3637
Findlibzmq.cmake \
3738
Findczmq.cmake \
3839
Findleveldb.cmake \
40+
Findcucumber.cmake \
3941
builds/cmake/Modules/ClangFormat.cmake \
4042
builds/cmake/clang-format-check.sh.in \
4143
builds/cmake/Config.cmake.in \

api/dafka_consumer.api

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@
99
<return type = "integer" />
1010
</method>
1111

12-
</class>
12+
<method name = "address" singleton = "1">
13+
<argument name = "self" type = "zactor" />
14+
<return type = "string" fresh = "1" />
15+
</method>
16+
17+
</class>

builds/check_zproject/ci_build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set -ex
1111
cd "$REPO_DIR/.."
1212
git clone --quiet --depth 1 https://github.com/zeromq/libzmq.git libzmq
1313
git clone --quiet --depth 1 https://github.com/zeromq/czmq.git czmq
14+
git clone --quiet --depth 1 https://github.com/sappo/cucumber-c cucumber
1415
cd -
1516

1617
if ! ((command -v dpkg-query >/dev/null 2>&1 && dpkg-query --list zproject >/dev/null 2>&1) || \

builds/cmake/ci_build.sh

+28
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,34 @@ if ! ((command -v dpkg-query >/dev/null 2>&1 && dpkg-query --list libczmq-dev >/
118118
$CI_TIME make install
119119
cd "${BASE_PWD}"
120120
fi
121+
if ! ((command -v dpkg-query >/dev/null 2>&1 && dpkg-query --list cucumber-dev >/dev/null 2>&1) || \
122+
(command -v brew >/dev/null 2>&1 && brew ls --versions cucumber >/dev/null 2>&1)); then
123+
BASE_PWD=${PWD}
124+
cd tmp-deps
125+
$CI_TIME git clone --quiet --depth 1 https://github.com/sappo/cucumber-c cucumber
126+
cd cucumber
127+
CCACHE_BASEDIR=${PWD}
128+
export CCACHE_BASEDIR
129+
git --no-pager log --oneline -n1
130+
if [ -e autogen.sh ]; then
131+
$CI_TIME ./autogen.sh 2> /dev/null
132+
fi
133+
if [ -e buildconf ]; then
134+
$CI_TIME ./buildconf 2> /dev/null
135+
fi
136+
if [ ! -e autogen.sh ] && [ ! -e buildconf ] && [ ! -e ./configure ] && [ -s ./configure.ac ]; then
137+
$CI_TIME libtoolize --copy --force && \
138+
$CI_TIME aclocal -I . && \
139+
$CI_TIME autoheader && \
140+
$CI_TIME automake --add-missing --copy && \
141+
$CI_TIME autoconf || \
142+
$CI_TIME autoreconf -fiv
143+
fi
144+
$CI_TIME ./configure "${CONFIG_OPTS[@]}"
145+
$CI_TIME make -j4
146+
$CI_TIME make install
147+
cd "${BASE_PWD}"
148+
fi
121149

122150
cd ../..
123151

0 commit comments

Comments
 (0)