Properly close tmp files in unversioned

If not, using `go test -count=n` would make them pile up and ultimately
get to the limit of open files:

	2015/12/05 12:43:56 http: Accept error: accept tcp 127.0.0.1:39768: accept4: too many open files; retrying in 5ms
	2015/12/05 12:43:56 http: Accept error: accept tcp 127.0.0.1:46606: accept4: too many open files; retrying in 5ms
	2015/12/05 12:43:56 http: Accept error: accept tcp 127.0.0.1:46606: accept4: too many open files; retrying in 10ms
	2015/12/05 12:43:56 http: Accept error: accept tcp 127.0.0.1:46606: accept4: too many open files; retrying in 20ms

Steps to reproduce (no longer fails):

	godep go test -short -run '^$' -o test .
	./test -test.run '^TestDoRequestNewWayFile$' -test.count 100

Note that this might not fail if your `ulimit -n` is not low enough.
This commit is contained in:
Daniel Martí 2015-12-05 13:45:53 +01:00
parent c8f1019c10
commit 5505706891

View File

@ -241,6 +241,7 @@ func TestRequestBody(t *testing.T) {
if err != nil {
t.Fatalf("unable to create temp file")
}
defer f.Close()
os.Remove(f.Name())
r = (&Request{}).Body(f.Name())
if r.err == nil || r.body != nil {
@ -943,6 +944,7 @@ func TestDoRequestNewWayFile(t *testing.T) {
if err != nil {
t.Errorf("unexpected error: %v", err)
}
defer file.Close()
_, err = file.Write(reqBodyExpected)
if err != nil {