Skip to content

Commit 19d2da1

Browse files
committed
deploy for test
1 parent 5d78979 commit 19d2da1

File tree

1 file changed

+65
-27
lines changed

1 file changed

+65
-27
lines changed

CTP/common/script/start_consumer.sh

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function updateCodes()
149149
fi
150150
fi
151151

152-
changedCount=`cd ${CTP_HOME}; run_grepo_fetch -r cubrid-testtools -b "$branchName" -p "CTP" -e "conf" --check-only . | grep "fetch" | grep CHANGED | wc -l`
152+
changedCount=`cd ${CTP_HOME}; run_grepo_fetch -r cubrid-testtools -b "$branchName" -p "CTP" -e "conf" -e "common" --check-only . | grep "fetch" | grep CHANGED | wc -l`
153153

154154
if [ "$changedCount" -gt "0" ]; then
155155
echo "-------------------------- Begin to update codes -----------------------------"
@@ -359,48 +359,62 @@ do
359359

360360
existsMsgId=`cat ${CTP_HOME}/common/sched/status/${x} 2> /dev/null | grep MSG_ID|awk -F ':' '{print $2}'`
361361
isFromGit=`cat ${CTP_HOME}/common/sched/status/${x} 2> /dev/null | grep BUILD_IS_FROM_GIT|awk -F ':' '{print $2}'`
362+
savedEnvBranch=`cat ${CTP_HOME}/common/sched/status/${x} 2> /dev/null | grep ENV_CTP_BRANCH_NAME|awk -F ':' '{print $2}'`
363+
testCompleted=`cat ${CTP_HOME}/common/sched/status/${x} 2> /dev/null | grep TEST_COMPLETED|awk -F ':' '{print $2}'`
362364
isStartByData=`echo $existsMsgId|grep "[^0-9]"|wc -l`
363365
if [ "$existsMsgId" -a ${isStartByData} -gt 0 ]; then
364366
echo "Action: $x, ${q_exec[$count]}.sh, CONTINUE"
365-
# Update CTP if ENV_CTP_BRANCH_NAME is set in continue mode
366-
tempBranchContinue=""
367-
if [ $withoutSync -ne 1 ]; then
368-
source ${CTP_HOME}/common/sched/init.sh $ser_site
369-
if [ "$CTP_BRANCH_NAME" ] && [ "$CTP_BRANCH_NAME" != "$branchName" ]; then
370-
echo "ENV_CTP_BRANCH_NAME detected: $CTP_BRANCH_NAME (updating from $branchName)"
371-
updateCodes $CTP_BRANCH_NAME
372-
tempBranchContinue="$branchName"
367+
368+
# Check if test is already completed (only need restore)
369+
if [ "$testCompleted" = "yes" ]; then
370+
echo "Test already completed, only restore branch needed"
371+
restoreBranch=`cat ${CTP_HOME}/common/sched/status/$x 2> /dev/null | grep RESTORE_BRANCH|awk -F ':' '{print $2}'`
372+
if [ "$restoreBranch" ] && [ "$restoreBranch" = "$branchName" ]; then
373+
echo "Restoring CTP to base branch: $branchName (may restart)..."
374+
updateCodes $branchName
375+
echo "CTP restored to: $branchName"
373376
fi
377+
echo '' > ${CTP_HOME}/common/sched/status/${x}
378+
continue
379+
fi
380+
381+
# Update CTP to ENV branch if saved in status (may restart again)
382+
if [ $withoutSync -ne 1 ] && [ "$savedEnvBranch" ] && [ "$savedEnvBranch" != "$branchName" ]; then
383+
echo "ENV_CTP_BRANCH_NAME found in status: $savedEnvBranch"
384+
echo "Updating CTP to ENV branch (may restart)..."
385+
updateCodes $savedEnvBranch
386+
echo "CTP updated to: $savedEnvBranch"
374387
fi
388+
375389
(cd ${CTP_HOME}; export BUILD_IS_FROM_GIT=$isFromGit ;source ${CTP_HOME}/common/sched/init.sh $ser_site;sh common/ext/${q_exec[$count]}.sh YES)
376390

377391
echo
378392
echo "End continue mode test!"
379393
consumerTimer ${existsMsgId} "stop"
380394

381-
# Restore original branch if temp branch was used
382-
[ -n "$tempBranchContinue" ] && updateCodes $tempBranchContinue
383-
384395
contimeENDTIME=`getTimeStamp`
385396
echo "END_CONTINUE_TIME:${contimeENDTIME}"
397+
398+
# Check if need to restore to base branch
399+
restoreBranch=`cat ${CTP_HOME}/common/sched/status/$x 2> /dev/null | grep RESTORE_BRANCH|awk -F ':' '{print $2}'`
400+
if [ "$restoreBranch" ] && [ "$restoreBranch" = "$branchName" ]; then
401+
# Mark test as completed, keep only restore info
402+
echo "MSG_ID:$existsMsgId" > ${CTP_HOME}/common/sched/status/$x
403+
echo "TEST_COMPLETED:yes" >> ${CTP_HOME}/common/sched/status/$x
404+
echo "RESTORE_BRANCH:$branchName" >> ${CTP_HOME}/common/sched/status/$x
405+
406+
echo "Restoring CTP to base branch: $branchName (may restart)..."
407+
updateCodes $branchName
408+
echo "CTP restored to: $branchName"
409+
fi
410+
386411
echo '' > ${CTP_HOME}/common/sched/status/${x}
387412
echo
388413
fi
389414

390415
startAgent $x
391416
hasTestBuild
392417

393-
#update client again if ENV_CTP_BRANCH_NAME is set in message
394-
tempBranch=""
395-
if [ "$hasBuild" == "true" ] && [ $withoutSync -ne 1 ]; then
396-
source ${CTP_HOME}/common/sched/init.sh $ser_site
397-
if [ "$CTP_BRANCH_NAME" ] && [ "$CTP_BRANCH_NAME" != "$branchName" ]; then
398-
echo "ENV_CTP_BRANCH_NAME detected: $CTP_BRANCH_NAME (updating from $branchName)"
399-
updateCodes $CTP_BRANCH_NAME
400-
tempBranch="$branchName"
401-
fi
402-
fi
403-
404418
if [ "$isDebug" == "--debug" ]; then
405419
echo "-------------------------- Debug Message Information -----------------------------"
406420
cat ${CTP_HOME}/common/sched/result/$fileName
@@ -422,10 +436,22 @@ do
422436
echo "START_TIME:${TestTime}" >> $statFile
423437

424438
echo
425-
echo "Log msg id into queue file!"
439+
echo "Save message info to status file for continue mode"
426440
echo "MSG_ID:$msgId" > ${CTP_HOME}/common/sched/status/$x
427441
echo "BUILD_IS_FROM_GIT:$build_is_from_git" >> ${CTP_HOME}/common/sched/status/$x
428442
echo "START_TIME:${TestTime}" >> ${CTP_HOME}/common/sched/status/$x
443+
444+
# Check ENV_CTP_BRANCH_NAME and save to status before updateCodes
445+
source ${CTP_HOME}/common/sched/init.sh $ser_site
446+
if [ "$CTP_BRANCH_NAME" ] && [ "$CTP_BRANCH_NAME" != "$branchName" ]; then
447+
echo "ENV_CTP_BRANCH_NAME:$CTP_BRANCH_NAME" >> ${CTP_HOME}/common/sched/status/$x
448+
echo "RESTORE_BRANCH:$branchName" >> ${CTP_HOME}/common/sched/status/$x
449+
echo
450+
echo "ENV_CTP_BRANCH_NAME detected: $CTP_BRANCH_NAME"
451+
echo "Updating CTP to ENV branch (may restart)..."
452+
updateCodes $CTP_BRANCH_NAME
453+
echo "CTP updated to: $CTP_BRANCH_NAME"
454+
fi
429455
echo
430456

431457
consumerTimer $msgId "start"
@@ -434,11 +460,23 @@ do
434460

435461
consumerTimer $msgId "stop"
436462

437-
# Restore original branch if temp branch was used
438-
[ -n "$tempBranch" ] && updateCodes $tempBranch
439-
440463
ENDTIME=`getTimeStamp`
441464
echo
465+
echo "Test completed. Check if need to restore branch..."
466+
467+
# Check if need to restore to base branch
468+
restoreBranch=`cat ${CTP_HOME}/common/sched/status/$x 2> /dev/null | grep RESTORE_BRANCH|awk -F ':' '{print $2}'`
469+
if [ "$restoreBranch" ] && [ "$restoreBranch" = "$branchName" ]; then
470+
# Mark test as completed, keep only restore info
471+
echo "MSG_ID:$msgId" > ${CTP_HOME}/common/sched/status/$x
472+
echo "TEST_COMPLETED:yes" >> ${CTP_HOME}/common/sched/status/$x
473+
echo "RESTORE_BRANCH:$branchName" >> ${CTP_HOME}/common/sched/status/$x
474+
475+
echo "Restoring CTP to base branch: $branchName (may restart)..."
476+
updateCodes $branchName
477+
echo "CTP restored to: $branchName"
478+
fi
479+
442480
echo "Clean msg id from queue file"
443481
echo '' > ${CTP_HOME}/common/sched/status/$x
444482
echo "END_TIME:${ENDTIME}"

0 commit comments

Comments
 (0)