From 5505706891bf0363c1af549233ad9e49dc394f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 5 Dec 2015 13:45:53 +0100 Subject: [PATCH] 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. --- pkg/client/unversioned/request_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/client/unversioned/request_test.go b/pkg/client/unversioned/request_test.go index 7345954998c..e7c5a08b165 100644 --- a/pkg/client/unversioned/request_test.go +++ b/pkg/client/unversioned/request_test.go @@ -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 {