Skip to content

Commit bc63ed2

Browse files
ktfknopers8
authored andcommitted
Make sure the ports are unique when running the multinode test (#1538)
* Make sure the ports are unique when running the multinode test * Update o2-qc-multinode-test.sh * update the path in curl * do not generate randomly UNIQUE_PORT_2 anymore Co-authored-by: Piotr Konopka <piotr.jan.konopka@cern.ch>
1 parent fb5f0c1 commit bc63ed2

3 files changed

Lines changed: 31 additions & 31 deletions

File tree

Framework/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ set_property(TEST functional_test PROPERTY TIMEOUT 45)
332332

333333
include(GenerateUniquePort)
334334
o2_generate_unique_port(UNIQUE_PORT_1)
335-
o2_generate_unique_port(UNIQUE_PORT_2)
335+
# UNIQUE_PORT_2 is UNIQUE_PORT_1 + 1
336+
# since we are guaranteed UNIQUE_PORT_1 is even.
337+
math(EXPR UNIQUE_PORT_2 "${UNIQUE_PORT_1} + 1")
336338
configure_file(multinode-test.json.in ${CMAKE_BINARY_DIR}/tests/multinode-test.json)
337339
add_test(NAME multinode_test COMMAND o2-qc-multinode-test.sh)
338340
set_tests_properties(multinode_test

Framework/script/o2-qc-multinode-test.sh

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ for sig in INT QUIT HUP TERM; do
2121
done
2222
trap cleanup EXIT
2323

24+
if [ -z "$UNIQUE_PORT_1" ]
25+
then
26+
echo "UNIQUE_PORT_1 must be set when calling o2-qc-multinode-test.sh"
27+
exit 1
28+
fi
29+
export UNIQUE_TEST_NAME="multinode-test-${UNIQUE_PORT_1}"
30+
2431
function check_if_port_in_use() {
2532
OS=`uname`
2633
if [[ $OS == Linux ]] ; then
@@ -42,29 +49,21 @@ function delete_data() {
4249
curl -i -L ccdb-test.cern.ch:8080/truncate/qc/TST/QO/MultiNodeLocalTest
4350
curl -i -L ccdb-test.cern.ch:8080/truncate/qc/TST/QO/MultiNodeRemoteTest
4451

45-
rm -f /tmp/multinode_test_obj${UNIQUE_PORT_1}.root
46-
rm -f /tmp/multinode_test_obj${UNIQUE_PORT_2}.root
52+
cd /tmp
53+
# mv in /tmp is guaranteed to be atomic
54+
mv -f /tmp/${UNIQUE_TEST_NAME}{,.todelete}
55+
rm -rf /tmp/${UNIQUE_TEST_NAME}.todelete
4756
}
4857

49-
if [ -z "$UNIQUE_PORT_1" ]
50-
then
51-
echo "UNIQUE_PORT_1 must be set when calling o2-qc-multinode-test.sh"
52-
exit 1
53-
fi
58+
delete_data
59+
# mkdir in /tmp is guaranteed to be atomic
60+
mkdir /tmp/${UNIQUE_TEST_NAME} || { echo "Concurrent usage of the same port ${UNIQUE_PORT_1} detected, exiting"; exit 1; }
61+
pushd /tmp/${UNIQUE_TEST_NAME}
62+
63+
UNIQUE_PORT_2=$((UNIQUE_PORT_1+1))
64+
5465
check_if_port_in_use $UNIQUE_PORT_1
55-
if [ -z "$UNIQUE_PORT_2" ]
56-
then
57-
echo "UNIQUE_PORT_2 must be set when calling o2-qc-multinode-test.sh"
58-
exit 1
59-
fi
6066
check_if_port_in_use $UNIQUE_PORT_2
61-
if [ "$UNIQUE_PORT_1" == "$UNIQUE_PORT_2" ]
62-
then
63-
echo "UNIQUE_PORT_1 must be different than UNIQUE_PORT_2 when calling o2-qc-multinode-test.sh"
64-
echo "You were probably very unlucky to have the same port randomly selected twice."
65-
echo "Just run the tests again please (or complain to the QC developers if that happens suspiciously often)."
66-
exit 1
67-
fi
6867
if [ -z "$JSON_DIR" ]
6968
then
7069
echo "JSON_DIR must be set when calling o2-qc-multinode-test.sh"
@@ -80,8 +79,6 @@ else
8079
exit 0
8180
fi
8281

83-
delete_data
84-
8582
# store data
8683
o2-qc-run-producer --producers 2 --message-amount 15 --message-rate 1 -b | timeout -s INT 40s o2-qc --config json://${JSON_DIR}/multinode-test.json -b --local --host localhost --run &
8784

@@ -92,21 +89,21 @@ wait
9289

9390
# check MonitorObject
9491
# first the return code must be 200
95-
code=$(curl -L ccdb-test.cern.ch:8080/qc/TST/MO/MultiNodeLocalTest${UNIQUE_PORT_1}/example/`date +%s`999 --write-out %{http_code} --silent --output /tmp/multinode_test_obj${UNIQUE_PORT_1}.root)
92+
code=$(curl -L ccdb-test.cern.ch:8080/qc/TST/MO/MultiNodeLocalTest${UNIQUE_PORT_1}/example/`date +%s`999 --write-out %{http_code} --silent --output /tmp/${UNIQUE_TEST_NAME}/multinode_test_obj${UNIQUE_PORT_1}.root)
9693
if (( $code != 200 )); then
9794
echo "Error, monitor object of the local QC Task could not be found."
9895
delete_data
9996
exit 2
10097
fi
10198
# try to check that we got a valid root object
102-
root -b -l -q -e 'TFile f("/tmp/multinode_test_obj${UNIQUE_PORT_1}.root"); f.Print();'
99+
root -b -l -q -e 'TFile f("/tmp/${UNIQUE_TEST_NAME}/multinode_test_obj${UNIQUE_PORT_1}.root"); f.Print();'
103100
if (( $? != 0 )); then
104101
echo "Error, monitor object of the local QC Task is invalid."
105102
delete_data
106103
exit 2
107104
fi
108105
# try if it is a non empty histogram
109-
entries=`root -b -l -q -e 'TFile f("/tmp/multinode_test_obj${UNIQUE_PORT_1}.root"); TH1F *h = (TH1F*)f.Get("ccdb_object"); cout << h->GetEntries() << endl;' | tail -n 1`
106+
entries=`root -b -l -q -e 'TFile f("/tmp/${UNIQUE_TEST_NAME}/multinode_test_obj${UNIQUE_PORT_1}.root"); TH1F *h = (TH1F*)f.Get("ccdb_object"); cout << h->GetEntries() << endl;' | tail -n 1`
110107
if ! [ $entries -gt 0 ] 2>/dev/null
111108
then
112109
echo "The histogram of the local QC Task is empty or the object is not a histogram."
@@ -116,21 +113,21 @@ fi
116113

117114
# check MonitorObject
118115
# first the return code must be 200
119-
code=$(curl -L ccdb-test.cern.ch:8080/qc/TST/MO/MultiNodeRemoteTest${UNIQUE_PORT_2}/example/`date +%s`999 --write-out %{http_code} --silent --output /tmp/multinode_test_obj${UNIQUE_PORT_2}.root)
116+
code=$(curl -L ccdb-test.cern.ch:8080/qc/TST/MO/MultiNodeRemoteTest${UNIQUE_PORT_2}/example/`date +%s`999 --write-out %{http_code} --silent --output /tmp/${UNIQUE_TEST_NAME}/multinode_test_obj${UNIQUE_PORT_2}.root)
120117
if (( $code != 200 )); then
121118
echo "Error, monitor object of the remote QC Task could not be found."
122119
delete_data
123120
exit 2
124121
fi
125122
# try to check that we got a valid root object
126-
root -b -l -q -e 'TFile f("/tmp/multinode_test_obj${UNIQUE_PORT_2}.root"); f.Print();'
123+
root -b -l -q -e 'TFile f("/tmp/${UNIQUE_TEST_NAME}/multinode_test_obj${UNIQUE_PORT_2}.root"); f.Print();'
127124
if (( $? != 0 )); then
128125
echo "Error, monitor object of the remote QC Task is invalid."
129126
delete_data
130127
exit 2
131128
fi
132129
# try if it is a non empty histogram
133-
entries=`root -b -l -q -e 'TFile f("/tmp/multinode_test_obj${UNIQUE_PORT_2}.root"); TH1F *h = (TH1F*)f.Get("ccdb_object"); cout << h->GetEntries() << endl;' | tail -n 1`
130+
entries=`root -b -l -q -e 'TFile f("/tmp/${UNIQUE_TEST_NAME}/multinode_test_obj${UNIQUE_PORT_2}.root"); TH1F *h = (TH1F*)f.Get("ccdb_object"); cout << h->GetEntries() << endl;' | tail -n 1`
134131
if ! [ $entries -gt 0 ] 2>/dev/null
135132
then
136133
echo "The histogram of the remote QC Task is empty or the object is not a histogram."

cmake/GenerateUniquePort.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ include_guard()
1818
function(o2_generate_unique_port VAR_NAME)
1919

2020
string(RANDOM LENGTH 1 ALPHABET 345 FIRST_DIGIT)
21-
string(RANDOM LENGTH 4 ALPHABET 0123456789 OTHER_DIGITS)
22-
string(CONCAT ${VAR_NAME} ${FIRST_DIGIT} ${OTHER_DIGITS})
21+
string(RANDOM LENGTH 3 ALPHABET 0123456789 OTHER_DIGITS)
22+
string(RANDOM LENGTH 1 ALPHABET 02468 LAST_DIGIT)
23+
string(CONCAT ${VAR_NAME} ${FIRST_DIGIT} ${OTHER_DIGITS} ${LAST_DIGIT})
2324

2425
set(${VAR_NAME} ${${VAR_NAME}} PARENT_SCOPE)
2526

26-
endfunction()
27+
endfunction()

0 commit comments

Comments
 (0)