diff --git a/pkg/client/record/event.go b/pkg/client/record/event.go index 0cd6a3df403..91b93cdc48d 100644 --- a/pkg/client/record/event.go +++ b/pkg/client/record/event.go @@ -30,6 +30,9 @@ import ( "github.com/golang/glog" ) +// retryEventSleep is the time between record failures to retry. Available for test alteration. +var retryEventSleep = 1 * time.Second + // EventRecorder knows how to store events (client.Client implements it.) // EventRecorder must respect the namespace that will be embedded in 'event'. // It is assumed that EventRecorder will return the same sorts of errors as @@ -41,6 +44,7 @@ type EventRecorder interface { // StartRecording starts sending events to recorder. Call once while initializing // your binary. Subsequent calls will be ignored. The return value can be ignored // or used to stop recording, if desired. +// TODO: make me an object with parameterizable queue length and retry interval func StartRecording(recorder EventRecorder, source api.EventSource) watch.Interface { return GetEvents(func(event *api.Event) { // Make a copy before modification, because there could be multiple listeners. @@ -80,7 +84,7 @@ func StartRecording(recorder EventRecorder, source api.EventSource) watch.Interf break } glog.Errorf("Unable to write event: '%v' (will retry in 1 second)", err) - time.Sleep(1 * time.Second) + time.Sleep(retryEventSleep) } }) } diff --git a/pkg/client/record/event_test.go b/pkg/client/record/event_test.go index 8383424a509..0d64ebaa7a6 100644 --- a/pkg/client/record/event_test.go +++ b/pkg/client/record/event_test.go @@ -14,22 +14,26 @@ See the License for the specific language governing permissions and limitations under the License. */ -package record_test +package record import ( "fmt" "reflect" "strings" "testing" + "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" - "github.com/GoogleCloudPlatform/kubernetes/pkg/client/record" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) +func init() { + retryEventSleep = 1 * time.Microsecond +} + type testEventRecorder struct { OnEvent func(e *api.Event) (*api.Event, error) } @@ -142,16 +146,16 @@ func TestEventf(t *testing.T) { return event, nil }, } - recorder := record.StartRecording(&testEvents, api.EventSource{Component: "eventTest"}) - logger := record.StartLogging(t.Logf) // Prove that it is useful - logger2 := record.StartLogging(func(formatter string, args ...interface{}) { + recorder := StartRecording(&testEvents, api.EventSource{Component: "eventTest"}) + logger := StartLogging(t.Logf) // Prove that it is useful + logger2 := StartLogging(func(formatter string, args ...interface{}) { if e, a := item.expectLog, fmt.Sprintf(formatter, args...); e != a { t.Errorf("Expected '%v', got '%v'", e, a) } called <- struct{}{} }) - record.Eventf(item.obj, item.status, item.reason, item.messageFmt, item.elements...) + Eventf(item.obj, item.status, item.reason, item.messageFmt, item.elements...) <-called <-called @@ -204,7 +208,7 @@ func TestWriteEventError(t *testing.T) { } done := make(chan struct{}) - defer record.StartRecording( + defer StartRecording( &testEventRecorder{ OnEvent: func(event *api.Event) (*api.Event, error) { if event.Message == "finished" { @@ -227,9 +231,9 @@ func TestWriteEventError(t *testing.T) { ).Stop() for caseName := range table { - record.Event(ref, "Status", "Reason", caseName) + Event(ref, "Status", "Reason", caseName) } - record.Event(ref, "Status", "Reason", "finished") + Event(ref, "Status", "Reason", "finished") <-done for caseName, item := range table {