Port test from cf1904f to avoid future regression

Related issue: #11939, #12084
Merge pull request #12435 from sikachu/master-port-12084

Port test from cf1904f to avoid future regression