Commit 6b4ae1d2 authored by Shenghou Ma's avatar Shenghou Ma

test/bench/go1: fix gzip test

      We can't depend on init() order, and certainly we don't want to
register all future benchmarks that use jsonbytes or jsondata to init()
in json_test.go, so we use a more general solution: make generation of
jsonbytes and jsondata their own function so that the compiler will take
care of the order.

R=golang-dev, dave, rsc
CC=golang-dev
https://golang.org/cl/6282046
parent 622ace8f
...@@ -21,9 +21,7 @@ var ( ...@@ -21,9 +21,7 @@ var (
gobdata *JSONResponse gobdata *JSONResponse
) )
func gobinit() { func init() {
// gobinit is called after json's init,
// because it uses jsondata.
gobdata = gobResponse(&jsondata) gobdata = gobResponse(&jsondata)
var buf bytes.Buffer var buf bytes.Buffer
......
...@@ -17,11 +17,11 @@ import ( ...@@ -17,11 +17,11 @@ import (
) )
var ( var (
jsonbytes []byte jsonbytes = makeJsonBytes()
jsondata JSONResponse jsondata = makeJsonData()
) )
func init() { func makeJsonBytes() []byte {
var r io.Reader var r io.Reader
r = strings.NewReader(jsonbz2_base64) r = strings.NewReader(jsonbz2_base64)
r = base64.NewDecoder(base64.StdEncoding, r) r = base64.NewDecoder(base64.StdEncoding, r)
...@@ -30,12 +30,15 @@ func init() { ...@@ -30,12 +30,15 @@ func init() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
jsonbytes = b return b
}
if err := json.Unmarshal(jsonbytes, &jsondata); err != nil { func makeJsonData() JSONResponse {
var v JSONResponse
if err := json.Unmarshal(jsonbytes, &v); err != nil {
panic(err) panic(err)
} }
gobinit() return v
} }
type JSONResponse struct { type JSONResponse struct {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment