Skip to content

Commit 04d732b

Browse files
committed
build: shorten a few packages with long tests
Takes 3% off my all.bash run time. For #10571. Change-Id: I8f00f523d6919e87182d35722a669b0b96b8218b Reviewed-on: https://go-review.googlesource.com/18087 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
1 parent acc1500 commit 04d732b

File tree

11 files changed

+114
-11
lines changed

11 files changed

+114
-11
lines changed

src/archive/zip/zip_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"bytes"
1111
"fmt"
1212
"hash"
13+
"internal/testenv"
1314
"io"
1415
"io/ioutil"
1516
"sort"
@@ -19,6 +20,9 @@ import (
1920
)
2021

2122
func TestOver65kFiles(t *testing.T) {
23+
if testing.Short() && testenv.Builder() == "" {
24+
t.Skip("skipping in short mode")
25+
}
2226
buf := new(bytes.Buffer)
2327
w := NewWriter(buf)
2428
const nFiles = (1 << 16) + 42

src/compress/flate/deflate_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package flate
77
import (
88
"bytes"
99
"fmt"
10+
"internal/testenv"
1011
"io"
1112
"io/ioutil"
1213
"reflect"
@@ -343,6 +344,9 @@ var deflateInflateStringTests = []deflateInflateStringTest{
343344
}
344345

345346
func TestDeflateInflateString(t *testing.T) {
347+
if testing.Short() && testenv.Builder() == "" {
348+
t.Skip("skipping in short mode")
349+
}
346350
for _, test := range deflateInflateStringTests {
347351
gold, err := ioutil.ReadFile(test.filename)
348352
if err != nil {
@@ -436,7 +440,11 @@ func TestWriterReset(t *testing.T) {
436440
t.Fatalf("NewWriter: %v", err)
437441
}
438442
buf := []byte("hello world")
439-
for i := 0; i < 1024; i++ {
443+
n := 1024
444+
if testing.Short() {
445+
n = 10
446+
}
447+
for i := 0; i < n; i++ {
440448
w.Write(buf)
441449
}
442450
w.Reset(ioutil.Discard)

src/compress/lzw/writer_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package lzw
66

77
import (
8+
"internal/testenv"
89
"io"
910
"io/ioutil"
1011
"os"
@@ -13,6 +14,7 @@ import (
1314
)
1415

1516
var filenames = []string{
17+
"../testdata/gettysburg.txt",
1618
"../testdata/e.txt",
1719
"../testdata/pi.txt",
1820
}
@@ -89,10 +91,16 @@ func TestWriter(t *testing.T) {
8991
for _, filename := range filenames {
9092
for _, order := range [...]Order{LSB, MSB} {
9193
// The test data "2.71828 etcetera" is ASCII text requiring at least 6 bits.
92-
for _, litWidth := range [...]int{6, 7, 8} {
94+
for litWidth := 6; litWidth <= 8; litWidth++ {
95+
if filename == "../testdata/gettysburg.txt" && litWidth == 6 {
96+
continue
97+
}
9398
testFile(t, filename, order, litWidth)
9499
}
95100
}
101+
if testing.Short() && testenv.Builder() == "" {
102+
break
103+
}
96104
}
97105
}
98106

src/compress/testdata/gettysburg.txt

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Four score and seven years ago our fathers brought forth on
2+
this continent, a new nation, conceived in Liberty, and dedicated
3+
to the proposition that all men are created equal.
4+
Now we are engaged in a great Civil War, testing whether that
5+
nation, or any nation so conceived and so dedicated, can long
6+
endure.
7+
We are met on a great battle-field of that war.
8+
We have come to dedicate a portion of that field, as a final
9+
resting place for those who here gave their lives that that
10+
nation might live. It is altogether fitting and proper that
11+
we should do this.
12+
But, in a larger sense, we can not dedicate - we can not
13+
consecrate - we can not hallow - this ground.
14+
The brave men, living and dead, who struggled here, have
15+
consecrated it, far above our poor power to add or detract.
16+
The world will little note, nor long remember what we say here,
17+
but it can never forget what they did here.
18+
It is for us the living, rather, to be dedicated here to the
19+
unfinished work which they who fought here have thus far so
20+
nobly advanced. It is rather for us to be here dedicated to
21+
the great task remaining before us - that from these honored
22+
dead we take increased devotion to that cause for which they
23+
gave the last full measure of devotion -
24+
that we here highly resolve that these dead shall not have
25+
died in vain - that this nation, under God, shall have a new
26+
birth of freedom - and that government of the people, by the
27+
people, for the people, shall not perish from this earth.
28+
29+
Abraham Lincoln, November 19, 1863, Gettysburg, Pennsylvania

src/compress/zlib/writer_test.go

+21-6
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ package zlib
77
import (
88
"bytes"
99
"fmt"
10+
"internal/testenv"
1011
"io"
1112
"io/ioutil"
1213
"os"
1314
"testing"
1415
)
1516

1617
var filenames = []string{
18+
"../testdata/gettysburg.txt",
1719
"../testdata/e.txt",
1820
"../testdata/pi.txt",
1921
}
@@ -152,22 +154,34 @@ func TestWriter(t *testing.T) {
152154
}
153155

154156
func TestWriterBig(t *testing.T) {
155-
for _, fn := range filenames {
157+
for i, fn := range filenames {
156158
testFileLevelDict(t, fn, DefaultCompression, "")
157159
testFileLevelDict(t, fn, NoCompression, "")
158160
for level := BestSpeed; level <= BestCompression; level++ {
159161
testFileLevelDict(t, fn, level, "")
162+
if level >= 1 && testing.Short() && testenv.Builder() == "" {
163+
break
164+
}
165+
}
166+
if i == 0 && testing.Short() && testenv.Builder() == "" {
167+
break
160168
}
161169
}
162170
}
163171

164172
func TestWriterDict(t *testing.T) {
165173
const dictionary = "0123456789."
166-
for _, fn := range filenames {
174+
for i, fn := range filenames {
167175
testFileLevelDict(t, fn, DefaultCompression, dictionary)
168176
testFileLevelDict(t, fn, NoCompression, dictionary)
169177
for level := BestSpeed; level <= BestCompression; level++ {
170178
testFileLevelDict(t, fn, level, dictionary)
179+
if level >= 1 && testing.Short() && testenv.Builder() == "" {
180+
break
181+
}
182+
}
183+
if i == 0 && testing.Short() && testenv.Builder() == "" {
184+
break
171185
}
172186
}
173187
}
@@ -179,10 +193,11 @@ func TestWriterReset(t *testing.T) {
179193
testFileLevelDictReset(t, fn, DefaultCompression, nil)
180194
testFileLevelDictReset(t, fn, NoCompression, []byte(dictionary))
181195
testFileLevelDictReset(t, fn, DefaultCompression, []byte(dictionary))
182-
if !testing.Short() {
183-
for level := BestSpeed; level <= BestCompression; level++ {
184-
testFileLevelDictReset(t, fn, level, nil)
185-
}
196+
if testing.Short() {
197+
break
198+
}
199+
for level := BestSpeed; level <= BestCompression; level++ {
200+
testFileLevelDictReset(t, fn, level, nil)
186201
}
187202
}
188203
}

src/go/internal/gcimporter/gcimporter_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ func TestImportStdLib(t *testing.T) {
164164
return
165165
}
166166

167-
nimports := testDir(t, "", time.Now().Add(maxTime)) // installed packages
167+
dt := maxTime
168+
if testing.Short() && testenv.Builder() == "" {
169+
dt = 10 * time.Millisecond
170+
}
171+
nimports := testDir(t, "", time.Now().Add(dt)) // installed packages
168172
t.Logf("tested %d imports", nimports)
169173
}
170174

src/go/types/stdlib_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ func testTestDir(t *testing.T, path string, ignore ...string) {
127127
func TestStdTest(t *testing.T) {
128128
testenv.MustHaveGoBuild(t)
129129

130+
if testing.Short() && testenv.Builder() == "" {
131+
t.Skip("skipping in short mode")
132+
}
133+
130134
// test/recover4.go is only built for Linux and Darwin.
131135
// TODO(gri) Remove once tests consider +build tags (issue 10370).
132136
if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
@@ -142,6 +146,10 @@ func TestStdTest(t *testing.T) {
142146
func TestStdFixed(t *testing.T) {
143147
testenv.MustHaveGoBuild(t)
144148

149+
if testing.Short() && testenv.Builder() == "" {
150+
t.Skip("skipping in short mode")
151+
}
152+
145153
testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "fixedbugs"),
146154
"bug248.go", "bug302.go", "bug369.go", // complex test instructions - ignore
147155
"issue6889.go", // gc-specific test
@@ -247,7 +255,7 @@ func pkgFilenames(dir string) ([]string, error) {
247255

248256
func walkDirs(t *testing.T, dir string) {
249257
// limit run time for short tests
250-
if testing.Short() && time.Since(start) >= 750*time.Millisecond {
258+
if testing.Short() && time.Since(start) >= 10*time.Millisecond {
251259
return
252260
}
253261

src/math/big/int_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,14 @@ func TestModSqrt(t *testing.T) {
13781378
t.Errorf("#%d: failed (sqrt(e) = %s)", i, &sqrt)
13791379
}
13801380
}
1381+
1382+
if testing.Short() && i > 2 {
1383+
break
1384+
}
1385+
}
1386+
1387+
if testing.Short() {
1388+
return
13811389
}
13821390

13831391
// exhaustive test for small values

src/math/rand/rand_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package rand
77
import (
88
"errors"
99
"fmt"
10+
"internal/testenv"
1011
"math"
1112
"os"
1213
"runtime"
@@ -327,9 +328,10 @@ func TestExpTables(t *testing.T) {
327328
func TestFloat32(t *testing.T) {
328329
// For issue 6721, the problem came after 7533753 calls, so check 10e6.
329330
num := int(10e6)
331+
// But do the full amount only on builders (not locally).
330332
// But ARM5 floating point emulation is slow (Issue 10749), so
331333
// do less for that builder:
332-
if testing.Short() && runtime.GOARCH == "arm" && os.Getenv("GOARM") == "5" {
334+
if testing.Short() && (testenv.Builder() == "" || runtime.GOARCH == "arm" && os.Getenv("GOARM") == "5") {
333335
num /= 100 // 1.72 seconds instead of 172 seconds
334336
}
335337

src/net/http/serve_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"crypto/tls"
1313
"errors"
1414
"fmt"
15+
"internal/testenv"
1516
"io"
1617
"io/ioutil"
1718
"log"
@@ -454,6 +455,7 @@ func TestServerTimeouts(t *testing.T) {
454455
if runtime.GOOS == "plan9" {
455456
t.Skip("skipping test; see https://golang.org/issue/7237")
456457
}
458+
t.Parallel()
457459
defer afterTest(t)
458460
reqNum := 0
459461
ts := httptest.NewUnstartedServer(HandlerFunc(func(res ResponseWriter, req *Request) {
@@ -937,6 +939,7 @@ func TestTLSHandshakeTimeout(t *testing.T) {
937939
if runtime.GOOS == "plan9" {
938940
t.Skip("skipping test; see https://golang.org/issue/7237")
939941
}
942+
t.Parallel()
940943
defer afterTest(t)
941944
ts := httptest.NewUnstartedServer(HandlerFunc(func(w ResponseWriter, r *Request) {}))
942945
errc := make(chanWriter, 10) // but only expecting 1
@@ -1277,6 +1280,9 @@ func TestServerUnreadRequestBodyLittle(t *testing.T) {
12771280
// should ignore client request bodies that a handler didn't read
12781281
// and close the connection.
12791282
func TestServerUnreadRequestBodyLarge(t *testing.T) {
1283+
if testing.Short() && testenv.Builder() == "" {
1284+
t.Log("skipping in short mode")
1285+
}
12801286
conn := new(testConn)
12811287
body := strings.Repeat("x", 1<<20)
12821288
conn.readBuf.Write([]byte(fmt.Sprintf(
@@ -1407,6 +1413,9 @@ var handlerBodyCloseTests = [...]handlerBodyCloseTest{
14071413
}
14081414

14091415
func TestHandlerBodyClose(t *testing.T) {
1416+
if testing.Short() && testenv.Builder() == "" {
1417+
t.Skip("skipping in -short mode")
1418+
}
14101419
for i, tt := range handlerBodyCloseTests {
14111420
testHandlerBodyClose(t, i, tt)
14121421
}

src/net/http/transport_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ func TestTransportMaxPerHostIdleConns(t *testing.T) {
436436
}
437437

438438
func TestTransportServerClosingUnexpectedly(t *testing.T) {
439+
t.Parallel()
439440
defer afterTest(t)
440441
ts := httptest.NewServer(hostPortHandler)
441442
defer ts.Close()
@@ -968,6 +969,7 @@ func TestTransportGzipShort(t *testing.T) {
968969

969970
// tests that persistent goroutine connections shut down when no longer desired.
970971
func TestTransportPersistConnLeak(t *testing.T) {
972+
t.Parallel()
971973
defer afterTest(t)
972974
gotReqCh := make(chan bool)
973975
unblockCh := make(chan bool)
@@ -1034,6 +1036,7 @@ func TestTransportPersistConnLeak(t *testing.T) {
10341036
// golang.org/issue/4531: Transport leaks goroutines when
10351037
// request.ContentLength is explicitly short
10361038
func TestTransportPersistConnLeakShortBody(t *testing.T) {
1039+
t.Parallel()
10371040
defer afterTest(t)
10381041
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
10391042
}))
@@ -1374,6 +1377,7 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) {
13741377
}
13751378

13761379
func TestTransportResponseHeaderTimeout(t *testing.T) {
1380+
t.Parallel()
13771381
defer afterTest(t)
13781382
if testing.Short() {
13791383
t.Skip("skipping timeout test in -short mode")
@@ -1445,6 +1449,7 @@ func TestTransportResponseHeaderTimeout(t *testing.T) {
14451449
}
14461450

14471451
func TestTransportCancelRequest(t *testing.T) {
1452+
t.Parallel()
14481453
defer afterTest(t)
14491454
if testing.Short() {
14501455
t.Skip("skipping test in -short mode")
@@ -1554,6 +1559,7 @@ Get = Get http://something.no-network.tld/: net/http: request canceled while wai
15541559
}
15551560

15561561
func TestCancelRequestWithChannel(t *testing.T) {
1562+
t.Parallel()
15571563
defer afterTest(t)
15581564
if testing.Short() {
15591565
t.Skip("skipping test in -short mode")
@@ -1611,6 +1617,7 @@ func TestCancelRequestWithChannel(t *testing.T) {
16111617
}
16121618

16131619
func TestCancelRequestWithChannelBeforeDo(t *testing.T) {
1620+
t.Parallel()
16141621
defer afterTest(t)
16151622
unblockc := make(chan bool)
16161623
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
@@ -2488,6 +2495,7 @@ func TestRetryIdempotentRequestsOnError(t *testing.T) {
24882495

24892496
// Issue 6981
24902497
func TestTransportClosesBodyOnError(t *testing.T) {
2498+
t.Parallel()
24912499
defer afterTest(t)
24922500
readBody := make(chan error, 1)
24932501
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {

0 commit comments

Comments
 (0)