Actively-used test helper function `testVolumeConfig` in `org.apache.hadoop.hdfs.server.datanode.TestDataNodeVolumeFailureToleration` chmod a directory with invalid perm 000 for testing purposes but later failed to chmod back this directory with a valid perm if the assertion inside this function failed. Any subsequent `mvn test` command would fail to run if this test had failed before. It is because Maven failed to build itself as it did not have permission to clean the temporarily-generated directory that has perm 000. See below for the code snippet that is buggy.
The failure of the statement `assertEquals(expectedBPServiceState, bpServiceState)` caused function to terminate without executing `FileUtil.chmod(dir.toString(), "755")` for each temporary directory with invalid perm 000 the test has created.
Any subsequent `mvn test` command would fail to run if this test had failed before. It is because Maven failed to build itself since it does not have permission to clean this temporarily-generated directory. For details of the failure, see below:
The test helper function `org.apache.hadoop.hdfs.server.datanode.TestDataNodeVolumeFailureToleration#testVolumeConfig` purposely set the directory `/home/ctest/app/Ctest-Hadoop/hadoop-hdfs-project/hadoop-hdfs/target/test/data/dfs/data/data1/current` to have perm 000. And at the end of this function, it changed the perm of this directory to 755. However, there is an assertion in this function before the perm was able to changed to 755. Once this assertion fails, the function terminates before the directory’s perm can be changed to 755. Hence, this directory was later unable to be removed by Maven for when executing `mvn test`.
In `org.apache.hadoop.hdfs.server.datanode.TestDataNodeVolumeFailureToleration#testVolumeConfig`, move the assertion `assertEquals(expectedBPServiceState, bpServiceState)` to the last line of this function. This fix will fix the bug and will not change the test outcome.