@@ -322,6 +322,7 @@ static void test_setup(void *data)
322
322
323
323
z_impl_zsock_recvfrom_fake .custom_fake = z_impl_zsock_recvfrom_custom_fake ;
324
324
z_impl_zsock_sendto_fake .custom_fake = z_impl_zsock_sendto_custom_fake ;
325
+ clear_socket_events (ZSOCK_POLLIN | ZSOCK_POLLOUT | ZSOCK_POLLERR );
325
326
326
327
for (i = 0 ; i < ARRAY_SIZE (messages_needing_response ); i ++ ) {
327
328
messages_needing_response [i ] = 0 ;
@@ -727,5 +728,65 @@ ZTEST(coap_client, test_multiple_clients)
727
728
zassert_ok (k_sem_take (& sem1 , K_MSEC (MORE_THAN_EXCHANGE_LIFETIME_MS )));
728
729
zassert_ok (k_sem_take (& sem2 , K_MSEC (MORE_THAN_EXCHANGE_LIFETIME_MS )));
729
730
zassert_equal (last_response_code , COAP_RESPONSE_CODE_OK , "Unexpected response" );
731
+ }
732
+
733
+
734
+ ZTEST (coap_client , test_poll_err )
735
+ {
736
+ int ret = 0 ;
737
+ struct sockaddr address = {0 };
738
+ struct coap_client_request client_request = {
739
+ .method = COAP_METHOD_GET ,
740
+ .confirmable = true,
741
+ .path = test_path ,
742
+ .fmt = COAP_CONTENT_FORMAT_TEXT_PLAIN ,
743
+ .cb = coap_callback ,
744
+ .payload = short_payload ,
745
+ .len = strlen (short_payload ),
746
+ };
747
+
748
+ z_impl_zsock_sendto_fake .custom_fake = z_impl_zsock_sendto_custom_fake_no_reply ;
749
+ set_socket_events (ZSOCK_POLLERR );
750
+
751
+ k_sleep (K_MSEC (1 ));
752
+
753
+ LOG_INF ("Send request" );
754
+ ret = coap_client_req (& client , 0 , & address , & client_request , NULL );
755
+ zassert_true (ret >= 0 , "Sending request failed, %d" , ret );
756
+
757
+ k_sleep (K_MSEC (MORE_THAN_EXCHANGE_LIFETIME_MS ));
758
+ zassert_equal (last_response_code , - EIO , "Unexpected response" );
759
+ }
760
+
761
+ ZTEST (coap_client , test_poll_err_after_response )
762
+ {
763
+ int ret = 0 ;
764
+ struct k_sem sem1 ;
765
+ struct sockaddr address = {0 };
766
+ struct coap_client_request client_request = {
767
+ .method = COAP_METHOD_GET ,
768
+ .confirmable = true,
769
+ .path = test_path ,
770
+ .fmt = COAP_CONTENT_FORMAT_TEXT_PLAIN ,
771
+ .cb = coap_callback ,
772
+ .payload = short_payload ,
773
+ .len = strlen (short_payload ),
774
+ .user_data = & sem1
775
+ };
776
+
777
+ zassert_ok (k_sem_init (& sem1 , 0 , 1 ));
778
+ z_impl_zsock_sendto_fake .custom_fake = z_impl_zsock_sendto_custom_fake_no_reply ;
779
+ set_socket_events (ZSOCK_POLLIN );
780
+
781
+ k_sleep (K_MSEC (1 ));
782
+
783
+ LOG_INF ("Send request" );
784
+ ret = coap_client_req (& client , 0 , & address , & client_request , NULL );
785
+ zassert_true (ret >= 0 , "Sending request failed, %d" , ret );
786
+
787
+ zassert_ok (k_sem_take (& sem1 , K_MSEC (MORE_THAN_EXCHANGE_LIFETIME_MS )));
788
+ zassert_equal (last_response_code , COAP_RESPONSE_CODE_OK , "Unexpected response" );
730
789
790
+ set_socket_events (ZSOCK_POLLERR );
791
+ zassert_not_ok (k_sem_take (& sem1 , K_MSEC (MORE_THAN_EXCHANGE_LIFETIME_MS )));
731
792
}
0 commit comments