Skip to content

Commit 3b85f9b

Browse files
committed
encoding/json: fix test failure
$ go test -cpu=1,1,1,1,1,1,1,1,1 encoding/json --- FAIL: TestIndentBig (0.00 seconds) scanner_test.go:131: Indent(jsonBig) did not get bigger On 4-th run initBig generates an empty array. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/49930051
1 parent 384f438 commit 3b85f9b

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/pkg/encoding/json/scanner_test.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -239,23 +239,16 @@ func trim(b []byte) []byte {
239239

240240
var jsonBig []byte
241241

242-
const (
243-
big = 10000
244-
small = 100
245-
)
246-
247242
func initBig() {
248-
n := big
243+
n := 10000
249244
if testing.Short() {
250-
n = small
245+
n = 100
251246
}
252-
if len(jsonBig) != n {
253-
b, err := Marshal(genValue(n))
254-
if err != nil {
255-
panic(err)
256-
}
257-
jsonBig = b
247+
b, err := Marshal(genValue(n))
248+
if err != nil {
249+
panic(err)
258250
}
251+
jsonBig = b
259252
}
260253

261254
func genValue(n int) interface{} {
@@ -296,6 +289,9 @@ func genArray(n int) []interface{} {
296289
if f > n {
297290
f = n
298291
}
292+
if f < 1 {
293+
f = 1
294+
}
299295
x := make([]interface{}, f)
300296
for i := range x {
301297
x[i] = genValue(((i+1)*n)/f - (i*n)/f)

0 commit comments

Comments
 (0)