From 678b57c2538fc0a1a132fda85901915a9d2c42bd Mon Sep 17 00:00:00 2001 From: Tymoteusz Bloch Date: Mon, 28 Oct 2019 13:51:18 +0100 Subject: [PATCH] Add code to verify if external Wifi module is still responsible after DNS Query flooding during DNS timeout test. DNS timeout test requires flooding device with DNS queries. This causes problem to ESP8266 module causing it to stuck for 11 sec. In result all following tests fails. To avoid this "smart delay" is added. If device preforms gethostbyname correctly then tests can proceed. Otherwise after 1 sec sleep gethostbyname is repeated until success or re-check limit (set to 15). Thanks to this all ethernet and non ESP8266 wireless devices don't need to wait but ESP must wait. --- .../dns/asynchronous_dns_timeouts.cpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/TESTS/netsocket/dns/asynchronous_dns_timeouts.cpp b/TESTS/netsocket/dns/asynchronous_dns_timeouts.cpp index 8c01298245..5c0a901bd9 100644 --- a/TESTS/netsocket/dns/asynchronous_dns_timeouts.cpp +++ b/TESTS/netsocket/dns/asynchronous_dns_timeouts.cpp @@ -33,6 +33,7 @@ int result_exp_timeout; const int EXTERNAL_THREAD_SIZE = 2048; const int EVENT_QUEUE_SIZE = 10; +const int MAX_TRIAL_ATTEMPTS = 15; events::EventQueue *event_queue; } @@ -66,9 +67,22 @@ void ASYNCHRONOUS_DNS_TIMEOUTS() // Depends on timing, but at least one operation shall fail to timeout TEST_ASSERT(result_exp_timeout > 0); - // Give event queue time to finalise before destructors - ThisThread::sleep_for(12000); - nsapi_dns_call_in_set(0); + + nsapi_dns_reset(); + SocketAddress address; + nsapi_error_t result; + int count = MAX_TRIAL_ATTEMPTS; + do { + result = NetworkInterface::get_default_instance()->gethostbyname(dns_test_hosts[0], &address); + if (result == NSAPI_ERROR_OK) { + return; + } + ThisThread::sleep_for(1000); + count--; + } while (result != NSAPI_ERROR_OK && count); + + } #endif // defined(MBED_CONF_RTOS_PRESENT) +