Skip to content

How long dose it recover when it breaker #61

@YuanWeiKang

Description

@YuanWeiKang

it's code

func TestBreaker22(t *testing.T) {
	brk := NewBreakerWithOptions(&Options{
		ShouldTrip: RateTripFunc(0.6, 100),
	})
	flag := 0
	start := time.Now().UnixNano()
	for i := 0; i < 200; i++ {
		err := brk.Call(func() error {
			return testDoSomething(flag)
		}, 0)

		last := atomic.LoadInt64(&brk.lastFailure)
		since := brk.Clock.Now().Sub(time.Unix(0, last))
		trip := atomic.LoadInt32(&brk.tripped)
		fmt.Printf("i:%d, trip:%d, last:%d, since:%+v, backOff:%+v, flag:%d, error:%s\n", i, trip, last, since, brk.nextBackOff, flag, err)

		if err == nil && brk.tripped == 0 {
			fmt.Printf("i:%d, trip:%d, duration:%d\n", i, brk.tripped, time.Now().UnixNano()-start)
			//break
		}
		if err != nil && strings.Contains(err.Error(), "breaker open") {
			flag = 1
			//time.Sleep(200 * time.Millisecond)
		}
	}
}

func testDoSomething(flag int) error {
	if flag == 0 {
		return fmt.Errorf("bad request")
	} else {
		return nil
	}
}

How do I calculate the recovery time?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions