MCPcopy
hub / github.com/kubernetes/client-go / TestWriteEventError

Function TestWriteEventError

tools/record/event_test.go:384–439  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

382}
383
384func TestWriteEventError(t *testing.T) {
385 type entry struct {
386 timesToSendError int
387 attemptsWanted int
388 err error
389 }
390 table := map[string]*entry{
391 "giveUp1": {
392 timesToSendError: 1000,
393 attemptsWanted: 1,
394 err: &restclient.RequestConstructionError{},
395 },
396 "giveUp2": {
397 timesToSendError: 1000,
398 attemptsWanted: 1,
399 err: &errors.StatusError{},
400 },
401 "retry1": {
402 timesToSendError: 1000,
403 attemptsWanted: 12,
404 err: &errors.UnexpectedObjectError{},
405 },
406 "retry2": {
407 timesToSendError: 1000,
408 attemptsWanted: 12,
409 err: fmt.Errorf("A weird error"),
410 },
411 "succeedEventually": {
412 timesToSendError: 2,
413 attemptsWanted: 2,
414 err: fmt.Errorf("A weird error"),
415 },
416 }
417
418 clock := clock.IntervalClock{Time: time.Now(), Duration: time.Second}
419 eventCorrelator := NewEventCorrelator(&clock)
420 randGen := rand.New(rand.NewSource(time.Now().UnixNano()))
421
422 for caseName, ent := range table {
423 attempts := 0
424 sink := &testEventSink{
425 OnCreate: func(event *v1.Event) (*v1.Event, error) {
426 attempts++
427 if attempts < ent.timesToSendError {
428 return nil, ent.err
429 }
430 return event, nil
431 },
432 }
433 ev := &v1.Event{}
434 recordToSink(sink, ev, eventCorrelator, randGen, 0)
435 if attempts != ent.attemptsWanted {
436 t.Errorf("case %v: wanted %d, got %d attempts", caseName, ent.attemptsWanted, attempts)
437 }
438 }
439}
440
441func TestUpdateExpiredEvent(t *testing.T) {

Callers

nothing calls this directly

Calls 4

NewEventCorrelatorFunction · 0.85
recordToSinkFunction · 0.85
ErrorfMethod · 0.65
NowMethod · 0.65

Tested by

no test coverage detected