From 071f24be4c8991dfc5feefcb33bf06680784c6df Mon Sep 17 00:00:00 2001 From: Goto Ippei <76621063+paaaaay5@users.noreply.github.com> Date: Tue, 12 Mar 2024 15:53:04 +0900 Subject: [PATCH] [add] unretryableError test --- firequeue_test.go | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/firequeue_test.go b/firequeue_test.go index 600eec5..b2b8904 100644 --- a/firequeue_test.go +++ b/firequeue_test.go @@ -24,8 +24,24 @@ func (te *testAWSError) Error() string { return "retryable error" } +type errCodeMode string + +const ( + retryable errCodeMode = "retryable" + unretryable errCodeMode = "unretryable" +) + +var ecm = retryable + func (te *testAWSError) Code() string { - return request.ErrCodeResponseTimeout + switch ecm { + case retryable: + return request.ErrCodeResponseTimeout + case unretryable: + return request.CanceledErrorCode + default: + return "" + } } func (te *testAWSError) Message() string { @@ -408,3 +424,27 @@ func TestStat_RetryCount(t *testing.T) { } t.Log(stats) } + +func TestStat_UnRetryableErrorCount(t *testing.T) { + // It means always return unretryable error. + fhErrorRate = 10 + ecm = unretryable + + tf := &testFirehose{} + q := firequeue.New(tf, "env", firequeue.BatchSize(1)) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + go q.Loop(ctx) + time.Sleep(1000 * time.Millisecond) + err := q.Enqueue(&firehose.Record{}) + if err != nil { + t.Errorf("error should not be occurred but: %s", err) + } + time.Sleep(5 * time.Second) + stats := q.Stats() + if stats.UnretryableError == 0 { + t.Errorf("retryCount should be more than 0 but: %d", stats.RetryCount) + } + t.Log(stats) +}