@@ -10,14 +10,16 @@ DOMAIN1=$1
1010DOMAIN2=$2
1111FILE1=" 1.txt"
1212FILE2=" 2.txt"
13+ TMP1=" tmp1.json"
14+ TMP2=" tmp2.json"
1315
14- # Perform curl requests in parallel
15- curl -s " http://${DOMAIN1} /batches" | jq > " $FILE1 " &
16+ # Fetch both responses in parallel
17+ curl -s " http://${DOMAIN1} /batches" > " $TMP1 " &
1618PID1=$!
17- curl -s " http://${DOMAIN2} /batches" | jq > " $FILE2 " &
19+ curl -s " http://${DOMAIN2} /batches" > " $TMP2 " &
1820PID2=$!
1921
20- # Wait for both curl commands to complete
22+ # Wait and check each curl
2123wait $PID1
2224if [ $? -ne 0 ]; then
2325 echo " Error fetching data from ${DOMAIN1} "
@@ -30,13 +32,35 @@ if [ $? -ne 0 ]; then
3032 exit 1
3133fi
3234
35+ # Get batch counts
36+ COUNT1=$( jq ' .batches | length' " $TMP1 " 2> /dev/null)
37+ COUNT2=$( jq ' .batches | length' " $TMP2 " 2> /dev/null)
38+
39+ # Validate batch presence
40+ if [ -z " $COUNT1 " ] || [ " $COUNT1 " -eq 0 ]; then
41+ echo " No batches found in response from ${DOMAIN1} "
42+ exit 1
43+ fi
44+
45+ if [ -z " $COUNT2 " ] || [ " $COUNT2 " -eq 0 ]; then
46+ echo " No batches found in response from ${DOMAIN2} "
47+ exit 1
48+ fi
49+
50+ # Print batch counts
51+ echo " Batch count from ${DOMAIN1} : $COUNT1 "
52+ echo " Batch count from ${DOMAIN2} : $COUNT2 "
53+
54+ # Strip batchTTL and save for comparison
55+ jq ' .batches | map(del(.batchTTL))' " $TMP1 " > " $FILE1 "
56+ jq ' .batches | map(del(.batchTTL))' " $TMP2 " > " $FILE2 "
57+
3358# Compare the files and show differences side by side
3459echo " Differences between ${FILE1} and ${FILE2} (side by side):"
35- diff --side-by-side --suppress-common-lines " $FILE1 " " $FILE2 "
36-
37- # Check if there were any differences
38- if [ $? -eq 0 ]; then
60+ if diff --side-by-side --suppress-common-lines " $FILE1 " " $FILE2 " ; then
3961 echo " No differences found."
62+ rm -f " $TMP1 " " $TMP2 "
4063else
4164 echo " Differences found (see above)."
65+ exit 1
4266fi
0 commit comments