Skip to content

Commit

Permalink
Fix telemetry test flakiness
Browse files Browse the repository at this point in the history
In telemetry test we are using an external service for checking
status codes and that service can have intermittent outages which
cause this test to fail. Retrying the request should make the
test a bit more reliable.
  • Loading branch information
antekresic committed Dec 22, 2023
1 parent 2bd06e2 commit 883037a
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions test/src/telemetry/test_telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
#define HTTPS_PORT 443
#define TEST_ENDPOINT "postman-echo.com"

/* Since we rely on an external service to test request statuses, we should retry
* a few times if we are not getting the correct response. This should reduce
* test flakiness.
*/
#define INVALID_STATUS_RETRIES 5

TS_FUNCTION_INFO_V1(ts_test_status);
TS_FUNCTION_INFO_V1(ts_test_status_ssl);
TS_FUNCTION_INFO_V1(ts_test_status_mock);
Expand Down Expand Up @@ -76,17 +82,33 @@ test_factory(ConnectionType type, int status, char *host, int port)
ts_connection_mock_set_recv_buf(conn, test_string, strlen(test_string));
#endif

req = build_request(status);
int retries = 0;
while (retries < INVALID_STATUS_RETRIES)
{
req = build_request(status);

rsp = ts_http_response_state_create();
rsp = ts_http_response_state_create();

err = ts_http_send_and_recv(conn, req, rsp);
err = ts_http_send_and_recv(conn, req, rsp);

ts_http_request_destroy(req);
ts_connection_destroy(conn);
ts_http_request_destroy(req);

if (err != HTTP_ERROR_NONE)
elog(ERROR, "%s", ts_http_strerror(err));
if (err != HTTP_ERROR_NONE)
elog(ERROR, "%s", ts_http_strerror(err));

/* We are mocking the connection, no need to retry */
if (type == CONNECTION_MOCK)
break;

/* Got what we want, no need to retry */
if (ts_http_response_state_valid_status(rsp) ||
ts_http_response_state_status_code(rsp) == status)
break;

retries++;
}

ts_connection_destroy(conn);

if (!ts_http_response_state_valid_status(rsp))
elog(ERROR,
Expand Down

0 comments on commit 883037a

Please sign in to comment.