Skip to content

Commit abae788

Browse files
committed
[nrf fromtree] tests: coap_client: Add testcase for Ack failure
Add testcase where sending Ack to incomming Confirmable message fails. This should be reported to application as now the server is unaware that transmission have succeeded, so we cannot thread it as success. Signed-off-by: Seppo Takalo <[email protected]> (cherry picked from commit fc51fa4)
1 parent c5f94cf commit abae788

File tree

1 file changed

+35
-0
lines changed
  • tests/net/lib/coap_client/src

1 file changed

+35
-0
lines changed

tests/net/lib/coap_client/src/main.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,41 @@ ZTEST(coap_client, test_separate_response_lost)
747747
zassert_equal(last_response_code, -ETIMEDOUT, "");
748748
}
749749

750+
ZTEST(coap_client, test_separate_response_ack_fail)
751+
{
752+
int ret = 0;
753+
struct k_sem sem;
754+
struct sockaddr address = {0};
755+
struct coap_client_request client_request = {
756+
.method = COAP_METHOD_GET,
757+
.confirmable = true,
758+
.path = test_path,
759+
.fmt = COAP_CONTENT_FORMAT_TEXT_PLAIN,
760+
.cb = coap_callback,
761+
.payload = short_payload,
762+
.len = strlen(short_payload),
763+
.user_data = &sem,
764+
};
765+
zassert_ok(k_sem_init(&sem, 0, 1));
766+
767+
int (*sendto_fakes[])(int, void *, size_t, int, const struct sockaddr *, socklen_t) = {
768+
z_impl_zsock_sendto_custom_fake,
769+
z_impl_zsock_sendto_custom_fake_err,
770+
};
771+
772+
SET_CUSTOM_FAKE_SEQ(z_impl_zsock_sendto, sendto_fakes, ARRAY_SIZE(sendto_fakes));
773+
z_impl_zsock_recvfrom_fake.custom_fake = z_impl_zsock_recvfrom_custom_fake_empty_ack;
774+
775+
k_sleep(K_MSEC(1));
776+
777+
LOG_INF("Send request");
778+
ret = coap_client_req(&client, 0, &address, &client_request, NULL);
779+
zassert_true(ret >= 0, "Sending request failed, %d", ret);
780+
781+
zassert_ok(k_sem_take(&sem, K_MSEC(COAP_SEPARATE_TIMEOUT)));
782+
zassert_equal(last_response_code, -ENETDOWN, "");
783+
}
784+
750785
ZTEST(coap_client, test_multiple_requests)
751786
{
752787
int ret = 0;

0 commit comments

Comments
 (0)