Skip to content

FormatPorts produces nondeterministic output due to map iteration order #4626

@opjt

Description

@opjt

Description

FormatPorts produces nondeterministic output because it iterates over a map[key][]PortMapping without sorting the keys.
Since Go map iteration order is random, the generated port string can change between runs (e.g., tcp group printed before udp or vice versa).

This causes the TestFormatPorts/mixed_tcp_and_udp_with_consecutive_ports_on_anyhost test to fail intermittently.

--- FAIL: TestFormatPorts (0.00s)
    --- FAIL: TestFormatPorts/mixed_tcp_and_udp_with_consecutive_ports_on_anyhost (0.00s)
        formatter_test.go:191: assertion failed: 0.0.0.0:3000-3001->8080-8081/tcp, 0.0.0.0:3002-3003->8082-8083/udp (tt.expected string) != 0.0.0.0:3002-3003->8082-8083/udp, 0.0.0.0:3000-3001->8080-8081/tcp (result string)
FAIL

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions