[1.7.x] Improved the test for refs #22682.

Thanks apollo13 for the review.

Backport of 6f4d7f41b1 from master