Ejemplo n.º 1
0
func TestResponseGetPollingDelay(t *testing.T) {
	d1 := 10 * time.Second

	r := mocks.NewResponse()
	mocks.SetRetryHeader(r, d1)
	ar := Response{Response: r}

	d2 := ar.GetPollingDelay(time.Duration(0))
	if d1 != d2 {
		t.Errorf("autorest: Response#GetPollingDelay failed to return the correct delay -- expected %v, received %v",
			d1, d2)
	}
}
Ejemplo n.º 2
0
func TestPollForDurationsStopsWithinReason(t *testing.T) {
	client := mocks.NewSender()
	client.EmitErrors(-1)

	d := 10 * time.Millisecond
	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)
	mocks.SetRetryHeader(resp, d)
	client.SetResponse(resp)

	req, _ := NewPollingRequest(resp, NullAuthorizer{})

	start := time.Now()
	PollForDuration(client, req, time.Duration(0), d)
	if time.Now().Sub(start) > (time.Duration(5.0) * d) {
		t.Error("autorest: PollForDuration took too long to stop -- exceeded 5 times expected duration")
	}
}
Ejemplo n.º 3
0
func TestPollingHonorsDelay(t *testing.T) {
	client := mocks.NewSender()
	client.EmitErrors(-1)

	d1 := 10 * time.Millisecond
	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)
	mocks.SetRetryHeader(resp, d1)
	client.SetResponse(resp)

	req, _ := NewPollingRequest(resp, NullAuthorizer{})

	start := time.Now()
	PollForAttempts(client, req, time.Duration(0), 2)
	d2 := time.Now().Sub(start)
	if d2 < d1 {
		t.Errorf("autorest: Polling failed to honor delay -- expected %v, actual %v", d1.Seconds(), d2.Seconds())
	}
}
Ejemplo n.º 4
0
func TestAfterRetryDelayWaits(t *testing.T) {
	client := mocks.NewSender()
	client.EmitErrors(-1)

	d := 10 * time.Millisecond

	resp := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
	mocks.SetAcceptedHeaders(resp)
	mocks.SetRetryHeader(resp, d)
	client.SetResponse(resp)

	tt := time.Now()
	r, _ := SendWithSender(client, mocks.NewRequest(),
		AfterRetryDelay(d),
		DoRetryForAttempts(2, time.Duration(0)))
	s := time.Since(tt)
	if s < d {
		t.Error("autorest: AfterRetryDelay failed to wait for at least the specified duration")
	}

	Respond(r,
		ByClosing())
}