Skip to content

Commit ec1fe11

Browse files
ethantkoeniglunny
authored andcommitted
Fix race condition in unit test (#456)
1 parent dfb5470 commit ec1fe11

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

modules/base/tool_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,19 @@ func TestDetectEncoding(t *testing.T) {
7676

7777
// iso-8859-1: d<accented e>cor<newline>
7878
b = []byte{0x44, 0xe9, 0x63, 0x6f, 0x72, 0x0a}
79-
testSuccess(b, "ISO-8859-1")
79+
encoding, err := DetectEncoding(b)
80+
assert.NoError(t, err)
81+
// due to a race condition in `chardet` library, it could either detect
82+
// "ISO-8859-1" or "IS0-8859-2" here. Technically either is correct, so
83+
// we accept either.
84+
assert.Contains(t, encoding, "ISO-8859")
8085

8186
setting.Repository.AnsiCharset = "placeholder"
8287
testSuccess(b, "placeholder")
8388

8489
// invalid bytes
8590
b = []byte{0xfa}
86-
_, err := DetectEncoding(b)
91+
_, err = DetectEncoding(b)
8792
assert.Error(t, err)
8893
}
8994

0 commit comments

Comments
 (0)