Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(unittest): refactor some unitests #214

Merged
merged 6 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ before_script:
- cd ..

script:
- ./build.sh test 1>buildMakeLog.txt
- ./build.sh test noVerbose



Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ option(RUN_UNIT_TEST "RUN_UNIT_TEST" OFF)

if(RUN_UNIT_TEST)
message(STATUS "** RUN_UNIT_TEST: ${RUN_UNIT_TEST} Do execution testing")
enable_testing()
add_subdirectory(test)
endif()

125 changes: 82 additions & 43 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ need_build_jsoncpp=1
need_build_libevent=1
need_build_boost=1
test=0
verbose=1
cpu_num=4

pasres_arguments(){
Expand All @@ -55,6 +56,9 @@ pasres_arguments(){
noBoost)
need_build_boost=0
;;
noVerbose)
verbose=0
;;
test)
test=1
esac
Expand Down Expand Up @@ -86,6 +90,12 @@ PrintParams()
else
echo "need build boost lib"
fi
if [ $verbose -eq 0 ]
then
echo "no need print detail logs"
else
echo "need print detail logs"
fi

echo "###########################################################################"
echo ""
Expand Down Expand Up @@ -157,7 +167,7 @@ BuildLibevent()
else
wget https://github.com/libevent/libevent/archive/${fname_libevent_down} -O libevent-${fname_libevent_down}
fi
unzip -o ${fname_libevent}
unzip -o ${fname_libevent} > unziplibevent.txt 2>&1
if [ $? -ne 0 ];then
exit 1
fi
Expand All @@ -171,16 +181,28 @@ BuildLibevent()
if [ $? -ne 0 ];then
exit 1
fi
echo "build libevent static #####################"
./configure --disable-openssl --enable-static=yes --enable-shared=no CFLAGS=-fPIC CPPFLAGS=-fPIC --prefix=${install_lib_dir}
echo "build libevent static #####################"
if [ $verbose -eq 0 ];
then
./configure --disable-openssl --enable-static=yes --enable-shared=no CFLAGS=-fPIC CPPFLAGS=-fPIC --prefix=${install_lib_dir} > libeventconfig.txt 2>&1
else
./configure --disable-openssl --enable-static=yes --enable-shared=no CFLAGS=-fPIC CPPFLAGS=-fPIC --prefix=${install_lib_dir}
fi
if [ $? -ne 0 ];then
exit 1
fi
make -j $cpu_num
fi
if [ $verbose -eq 0 ];
then
echo "build libevent without detail log."
make -j $cpu_num > libeventbuild.txt 2>&1
else
make -j $cpu_num
fi
if [ $? -ne 0 ];then
exit 1
fi
make install
echo "build linevent success."
}


Expand All @@ -199,7 +221,7 @@ BuildJsonCPP()
else
wget https://github.com/open-source-parsers/jsoncpp/archive/${fname_jsoncpp_down} -O jsoncpp-${fname_jsoncpp_down}
fi
unzip -o ${fname_jsoncpp}
unzip -o ${fname_jsoncpp} > unzipjsoncpp.txt 2>&1
if [ $? -ne 0 ];then
exit 1
fi
Expand All @@ -210,16 +232,27 @@ BuildJsonCPP()
fi
mkdir build; cd build
echo "build jsoncpp static ######################"
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir}
if [ $verbose -eq 0 ];
then
echo "build jsoncpp without detail log."
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} > jsoncppbuild.txt 2>&1
else
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir}
fi
if [ $? -ne 0 ];then
exit 1
fi
make -j $cpu_num
fi
if [ $verbose -eq 0 ];
then
make -j $cpu_num > jsoncppbuild.txt 2>&1
else
make -j $cpu_num
fi
if [ $? -ne 0 ];then
exit 1
fi
make install

echo "build jsoncpp success."
if [ ! -f ${install_lib_dir}/lib/libjsoncpp.a ]
then
echo " ./bin/lib directory is not libjsoncpp.a"
Expand All @@ -241,7 +274,7 @@ BuildBoost()
else
wget http://sourceforge.net/projects/boost/files/boost/${fname_boost_down}
fi
tar -zxvf ${fname_boost}
tar -zxvf ${fname_boost} > unzipboost.txt 2>&1
boost_dir=`ls | grep boost | grep .*[^gz]$`
cd ${boost_dir}
if [ $? -ne 0 ];then
Expand All @@ -253,7 +286,13 @@ BuildBoost()
fi
echo "build boost static #####################"
pwd
./b2 -j$cpu_num cflags=-fPIC cxxflags=-fPIC --with-atomic --with-thread --with-system --with-chrono --with-date_time --with-log --with-regex --with-serialization --with-filesystem --with-locale --with-iostreams threading=multi link=static release install --prefix=${install_lib_dir}
if [ $verbose -eq 0 ];
then
echo "build boost without detail log."
./b2 -j$cpu_num cflags=-fPIC cxxflags=-fPIC --with-atomic --with-thread --with-system --with-chrono --with-date_time --with-log --with-regex --with-serialization --with-filesystem --with-locale --with-iostreams threading=multi link=static release install --prefix=${install_lib_dir} > boostbuild.txt 2>&1
else
./b2 -j$cpu_num cflags=-fPIC cxxflags=-fPIC --with-atomic --with-thread --with-system --with-chrono --with-date_time --with-log --with-regex --with-serialization --with-filesystem --with-locale --with-iostreams threading=multi link=static release install --prefix=${install_lib_dir}
fi
if [ $? -ne 0 ];then
exit 1
fi
Expand All @@ -262,13 +301,21 @@ BuildBoost()
BuildRocketMQClient()
{
cd ${build_dir}
echo "============start to build rocketmq client cpp.========="
if [ $test -eq 0 ];then
cmake ..
else
cmake .. -DRUN_UNIT_TEST=ON
fi
make -j $cpu_num
if [ $verbose -eq 0 ];
then
echo "build rocketmq without detail log."
make -j $cpu_num > buildclient.txt 2>&1
else
make -j $cpu_num
fi
if [ $? -ne 0 ];then
echo "build error....."
exit 1
fi
#sudo make install
Expand Down Expand Up @@ -301,11 +348,22 @@ BuildGoogleTest()
cd googletest-release-1.8.1
mkdir build; cd build
echo "build googletest static #####################"
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir}
if [ $verbose -eq 0 ];
then
echo "build googletest without detail log."
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} > googletestbuild.txt 2>&1
else
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir}
fi
if [ $? -ne 0 ];then
exit 1
fi
make -j $cpu_num
fi
if [ $verbose -eq 0 ];
then
make -j $cpu_num > gtestbuild.txt 2>&1
else
make -j $cpu_num
fi
if [ $? -ne 0 ];then
exit 1
fi
Expand All @@ -321,36 +379,17 @@ BuildGoogleTest()
ExecutionTesting()
{
if [ $test -eq 0 ];then
echo "Do not execution test"
echo "Build success without executing unit tests."
return 0
fi
echo "################## test start ###########"
cd ${basepath}/test/bin
if [ ! -d ../log ]; then
mkdir ../log
echo "############# unit test start ###########"
cd ${build_dir}
make test
if [ $? -ne 0 ];then
echo "############# unit test failed ###########"
exit 1
fi
for files in `ls -F`
do
./$files > "../log/$files.txt" 2>&1

if [ $? -ne 0 ]; then
echo "$files erren"
cat ../log/$files.txt
return 0
fi
erren=`grep "FAILED TEST" ../log/$files.txt`

if [ -n "$erren" ]; then
echo "################## find erren ###########"
cat ../log/$files.txt

echo "################## end ExecutionTesting ###########"
return
else
echo "$files success"
fi
done
echo "################## test end ###########"
echo "############# unit test finish ###########"
}

PackageRocketMQStatic()
Expand Down
4 changes: 4 additions & 0 deletions src/extern/CPullConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ CPullResult Pull(CPullConsumer* consumer,
int maxNums) {
CPullResult pullResult;
memset(&pullResult, 0, sizeof(CPullResult));
if (consumer == NULL || subExpression == NULL) {
pullResult.pullStatus = E_BROKER_TIMEOUT;
return pullResult;
}
MQMessageQueue messageQueue(mq->topic, mq->brokerName, mq->queueId);
PullResult cppPullResult;
try {
Expand Down
4 changes: 3 additions & 1 deletion src/protocol/CommandHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,9 @@ CommandHeader* GetConsumerRunningInfoRequestHeader::Decode(Json::Value& ext) {
}

tempValue = ext["jstackEnable"];
if (tempValue.isString()) {
if (tempValue.isBool()) {
h->jstackEnable = tempValue.asBool();
} else if (tempValue.isString()) {
h->jstackEnable = UtilAll::to_bool(tempValue.asCString());
}
LOG_INFO("consumerGroup:%s, clientId:%s, jstackEnable:%d", h->consumerGroup.c_str(), h->clientId.c_str(),
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function(compile files)
foreach(file ${files})
get_filename_component(basename ${file} NAME_WE)
add_executable(${basename} ${file})
add_test(NAME rocketmq-${basename} COMMAND ${basename})
if(MSVC)
if(CMAKE_CONFIGURATION_TYPES STREQUAL "Release")
set_target_properties( ${basename} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMT" )
Expand Down
32 changes: 31 additions & 1 deletion test/src/extern/CMessageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@ using testing::Return;

using rocketmq::MQMessage;

TEST(cmessages, originMessage) {
CMessage* message = CreateMessage(NULL);
EXPECT_STREQ(GetOriginMessageTopic(message), "");

SetMessageTopic(message, "testTopic");
EXPECT_STREQ(GetOriginMessageTopic(message), "testTopic");

SetMessageTags(message, "testTags");
EXPECT_STREQ(GetOriginMessageTags(message), "testTags");

SetMessageKeys(message, "testKeys");
EXPECT_STREQ(GetOriginMessageKeys(message), "testKeys");

SetMessageBody(message, "testBody");
EXPECT_STREQ(GetOriginMessageBody(message), "testBody");

SetMessageProperty(message, "testKey", "testValue");
EXPECT_STREQ(GetOriginMessageProperty(message, "testKey"), "testValue");

SetDelayTimeLevel(message, 1);
EXPECT_EQ(GetOriginDelayTimeLevel(message), 1);

EXPECT_EQ(DestroyMessage(message), OK);

CMessage* message2 = CreateMessage("testTwoTopic");
EXPECT_STREQ(GetOriginMessageTopic(message2), "testTwoTopic");

EXPECT_EQ(DestroyMessage(message2), OK);
}

TEST(cmessages, info) {
CMessage* message = CreateMessage(NULL);
MQMessage* mqMessage = (MQMessage*)message;
Expand Down Expand Up @@ -75,7 +105,7 @@ TEST(cmessages, null) {
int main(int argc, char* argv[]) {
InitGoogleMock(&argc, argv);

testing::GTEST_FLAG(filter) = "cmessages.null";
// testing::GTEST_FLAG(filter) = "cmessages.*";
int itestts = RUN_ALL_TESTS();
return itestts;
}
Loading