TestSubstituteLang is flaky
mwhudson opened this issue · comments
It fails about 12% of the time for me:
--- FAIL: TestSubstituteLang (0.00s)
slug_test.go:155: 1. Substitute("o a o", map[string]string{"o":"no", "a":"or"}) = "no nor no"; want "no or no"
FAIL
/me subscribes to the bug
- Debian bug: #828985
Hello, thank you for your report.
I will look into it when I will find some free time (probably this week but I can't promise that, flaky bugs can eat a lot of time to fix...).
OK, I see the problem.
Substitute
is taking as input a map: https://github.com/gosimple/slug/blob/master/slug.go#L84
Because in Go maps return keys in random order when iterating over it then in case of this test sometimes replacing a
with or
run first and then on the second pass o
in or
gets replaced with no
.
There are two possible solutions (without breaking API):
- always run substitution in same order (sorting keys alphabetically)
- leave it as is but remove this tests and document it's could give different results each time it's run.
I'm in favour of first way, but maybe some users like actual behaviour? What your thoughts?
Same problem could happen in SubstituteRune
I am also in favour of the first solution. It seems better to have reproductible output than removing tests.
Sorry it took so long. Fixed and tagged.
thanks!