From f220aa1abacb4ece9082943a8e481e3193e3ae99 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Mon, 11 Aug 2014 17:12:53 -0700 Subject: [PATCH] Fix flaky TestOpGet and TestSyncCreateTimeout --- pkg/apiserver/apiserver_test.go | 9 ++++++--- pkg/apiserver/operation_test.go | 10 +++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/apiserver/apiserver_test.go b/pkg/apiserver/apiserver_test.go index 51d68201290..4e3a9c0a201 100644 --- a/pkg/apiserver/apiserver_test.go +++ b/pkg/apiserver/apiserver_test.go @@ -586,7 +586,7 @@ func expectApiStatus(t *testing.T, method, url string, data []byte, code int) *a func TestErrorsToAPIStatus(t *testing.T) { cases := map[error]api.Status{ - NewAlreadyExistsErr("foo", "bar"): api.Status{ + NewAlreadyExistsErr("foo", "bar"): { Status: api.StatusFailure, Code: http.StatusConflict, Reason: "already_exists", @@ -596,7 +596,7 @@ func TestErrorsToAPIStatus(t *testing.T) { ID: "bar", }, }, - NewConflictErr("foo", "bar", errors.New("failure")): api.Status{ + NewConflictErr("foo", "bar", errors.New("failure")): { Status: api.StatusFailure, Code: http.StatusConflict, Reason: "conflict", @@ -719,9 +719,12 @@ func TestWriteRAWJSONMarshalError(t *testing.T) { } func TestSyncCreateTimeout(t *testing.T) { + testOver := make(chan struct{}) + defer close(testOver) storage := SimpleRESTStorage{ injectedFunction: func(obj interface{}) (interface{}, error) { - time.Sleep(5 * time.Millisecond) + // Eliminate flakes by ensuring the create operation takes longer than this test. + <-testOver return obj, nil }, } diff --git a/pkg/apiserver/operation_test.go b/pkg/apiserver/operation_test.go index 30594069c62..bd082084c20 100644 --- a/pkg/apiserver/operation_test.go +++ b/pkg/apiserver/operation_test.go @@ -140,7 +140,15 @@ func TestOperationsList(t *testing.T) { } func TestOpGet(t *testing.T) { - simpleStorage := &SimpleRESTStorage{} + testOver := make(chan struct{}) + defer close(testOver) + simpleStorage := &SimpleRESTStorage{ + injectedFunction: func(obj interface{}) (interface{}, error) { + // Eliminate flakes by ensuring the create operation takes longer than this test. + <-testOver + return obj, nil + }, + } handler := New(map[string]RESTStorage{ "foo": simpleStorage, }, codec, "/prefix/version")