Commit 04d732b4 authored by Russ Cox's avatar Russ Cox

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/18087Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent acc15001
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"hash" "hash"
"internal/testenv"
"io" "io"
"io/ioutil" "io/ioutil"
"sort" "sort"
...@@ -19,6 +20,9 @@ import ( ...@@ -19,6 +20,9 @@ import (
) )
func TestOver65kFiles(t *testing.T) { func TestOver65kFiles(t *testing.T) {
if testing.Short() && testenv.Builder() == "" {
t.Skip("skipping in short mode")
}
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
w := NewWriter(buf) w := NewWriter(buf)
const nFiles = (1 << 16) + 42 const nFiles = (1 << 16) + 42
......
...@@ -7,6 +7,7 @@ package flate ...@@ -7,6 +7,7 @@ package flate
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"internal/testenv"
"io" "io"
"io/ioutil" "io/ioutil"
"reflect" "reflect"
...@@ -343,6 +344,9 @@ var deflateInflateStringTests = []deflateInflateStringTest{ ...@@ -343,6 +344,9 @@ var deflateInflateStringTests = []deflateInflateStringTest{
} }
func TestDeflateInflateString(t *testing.T) { func TestDeflateInflateString(t *testing.T) {
if testing.Short() && testenv.Builder() == "" {
t.Skip("skipping in short mode")
}
for _, test := range deflateInflateStringTests { for _, test := range deflateInflateStringTests {
gold, err := ioutil.ReadFile(test.filename) gold, err := ioutil.ReadFile(test.filename)
if err != nil { if err != nil {
...@@ -436,7 +440,11 @@ func TestWriterReset(t *testing.T) { ...@@ -436,7 +440,11 @@ func TestWriterReset(t *testing.T) {
t.Fatalf("NewWriter: %v", err) t.Fatalf("NewWriter: %v", err)
} }
buf := []byte("hello world") buf := []byte("hello world")
for i := 0; i < 1024; i++ { n := 1024
if testing.Short() {
n = 10
}
for i := 0; i < n; i++ {
w.Write(buf) w.Write(buf)
} }
w.Reset(ioutil.Discard) w.Reset(ioutil.Discard)
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package lzw package lzw
import ( import (
"internal/testenv"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
...@@ -13,6 +14,7 @@ import ( ...@@ -13,6 +14,7 @@ import (
) )
var filenames = []string{ var filenames = []string{
"../testdata/gettysburg.txt",
"../testdata/e.txt", "../testdata/e.txt",
"../testdata/pi.txt", "../testdata/pi.txt",
} }
...@@ -89,10 +91,16 @@ func TestWriter(t *testing.T) { ...@@ -89,10 +91,16 @@ func TestWriter(t *testing.T) {
for _, filename := range filenames { for _, filename := range filenames {
for _, order := range [...]Order{LSB, MSB} { for _, order := range [...]Order{LSB, MSB} {
// The test data "2.71828 etcetera" is ASCII text requiring at least 6 bits. // The test data "2.71828 etcetera" is ASCII text requiring at least 6 bits.
for _, litWidth := range [...]int{6, 7, 8} { for litWidth := 6; litWidth <= 8; litWidth++ {
if filename == "../testdata/gettysburg.txt" && litWidth == 6 {
continue
}
testFile(t, filename, order, litWidth) testFile(t, filename, order, litWidth)
} }
} }
if testing.Short() && testenv.Builder() == "" {
break
}
} }
} }
......
Four score and seven years ago our fathers brought forth on
this continent, a new nation, conceived in Liberty, and dedicated
to the proposition that all men are created equal.
Now we are engaged in a great Civil War, testing whether that
nation, or any nation so conceived and so dedicated, can long
endure.
We are met on a great battle-field of that war.
We have come to dedicate a portion of that field, as a final
resting place for those who here gave their lives that that
nation might live. It is altogether fitting and proper that
we should do this.
But, in a larger sense, we can not dedicate - we can not
consecrate - we can not hallow - this ground.
The brave men, living and dead, who struggled here, have
consecrated it, far above our poor power to add or detract.
The world will little note, nor long remember what we say here,
but it can never forget what they did here.
It is for us the living, rather, to be dedicated here to the
unfinished work which they who fought here have thus far so
nobly advanced. It is rather for us to be here dedicated to
the great task remaining before us - that from these honored
dead we take increased devotion to that cause for which they
gave the last full measure of devotion -
that we here highly resolve that these dead shall not have
died in vain - that this nation, under God, shall have a new
birth of freedom - and that government of the people, by the
people, for the people, shall not perish from this earth.
Abraham Lincoln, November 19, 1863, Gettysburg, Pennsylvania
...@@ -7,6 +7,7 @@ package zlib ...@@ -7,6 +7,7 @@ package zlib
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"internal/testenv"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
...@@ -14,6 +15,7 @@ import ( ...@@ -14,6 +15,7 @@ import (
) )
var filenames = []string{ var filenames = []string{
"../testdata/gettysburg.txt",
"../testdata/e.txt", "../testdata/e.txt",
"../testdata/pi.txt", "../testdata/pi.txt",
} }
...@@ -152,22 +154,34 @@ func TestWriter(t *testing.T) { ...@@ -152,22 +154,34 @@ func TestWriter(t *testing.T) {
} }
func TestWriterBig(t *testing.T) { func TestWriterBig(t *testing.T) {
for _, fn := range filenames { for i, fn := range filenames {
testFileLevelDict(t, fn, DefaultCompression, "") testFileLevelDict(t, fn, DefaultCompression, "")
testFileLevelDict(t, fn, NoCompression, "") testFileLevelDict(t, fn, NoCompression, "")
for level := BestSpeed; level <= BestCompression; level++ { for level := BestSpeed; level <= BestCompression; level++ {
testFileLevelDict(t, fn, level, "") testFileLevelDict(t, fn, level, "")
if level >= 1 && testing.Short() && testenv.Builder() == "" {
break
}
}
if i == 0 && testing.Short() && testenv.Builder() == "" {
break
} }
} }
} }
func TestWriterDict(t *testing.T) { func TestWriterDict(t *testing.T) {
const dictionary = "0123456789." const dictionary = "0123456789."
for _, fn := range filenames { for i, fn := range filenames {
testFileLevelDict(t, fn, DefaultCompression, dictionary) testFileLevelDict(t, fn, DefaultCompression, dictionary)
testFileLevelDict(t, fn, NoCompression, dictionary) testFileLevelDict(t, fn, NoCompression, dictionary)
for level := BestSpeed; level <= BestCompression; level++ { for level := BestSpeed; level <= BestCompression; level++ {
testFileLevelDict(t, fn, level, dictionary) testFileLevelDict(t, fn, level, dictionary)
if level >= 1 && testing.Short() && testenv.Builder() == "" {
break
}
}
if i == 0 && testing.Short() && testenv.Builder() == "" {
break
} }
} }
} }
...@@ -179,10 +193,11 @@ func TestWriterReset(t *testing.T) { ...@@ -179,10 +193,11 @@ func TestWriterReset(t *testing.T) {
testFileLevelDictReset(t, fn, DefaultCompression, nil) testFileLevelDictReset(t, fn, DefaultCompression, nil)
testFileLevelDictReset(t, fn, NoCompression, []byte(dictionary)) testFileLevelDictReset(t, fn, NoCompression, []byte(dictionary))
testFileLevelDictReset(t, fn, DefaultCompression, []byte(dictionary)) testFileLevelDictReset(t, fn, DefaultCompression, []byte(dictionary))
if !testing.Short() { if testing.Short() {
for level := BestSpeed; level <= BestCompression; level++ { break
testFileLevelDictReset(t, fn, level, nil) }
} for level := BestSpeed; level <= BestCompression; level++ {
testFileLevelDictReset(t, fn, level, nil)
} }
} }
} }
......
...@@ -164,7 +164,11 @@ func TestImportStdLib(t *testing.T) { ...@@ -164,7 +164,11 @@ func TestImportStdLib(t *testing.T) {
return return
} }
nimports := testDir(t, "", time.Now().Add(maxTime)) // installed packages dt := maxTime
if testing.Short() && testenv.Builder() == "" {
dt = 10 * time.Millisecond
}
nimports := testDir(t, "", time.Now().Add(dt)) // installed packages
t.Logf("tested %d imports", nimports) t.Logf("tested %d imports", nimports)
} }
......
...@@ -127,6 +127,10 @@ func testTestDir(t *testing.T, path string, ignore ...string) { ...@@ -127,6 +127,10 @@ func testTestDir(t *testing.T, path string, ignore ...string) {
func TestStdTest(t *testing.T) { func TestStdTest(t *testing.T) {
testenv.MustHaveGoBuild(t) testenv.MustHaveGoBuild(t)
if testing.Short() && testenv.Builder() == "" {
t.Skip("skipping in short mode")
}
// test/recover4.go is only built for Linux and Darwin. // test/recover4.go is only built for Linux and Darwin.
// TODO(gri) Remove once tests consider +build tags (issue 10370). // TODO(gri) Remove once tests consider +build tags (issue 10370).
if runtime.GOOS != "linux" && runtime.GOOS != "darwin" { if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
...@@ -142,6 +146,10 @@ func TestStdTest(t *testing.T) { ...@@ -142,6 +146,10 @@ func TestStdTest(t *testing.T) {
func TestStdFixed(t *testing.T) { func TestStdFixed(t *testing.T) {
testenv.MustHaveGoBuild(t) testenv.MustHaveGoBuild(t)
if testing.Short() && testenv.Builder() == "" {
t.Skip("skipping in short mode")
}
testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "fixedbugs"), testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "fixedbugs"),
"bug248.go", "bug302.go", "bug369.go", // complex test instructions - ignore "bug248.go", "bug302.go", "bug369.go", // complex test instructions - ignore
"issue6889.go", // gc-specific test "issue6889.go", // gc-specific test
...@@ -247,7 +255,7 @@ func pkgFilenames(dir string) ([]string, error) { ...@@ -247,7 +255,7 @@ func pkgFilenames(dir string) ([]string, error) {
func walkDirs(t *testing.T, dir string) { func walkDirs(t *testing.T, dir string) {
// limit run time for short tests // limit run time for short tests
if testing.Short() && time.Since(start) >= 750*time.Millisecond { if testing.Short() && time.Since(start) >= 10*time.Millisecond {
return return
} }
......
...@@ -1378,6 +1378,14 @@ func TestModSqrt(t *testing.T) { ...@@ -1378,6 +1378,14 @@ func TestModSqrt(t *testing.T) {
t.Errorf("#%d: failed (sqrt(e) = %s)", i, &sqrt) t.Errorf("#%d: failed (sqrt(e) = %s)", i, &sqrt)
} }
} }
if testing.Short() && i > 2 {
break
}
}
if testing.Short() {
return
} }
// exhaustive test for small values // exhaustive test for small values
......
...@@ -7,6 +7,7 @@ package rand ...@@ -7,6 +7,7 @@ package rand
import ( import (
"errors" "errors"
"fmt" "fmt"
"internal/testenv"
"math" "math"
"os" "os"
"runtime" "runtime"
...@@ -327,9 +328,10 @@ func TestExpTables(t *testing.T) { ...@@ -327,9 +328,10 @@ func TestExpTables(t *testing.T) {
func TestFloat32(t *testing.T) { func TestFloat32(t *testing.T) {
// For issue 6721, the problem came after 7533753 calls, so check 10e6. // For issue 6721, the problem came after 7533753 calls, so check 10e6.
num := int(10e6) num := int(10e6)
// But do the full amount only on builders (not locally).
// But ARM5 floating point emulation is slow (Issue 10749), so // But ARM5 floating point emulation is slow (Issue 10749), so
// do less for that builder: // do less for that builder:
if testing.Short() && runtime.GOARCH == "arm" && os.Getenv("GOARM") == "5" { if testing.Short() && (testenv.Builder() == "" || runtime.GOARCH == "arm" && os.Getenv("GOARM") == "5") {
num /= 100 // 1.72 seconds instead of 172 seconds num /= 100 // 1.72 seconds instead of 172 seconds
} }
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "fmt"
"internal/testenv"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
...@@ -454,6 +455,7 @@ func TestServerTimeouts(t *testing.T) { ...@@ -454,6 +455,7 @@ func TestServerTimeouts(t *testing.T) {
if runtime.GOOS == "plan9" { if runtime.GOOS == "plan9" {
t.Skip("skipping test; see https://golang.org/issue/7237") t.Skip("skipping test; see https://golang.org/issue/7237")
} }
t.Parallel()
defer afterTest(t) defer afterTest(t)
reqNum := 0 reqNum := 0
ts := httptest.NewUnstartedServer(HandlerFunc(func(res ResponseWriter, req *Request) { ts := httptest.NewUnstartedServer(HandlerFunc(func(res ResponseWriter, req *Request) {
...@@ -937,6 +939,7 @@ func TestTLSHandshakeTimeout(t *testing.T) { ...@@ -937,6 +939,7 @@ func TestTLSHandshakeTimeout(t *testing.T) {
if runtime.GOOS == "plan9" { if runtime.GOOS == "plan9" {
t.Skip("skipping test; see https://golang.org/issue/7237") t.Skip("skipping test; see https://golang.org/issue/7237")
} }
t.Parallel()
defer afterTest(t) defer afterTest(t)
ts := httptest.NewUnstartedServer(HandlerFunc(func(w ResponseWriter, r *Request) {})) ts := httptest.NewUnstartedServer(HandlerFunc(func(w ResponseWriter, r *Request) {}))
errc := make(chanWriter, 10) // but only expecting 1 errc := make(chanWriter, 10) // but only expecting 1
...@@ -1277,6 +1280,9 @@ func TestServerUnreadRequestBodyLittle(t *testing.T) { ...@@ -1277,6 +1280,9 @@ func TestServerUnreadRequestBodyLittle(t *testing.T) {
// should ignore client request bodies that a handler didn't read // should ignore client request bodies that a handler didn't read
// and close the connection. // and close the connection.
func TestServerUnreadRequestBodyLarge(t *testing.T) { func TestServerUnreadRequestBodyLarge(t *testing.T) {
if testing.Short() && testenv.Builder() == "" {
t.Log("skipping in short mode")
}
conn := new(testConn) conn := new(testConn)
body := strings.Repeat("x", 1<<20) body := strings.Repeat("x", 1<<20)
conn.readBuf.Write([]byte(fmt.Sprintf( conn.readBuf.Write([]byte(fmt.Sprintf(
...@@ -1407,6 +1413,9 @@ var handlerBodyCloseTests = [...]handlerBodyCloseTest{ ...@@ -1407,6 +1413,9 @@ var handlerBodyCloseTests = [...]handlerBodyCloseTest{
} }
func TestHandlerBodyClose(t *testing.T) { func TestHandlerBodyClose(t *testing.T) {
if testing.Short() && testenv.Builder() == "" {
t.Skip("skipping in -short mode")
}
for i, tt := range handlerBodyCloseTests { for i, tt := range handlerBodyCloseTests {
testHandlerBodyClose(t, i, tt) testHandlerBodyClose(t, i, tt)
} }
......
...@@ -436,6 +436,7 @@ func TestTransportMaxPerHostIdleConns(t *testing.T) { ...@@ -436,6 +436,7 @@ func TestTransportMaxPerHostIdleConns(t *testing.T) {
} }
func TestTransportServerClosingUnexpectedly(t *testing.T) { func TestTransportServerClosingUnexpectedly(t *testing.T) {
t.Parallel()
defer afterTest(t) defer afterTest(t)
ts := httptest.NewServer(hostPortHandler) ts := httptest.NewServer(hostPortHandler)
defer ts.Close() defer ts.Close()
...@@ -968,6 +969,7 @@ func TestTransportGzipShort(t *testing.T) { ...@@ -968,6 +969,7 @@ func TestTransportGzipShort(t *testing.T) {
// tests that persistent goroutine connections shut down when no longer desired. // tests that persistent goroutine connections shut down when no longer desired.
func TestTransportPersistConnLeak(t *testing.T) { func TestTransportPersistConnLeak(t *testing.T) {
t.Parallel()
defer afterTest(t) defer afterTest(t)
gotReqCh := make(chan bool) gotReqCh := make(chan bool)
unblockCh := make(chan bool) unblockCh := make(chan bool)
...@@ -1034,6 +1036,7 @@ func TestTransportPersistConnLeak(t *testing.T) { ...@@ -1034,6 +1036,7 @@ func TestTransportPersistConnLeak(t *testing.T) {
// golang.org/issue/4531: Transport leaks goroutines when // golang.org/issue/4531: Transport leaks goroutines when
// request.ContentLength is explicitly short // request.ContentLength is explicitly short
func TestTransportPersistConnLeakShortBody(t *testing.T) { func TestTransportPersistConnLeakShortBody(t *testing.T) {
t.Parallel()
defer afterTest(t) defer afterTest(t)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
})) }))
...@@ -1374,6 +1377,7 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) { ...@@ -1374,6 +1377,7 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) {
} }
func TestTransportResponseHeaderTimeout(t *testing.T) { func TestTransportResponseHeaderTimeout(t *testing.T) {
t.Parallel()
defer afterTest(t) defer afterTest(t)
if testing.Short() { if testing.Short() {
t.Skip("skipping timeout test in -short mode") t.Skip("skipping timeout test in -short mode")
...@@ -1445,6 +1449,7 @@ func TestTransportResponseHeaderTimeout(t *testing.T) { ...@@ -1445,6 +1449,7 @@ func TestTransportResponseHeaderTimeout(t *testing.T) {
} }
func TestTransportCancelRequest(t *testing.T) { func TestTransportCancelRequest(t *testing.T) {
t.Parallel()
defer afterTest(t) defer afterTest(t)
if testing.Short() { if testing.Short() {
t.Skip("skipping test in -short mode") t.Skip("skipping test in -short mode")
...@@ -1554,6 +1559,7 @@ Get = Get http://something.no-network.tld/: net/http: request canceled while wai ...@@ -1554,6 +1559,7 @@ Get = Get http://something.no-network.tld/: net/http: request canceled while wai
} }
func TestCancelRequestWithChannel(t *testing.T) { func TestCancelRequestWithChannel(t *testing.T) {
t.Parallel()
defer afterTest(t) defer afterTest(t)
if testing.Short() { if testing.Short() {
t.Skip("skipping test in -short mode") t.Skip("skipping test in -short mode")
...@@ -1611,6 +1617,7 @@ func TestCancelRequestWithChannel(t *testing.T) { ...@@ -1611,6 +1617,7 @@ func TestCancelRequestWithChannel(t *testing.T) {
} }
func TestCancelRequestWithChannelBeforeDo(t *testing.T) { func TestCancelRequestWithChannelBeforeDo(t *testing.T) {
t.Parallel()
defer afterTest(t) defer afterTest(t)
unblockc := make(chan bool) unblockc := make(chan bool)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
...@@ -2488,6 +2495,7 @@ func TestRetryIdempotentRequestsOnError(t *testing.T) { ...@@ -2488,6 +2495,7 @@ func TestRetryIdempotentRequestsOnError(t *testing.T) {
// Issue 6981 // Issue 6981
func TestTransportClosesBodyOnError(t *testing.T) { func TestTransportClosesBodyOnError(t *testing.T) {
t.Parallel()
defer afterTest(t) defer afterTest(t)
readBody := make(chan error, 1) readBody := make(chan error, 1)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
......
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