[1.6.x] Fixed #22338 -- Fixed a test dependent on dictionary key iteration order.

Backport of 69a4f383f6 from master