File: errorRetryTest.c

package info (click to toggle)
pgbackrest 2.57.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,344 kB
  • sloc: ansic: 127,546; xml: 19,452; perl: 12,761; pascal: 3,279; sh: 91; sql: 32; makefile: 23
file content (111 lines) | stat: -rw-r--r-- 3,658 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/***********************************************************************************************************************************
Error Retry Message Test
***********************************************************************************************************************************/
#include "common/harnessTime.h"

/***********************************************************************************************************************************
Test Run
***********************************************************************************************************************************/
static void
testRun(void)
{
    FUNCTION_HARNESS_VOID();

    // *****************************************************************************************************************************
    if (testBegin("ErrorRetry"))
    {
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("retry (detail disabled)");
        {
            ErrorRetry *const retry = errRetryNew();

            TRY_BEGIN()
            {
                THROW(FormatError, "message1");
            }
            CATCH_ANY()
            {
                TEST_RESULT_VOID(errRetryAddP(retry), "add retry");
            }
            TRY_END();

            TRY_BEGIN()
            {
                THROW(KernelError, "message2");
            }
            CATCH_ANY()
            {
                TEST_RESULT_VOID(errRetryAddP(retry, errorType(), STR(errorMessage())), "add retry");
            }
            TRY_END();

            TEST_RESULT_BOOL(errRetryType(retry) == &FormatError, true, "error type");
            TEST_RESULT_STR_Z(
                errRetryMessage(retry),
                "message1\n"
                "[RETRY DETAIL OMITTED]",
                "error message");
        }

        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("retry (detail enabled)");
        {
            hrnErrorRetryDetailEnable();

            TimeMSec timeList[] = {0, 50, 75, 150};
            hrnTimeMSecSet(timeList, LENGTH_OF(timeList));

            ErrorRetry *const retry = errRetryNew();

            TRY_BEGIN()
            {
                THROW(FormatError, "message1");
            }
            CATCH_ANY()
            {
                TEST_RESULT_VOID(errRetryAddP(retry), "add retry");
            }
            TRY_END();

            TRY_BEGIN()
            {
                THROW(FormatError, "message1");
            }
            CATCH_ANY()
            {
                TEST_RESULT_VOID(errRetryAddP(retry), "add retry");
            }
            TRY_END();

            TRY_BEGIN()
            {
                THROW(KernelError, "message2");
            }
            CATCH_ANY()
            {
                TEST_RESULT_VOID(errRetryAddP(retry), "add retry");
            }
            TRY_END();

            TRY_BEGIN()
            {
                THROW(ServiceError, "message1");
            }
            CATCH_ANY()
            {
                TEST_RESULT_VOID(errRetryAddP(retry), "add retry");
            }
            TRY_END();

            TEST_RESULT_BOOL(errRetryType(retry) == &FormatError, true, "error type");
            TEST_RESULT_STR_Z(
                errRetryMessage(retry),
                "message1\n"
                "    [FormatError] on 2 retries from 50-150ms: message1\n"
                "    [KernelError] on retry at 75ms: message2",
                "error message");
        }
    }

    FUNCTION_HARNESS_RETURN_VOID();
}