Thanks Xiaoyu Yao for reporting this issue.
HDFS-7886 was not completely fix this issue. Can see the comment in HDFS-7930(https://issues.apache.org/jira/browse/HDFS-7930?focusedCommentId=14368053&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14368053).
Although this will not fix the testTruncateWithDataNodesRestart() completely. The location is correctly invalidated on the NN, but then NN postpones invalidation on the DN and waits for the next report.
If I add triggerBlockReports() before waitReplication() then the test passes, as it finally triggers deletion of the replica on the DN.
I think the main problem is that the block report is not completely sended to the namenode after block recovery, then lead the cluster wait for the replication.
I tested testTruncateWithDataNodesRestart in my local env, it will fails one time when I runs that test 3~5 times. But when I try the way as the comment mentioned, the result are all passed. I think the operation triggerBlockReports() would be make sense to this jira.
Attach a simple patch for this.