@@ -21,6 +21,13 @@ for sig in INT QUIT HUP TERM; do
2121done
2222trap 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+
2431function 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+
5465check_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
6066check_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
6867if [ -z " $JSON_DIR " ]
6968then
7069 echo " JSON_DIR must be set when calling o2-qc-multinode-test.sh"
8079 exit 0
8180fi
8281
83- delete_data
84-
8582# store data
8683o2-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
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)
9693if (( $code != 200 )) ; then
9794 echo " Error, monitor object of the local QC Task could not be found."
9895 delete_data
9996 exit 2
10097fi
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();'
103100if (( $? != 0 )) ; then
104101 echo " Error, monitor object of the local QC Task is invalid."
105102 delete_data
106103 exit 2
107104fi
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`
110107if ! [ $entries -gt 0 ] 2> /dev/null
111108then
112109 echo " The histogram of the local QC Task is empty or the object is not a histogram."
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)
120117if (( $code != 200 )) ; then
121118 echo " Error, monitor object of the remote QC Task could not be found."
122119 delete_data
123120 exit 2
124121fi
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();'
127124if (( $? != 0 )) ; then
128125 echo " Error, monitor object of the remote QC Task is invalid."
129126 delete_data
130127 exit 2
131128fi
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`
134131if ! [ $entries -gt 0 ] 2> /dev/null
135132then
136133 echo " The histogram of the remote QC Task is empty or the object is not a histogram."
0 commit comments