Repository: Unidata/netcdf-c
Pull request #2552 (2022-11-09 03:16:36)

Fix race condition in ncdump (and other) tests.
re: Issue https://github.com/Unidata/netcdf-c/issues/2551

[dopplershift](https://github.com/dopplershift) identified the use of a common scratch file (tmp.cdl) across multiple test shell scripts in ncdump directory and the nczarr_test directory.
This sometimes causes errors because of race conditions between those scripts.

I renamed those common files to avoid the race condition.  I also did some further checking and found some additional, similar conflicts and fixed those. Also did some minor cleanup of unused files.

Tests fixed:
ncdump: run_back_comp_tests.sh tst_bom.sh tst_nccopy4.sh tst_nccopy5.sh
nczarr_test: run_nccopyz.sh run_nczarr_fill.sh run_scalar.sh


Patch:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 17959e7d4..ce08071fa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1062,14 +1062,15 @@ ENDIF()
 IF(ENABLE_DAP)
   SET(USE_DAP ON CACHE BOOL "")
   SET(ENABLE_DAP2 ON CACHE BOOL "")
+  SET(ENABLE_DAP4 OFF CACHE BOOL "")
 
-  IF(ENABLE_HDF5)
-    SET(ENABLE_DAP4 ON CACHE BOOL "")
+  IF(NOT ENABLE_HDF5)
+    SET(ENABLE_DAP4 OFF CACHE BOOL "")
   ENDIF(ENABLE_HDF5)
 
 ELSE()
-  SET(ENABLE_DAP2 OFF)
-  SET(ENABLE_DAP4 OFF)
+  SET(ENABLE_DAP2 OFF CACHE BOOL "")
+  SET(ENABLE_DAP4 OFF CACHE BOOL "")
 ENDIF()
 
 # Option to support byte-range reading of remote datasets
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 57e9ff7db..efe585bc8 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -7,7 +7,7 @@ This file contains a high-level description of this package's evolution. Release
 
 ## 4.9.1 - T.B.D.
 
-### 4.9.1 - Release Candidate 1 - October 20, 2022
+### 4.9.1 - Release Candidate 2 - TBD
 
 #### Known Issues
 
@@ -16,6 +16,7 @@ This file contains a high-level description of this package's evolution. Release
 
 #### Changes
 
+* [Bug Fix] Fix some race conditions due to use of a common file in multiple shell scripts . See [Github #2552](https://github.com/Unidata/netcdf-c/pull/2552).
 * [Enhancement][Documentation] Add Plugins Quick Start Guide.  See [GitHub #2524](https://github.com/Unidata/netcdf-c/pull/2524) for more information.
 * [Enhancement] Add new entries in `netcdf_meta.h`, `NC_HAS_BLOSC` and `NC_HAS_BZ2`. See [Github #2511](https://github.com/Unidata/netcdf-c/issues/2511) and [Github #2512](https://github.com/Unidata/netcdf-c/issues/2512) for more information.
 * [Enhancement] Add new options to `nc-config`: `--has-multifilters`, `--has-stdfilters`, `--has-quantize`, `--plugindir`.  See [Github #2509](https://github.com/Unidata/netcdf-c/pull/2509) for more information.
diff --git a/configure.ac b/configure.ac
index 3a3806944..8644d172f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -609,7 +609,7 @@ fi
 AM_CONDITIONAL(ENABLE_QUANTIZE, [test x$enable_quantize = xyes])
 
 # --enable-dap => enable-dap4
-enable_dap4=$enable_dap
+enable_dap4=no
 AC_MSG_CHECKING([whether dap use of remotetest server should be enabled])
 AC_ARG_ENABLE([dap-remote-tests],
               [AS_HELP_STRING([--disable-dap-remote-tests],
diff --git a/ncdump/tst_bom.sh b/ncdump/tst_bom.sh
index 40232a385..63eb38d88 100755
--- a/ncdump/tst_bom.sh
+++ b/ncdump/tst_bom.sh
@@ -12,7 +12,7 @@ export srcdir;
 
 echo ""
 
-rm -f tst_bom.cdl tmp.cdl tst_bom8.* tst_bom16.*
+rm -f tst_bom.cdl tmp_bom.cdl tst_bom8.* tst_bom16.*
 
 cat <<EOF >>tst_bom.cdl
 netcdf tst_bom {
@@ -30,12 +30,12 @@ cat tst_bom.cdl >> tst_bom8.cdl
 
 echo "*** Verify .nc file"
 ${NCGEN} -k nc3 -o tst_bom8.nc tst_bom8.cdl
-${NCDUMP} -n tst_bom tst_bom8.nc > tmp.cdl
-diff -w tst_bom.cdl tmp.cdl
+${NCDUMP} -n tst_bom tst_bom8.nc > tmp_bom.cdl
+diff -w tst_bom.cdl tmp_bom.cdl
 
 # Do it again but with Big-Endian 16; should fail
 
-rm -f tmp.cdl tst_bom8.* tst_bom16.*
+rm -f tmp_bom.cdl tst_bom8.* tst_bom16.*
 
 echo "*** Generate a cdl file with leading UTF-16 BOM."
 ${execdir}/bom 16 >tst_bom16.cdl
@@ -50,6 +50,6 @@ echo '***XFAIL : BOM Big Endian 16'
 fi
 
 # Cleanup
-rm -f tst_bom.cdl tmp.cdl tst_bom8.* tst_bom16.*
+rm -f tst_bom.cdl tmp_bom.cdl tst_bom8.* tst_bom16.*
 
 exit 0
diff --git a/ncdump/tst_nccopy4.sh b/ncdump/tst_nccopy4.sh
index cd2d6b759..1700aeee5 100755
--- a/ncdump/tst_nccopy4.sh
+++ b/ncdump/tst_nccopy4.sh
@@ -56,56 +56,56 @@ if test `wc -c < tst_deflated.nc` -ge  `wc -c < tst_inflated4.nc`; then
     exit 1
 fi
 echo "*** Test nccopy -d1 -s can compress a classic model netCDF-4 file even more ..."
-${NCCOPY} -d1 -s tst_inflated.nc tmp.nc
-if test `wc -c < tmp.nc` -ge  `wc -c < tst_inflated.nc`; then
+${NCCOPY} -d1 -s tst_inflated.nc tmp_ncc4.nc
+if test `wc -c < tmp_ncc4.nc` -ge  `wc -c < tst_inflated.nc`; then
     exit 1
 fi
 echo "*** Test nccopy -d1 -s can compress a netCDF-4 file even more ..."
-${NCCOPY} -d1 -s tst_inflated4.nc tmp.nc
-if test `wc -c < tmp.nc` -ge  `wc -c < tst_inflated4.nc`; then
+${NCCOPY} -d1 -s tst_inflated4.nc tmp_ncc4.nc
+if test `wc -c < tmp_ncc4.nc` -ge  `wc -c < tst_inflated4.nc`; then
     exit 1
 fi
 echo "*** Test nccopy -d0 turns off compression, shuffling of compressed, shuffled file ..."
-${NCCOPY} -d0 tst_inflated4.nc tmp.nc
-${NCDUMP} -sh tmp.nc > tmp.cdl
-if fgrep '_DeflateLevel' < tmp.cdl ; then
+${NCCOPY} -d0 tst_inflated4.nc tmp_ncc4.nc
+${NCDUMP} -sh tmp_ncc4.nc > tmp_ncc4.cdl
+if fgrep '_DeflateLevel' < tmp_ncc4.cdl ; then
     exit 1
 fi
-if fgrep '_Shuffle' < tmp.cdl ; then
+if fgrep '_Shuffle' < tmp_ncc4.cdl ; then
     exit 1
 fi
-rm tst_deflated.nc tst_inflated.nc tst_inflated4.nc tmp.nc tmp.cdl
+rm tst_deflated.nc tst_inflated.nc tst_inflated4.nc tmp_ncc4.nc tmp_ncc4.cdl
 
 echo "*** Testing nccopy -d1 -s on ncdump/*.nc files"
 for i in $TESTFILES0 ; do
     echo "*** Test nccopy -d1 -s $i.nc copy_of_$i.nc ..."
     ${NCCOPY} -d1 -s $i.nc copy_of_$i.nc
-    ${NCDUMP} -n copy_of_$i $i.nc > tmp.cdl
+    ${NCDUMP} -n copy_of_$i $i.nc > tmp_ncc4.cdl
     ${NCDUMP} copy_of_$i.nc > copy_of_$i.cdl
     #    echo "*** compare " with copy_of_$i.cdl
-    diff copy_of_$i.cdl tmp.cdl
-    rm copy_of_$i.nc copy_of_$i.cdl tmp.cdl
+    diff copy_of_$i.cdl tmp_ncc4.cdl
+    rm copy_of_$i.nc copy_of_$i.cdl tmp_ncc4.cdl
 done
 ./tst_chunking
 echo "*** Test that nccopy -c can chunk and unchunk files"
-${NCCOPY} -M0 tst_chunking.nc tmp.nc
-${NCDUMP} tmp.nc > tmp.cdl
+${NCCOPY} -M0 tst_chunking.nc tmp_ncc4.nc
+${NCDUMP} tmp_ncc4.nc > tmp_ncc4.cdl
 ${NCCOPY} -c dim0/,dim1/1,dim2/,dim3/1,dim4/,dim5/1,dim6/ tst_chunking.nc tmp-chunked.nc
-${NCDUMP} -n tmp tmp-chunked.nc > tmp-chunked.cdl
-diff tmp.cdl tmp-chunked.cdl
+${NCDUMP} -n tmp_ncc4 tmp-chunked.nc > tmp-chunked.cdl
+diff tmp_ncc4.cdl tmp-chunked.cdl
 ${NCCOPY} -c dim0/,dim1/,dim2/,dim3/,dim4/,dim5/,dim6/ tmp-chunked.nc tmp-unchunked.nc
-${NCDUMP} -n tmp tmp-unchunked.nc > tmp-unchunked.cdl
-diff tmp.cdl tmp-unchunked.cdl
+${NCDUMP} -n tmp_ncc4 tmp-unchunked.nc > tmp-unchunked.cdl
+diff tmp_ncc4.cdl tmp-unchunked.cdl
 ${NCCOPY} -c // tmp-chunked.nc tmp-unchunked2.nc
-${NCDUMP} -n tmp tmp-unchunked.nc > tmp-unchunked2.cdl
-diff tmp.cdl tmp-unchunked2.cdl
+${NCDUMP} -n tmp_ncc4 tmp-unchunked.nc > tmp-unchunked2.cdl
+diff tmp_ncc4.cdl tmp-unchunked2.cdl
 echo "*** Test that nccopy -c works as intended for record dimension default (1)"
 ${NCGEN} -b -o tst_bug321.nc $srcdir/tst_bug321.cdl
-${NCCOPY} -k nc7 -c"lat/2,lon/2" tst_bug321.nc tmp.nc
-${NCDUMP} -n tst_bug321 tmp.nc > tmp.cdl
-diff -b $srcdir/tst_bug321.cdl tmp.cdl
+${NCCOPY} -k nc7 -c"lat/2,lon/2" tst_bug321.nc tmp_ncc4.nc
+${NCDUMP} -n tst_bug321 tmp_ncc4.nc > tmp_ncc4.cdl
+diff -b $srcdir/tst_bug321.cdl tmp_ncc4.cdl
 
-rm tst_chunking.nc tmp.nc tmp.cdl tmp-chunked.nc tmp-chunked.cdl tmp-unchunked.nc tmp-unchunked.cdl
+rm tst_chunking.nc tmp_ncc4.nc tmp_ncc4.cdl tmp-chunked.nc tmp-chunked.cdl tmp-unchunked.nc tmp-unchunked.cdl
 
 echo "*** Test that nccopy -c dim/n works as intended "
 ${NCGEN} -4 -b -o tst_perdimspecs.nc $srcdir/ref_tst_perdimspecs.cdl
diff --git a/ncdump/tst_nccopy5.sh b/ncdump/tst_nccopy5.sh
index c2933ed6f..ebea3b051 100755
--- a/ncdump/tst_nccopy5.sh
+++ b/ncdump/tst_nccopy5.sh
@@ -70,7 +70,7 @@ cleanup() {
 # remove all created files
 reset() {
     cleanup
-    rm -fr tst_nc5.nc tst_nc5.cdl tmp.cdl
+    rm -fr tst_nc5.nc tst_nc5.cdl tmp_ncc5.cdl
     rm -f tst_nc5_omit.nc tst_nc5_omit.cdl
 }
 


Test patch:
diff --git a/nc_test4/tst_filter.sh b/nc_test4/tst_filter.sh
index e777956d0..38244e468 100755
--- a/nc_test4/tst_filter.sh
+++ b/nc_test4/tst_filter.sh
@@ -110,7 +110,7 @@ fi
 
 if test "x$NCP" = x1 ; then
 echo "*** Testing dynamic filters using nccopy"
-rm -f ./tmp_unfiltered.nc ./tmp_filtered.nc ./tmp.nc ./tmp_filtered.dump ./tmp_filter.txt
+rm -f ./tmp_unfiltered.nc ./tmp_filtered.nc ./tmp_filtered.dump ./tmp_filter.txt
 # Create our input test files
 ${NCGEN} -4 -lb -o tmp_unfiltered.nc ${srcdir}/ref_unfiltered.cdl
 ${NCGEN} -4 -lb -o tmp_unfilteredvv.nc ${srcdir}/ref_unfilteredvv.cdl
diff --git a/ncdump/run_back_comp_tests.sh b/ncdump/run_back_comp_tests.sh
index 3eac829ec..f0b899862 100755
--- a/ncdump/run_back_comp_tests.sh
+++ b/ncdump/run_back_comp_tests.sh
@@ -13,25 +13,25 @@ echo "*** Testing that this version can read data produced by old versions of ne
 echo "*** checking ref_nc_test_netcdf4_4_0.nc..."
 ${NCDUMP} -n ref_nc_test_netcdf4_4_0 $srcdir/ref_nc_test_netcdf4_4_0.nc > tst_nc_test_netcdf4_4_0.cdl
 # Why drop the first two lines?
-#tail -n +2 < $srcdir/ref_nc_test_netcdf4.cdl > tmp.cdl
+#tail -n +2 < $srcdir/ref_nc_test_netcdf4.cdl > tmp_back_comp.cdl
 #tail -n +2 < tst_nc_test_netcdf4_4_0.cdl > tmp_4_0.cdl
-#diff -b -w tmp.cdl tmp_4_0.cdl
+#diff -b -w tmp_back_comp.cdl tmp_4_0.cdl
 diff -b -w $srcdir/ref_nc_test_netcdf4.cdl tst_nc_test_netcdf4_4_0.cdl
 
 # echo "*** Testing that old versions can read data produced by this version of netCDF."
 # echo "*** checking version 4.0..."
 # ${NCGEN} -b -o tst_nc_test_netcdf4 -k nc7 $srcdir/ref_nc_test_netcdf4.cdl
 # /machine/local_4.0/bin/ncdump tst_nc_test_netcdf4.nc > tst_nc_test_netcdf4.cdl
-# tail -n +2 <$srcdir/ref_nc_test_netcdf4.cdl > tmp.cdl
+# tail -n +2 <$srcdir/ref_nc_test_netcdf4.cdl > tmp_back_comp.cdl
 # tail -n +2 <tst_nc_test_netcdf4.cdl > tmp_4_0.cdl
-# diff -b -w tmp.cdl tmp_4_0.cdl
+# diff -b -w tmp_back_comp.cdl tmp_4_0.cdl
 
 # echo "*** checking version 4.1.1..."
 # ${NCGEN} -b -o tst_nc_test_netcdf4 -k nc7 $srcdir/ref_nc_test_netcdf4.cdl
 # /machine/local_4.1.1/bin/ncdump tst_nc_test_netcdf4.nc > tst_nc_test_netcdf4.cdl
-# tail -n +2 <$srcdir/ref_nc_test_netcdf4.cdl > tmp.cdl
+# tail -n +2 <$srcdir/ref_nc_test_netcdf4.cdl > tmp_back_comp.cdl
 # tail -n +2 <tst_nc_test_netcdf4.cdl > tmp_4_0.cdl
-# diff -b -w tmp.cdl tmp_4_0.cdl
+# diff -b -w tmp_back_comp.cdl tmp_4_0.cdl
 
 echo "*** All backward compatibility tests passed!"
 exit 0
diff --git a/nczarr_test/run_nccopyz.sh b/nczarr_test/run_nccopyz.sh
index 3bef9cc8f..76d1d10dc 100755
--- a/nczarr_test/run_nccopyz.sh
+++ b/nczarr_test/run_nccopyz.sh
@@ -30,15 +30,15 @@ fileargs tmp
 ./tst_zchunks3 -e ${zext}
 echo "*** Test that nccopy -c can chunk files"
 ${NCCOPY} -M0 tmp_chunks3.nc "$fileurl"
-${NCDUMP} -n tmp -sh "$fileurl" > tmp.cdl
-verifychunking tmp.cdl "ivar:_ChunkSizes=7,4,2,3,5,6,9;" "fvar:_ChunkSizes=9,6,5,3,2,4,7;"
+${NCDUMP} -n tmp -sh "$fileurl" > tmp_nccz.cdl
+verifychunking tmp_nccz.cdl "ivar:_ChunkSizes=7,4,2,3,5,6,9;" "fvar:_ChunkSizes=9,6,5,3,2,4,7;"
 
 fileargs tmp_chunked
 ./tst_zchunks3 -e ${zext}
 ${NCCOPY} -M0 -c dim0/,dim1/1,dim2/,dim3/1,dim4/,dim5/1,dim6/ tmp_chunks3.nc "$fileurl"
 ${NCDUMP} -sh -n tmp "$fileurl" > tmp_chunked.cdl
 verifychunking tmp_chunked.cdl "ivar:_ChunkSizes=7,1,2,1,5,1,9;" "fvar:_ChunkSizes=9,1,5,1,2,1,7;"
-chunkclean tmp.cdl tmpx.cdl
+chunkclean tmp_nccz.cdl tmpx.cdl
 chunkclean tmp_chunked.cdl tmp_chunkedx.cdl
 diff tmpx.cdl tmp_chunkedx.cdl
 
diff --git a/nczarr_test/run_nczarr_fill.sh b/nczarr_test/run_nczarr_fill.sh
index 2176ee3e2..4995f8dc8 100755
--- a/nczarr_test/run_nczarr_fill.sh
+++ b/nczarr_test/run_nczarr_fill.sh
@@ -15,10 +15,10 @@ echo "*** Test: Github issue #2059"
 fileargs tmp_groups_regular "mode=zarr,$zext"
 deletemap $zext $file
 ${NCCOPY} ${srcdir}/ref_groups.h5 "$fileurl"
-rm -f tmp.cdl
+rm -f tmp_nczfill.cdl
 ${ZMD} -h "$fileurl"
-${NCDUMP} -s -n tmp_groups_regular "$fileurl" > tmp.cdl
-sclean tmp.cdl tmp_groups_regular_$zext.cdl
+${NCDUMP} -s -n tmp_groups_regular "$fileurl" > tmp_nczfill.cdl
+sclean tmp_nczfill.cdl tmp_groups_regular_$zext.cdl
 diff -wb ${srcdir}/ref_groups_regular.cdl tmp_groups_regular_$zext.cdl
 }
 
@@ -27,10 +27,10 @@ zext=$1
 echo "*** Test: Github issue #2062"
 rm -fr ref_byte.zarr
 unzip ${srcdir}/ref_byte.zarr.zip
-rm -fr tmp.cdl
+rm -fr tmp_nczfill.cdl
 ${ZMD} -h "file://ref_byte.zarr#mode=zarr,$zext"
-${NCDUMP} -s "file://ref_byte.zarr#mode=zarr,$zext" > tmp.cdl
-sclean tmp.cdl tmp_byte_$zext.cdl
+${NCDUMP} -s "file://ref_byte.zarr#mode=zarr,$zext" > tmp_nczfill.cdl
+sclean tmp_nczfill.cdl tmp_byte_$zext.cdl
 diff -wb ${srcdir}/ref_byte.cdl tmp_byte_$zext.cdl
 rm -fr ref_byte.zarr
 }
@@ -40,10 +40,10 @@ zext=$1
 echo "*** Test: Github issue #2063"
 rm -fr ref_byte_fill_value_null.zarr
 unzip ${srcdir}/ref_byte_fill_value_null.zarr.zip
-rm -fr tmp.cdl
+rm -fr tmp_nczfill.cdl
 ${ZMD} -h "file://ref_byte_fill_value_null.zarr#mode=zarr,$zext"
-${NCDUMP} -s "file://ref_byte_fill_value_null.zarr#mode=zarr,$zext" > tmp.cdl
-sclean tmp.cdl tmp_byte_fill_value_null_$zext.cdl
+${NCDUMP} -s "file://ref_byte_fill_value_null.zarr#mode=zarr,$zext" > tmp_nczfill.cdl
+sclean tmp_nczfill.cdl tmp_byte_fill_value_null_$zext.cdl
 diff -wb ${srcdir}/ref_byte_fill_value_null.cdl tmp_byte_fill_value_null_$zext.cdl
 rm -fr ref_byte_fill_value_null.zarr
 }
diff --git a/nczarr_test/run_scalar.sh b/nczarr_test/run_scalar.sh
index 694c51306..5b8315bb0 100755
--- a/nczarr_test/run_scalar.sh
+++ b/nczarr_test/run_scalar.sh
@@ -7,6 +7,7 @@ if test "x$srcdir" = x ; then srcdir=`pwd`; fi
 
 # This shell script tests support for the NC_STRING type
 
+set -x
 set -e
 
 zarrscalar() {