Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Unified Diff: webrtc/p2p/base/stunrequest_unittest.cc

Issue 2300143005: Fixed flaky StunRequestTests which depended on the wall clock (Closed)
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/stunrequest_unittest.cc
diff --git a/webrtc/p2p/base/stunrequest_unittest.cc b/webrtc/p2p/base/stunrequest_unittest.cc
index 5fb34a85d263e1ec90e74dd59711e3cb9d97557a..47583b90e8e9072b36a18a3ecfd4059303cb2dda 100644
--- a/webrtc/p2p/base/stunrequest_unittest.cc
+++ b/webrtc/p2p/base/stunrequest_unittest.cc
@@ -9,6 +9,7 @@
*/
#include "webrtc/p2p/base/stunrequest.h"
+#include "webrtc/base/fakeclock.h"
#include "webrtc/base/gunit.h"
#include "webrtc/base/helpers.h"
#include "webrtc/base/logging.h"
@@ -17,12 +18,6 @@
using namespace cricket;
-// STUN timeout (with all retries) is 9500ms.
-// Add some margin of error for slow bots.
-// TODO(deadbeef): Use simulated clock instead of just increasing timeouts to
-// fix flaky tests.
-static const int kTimeoutMs = 15000;
-
class StunRequestTest : public testing::Test,
public sigslot::has_slots<> {
public:
@@ -150,18 +145,19 @@ TEST_F(StunRequestTest, TestUnexpected) {
// Test that requests are sent at the right times, and that the 9th request
// (sent at 7900 ms) can be properly replied to.
TEST_F(StunRequestTest, TestBackoff) {
+ const int MAX_TIMEOUT_MS = 10000;
+ rtc::ScopedFakeClock fake_clock;
StunMessage* req = CreateStunMessage(STUN_BINDING_REQUEST, NULL);
int64_t start = rtc::TimeMillis();
manager_.Send(new StunRequestThunker(req, this));
StunMessage* res = CreateStunMessage(STUN_BINDING_RESPONSE, req);
for (int i = 0; i < 9; ++i) {
- while (request_count_ == i)
- rtc::Thread::Current()->ProcessMessages(1);
+ EXPECT_TRUE_SIMULATED_WAIT(request_count_ != i, MAX_TIMEOUT_MS, fake_clock);
int64_t elapsed = rtc::TimeMillis() - start;
LOG(LS_INFO) << "STUN request #" << (i + 1)
<< " sent at " << elapsed << " ms";
- EXPECT_GE(TotalDelay(i + 1), elapsed);
+ EXPECT_EQ(TotalDelay(i), elapsed);
}
EXPECT_TRUE(manager_.CheckResponse(res));
@@ -174,13 +170,15 @@ TEST_F(StunRequestTest, TestBackoff) {
// Test that we timeout properly if no response is received in 9500 ms.
TEST_F(StunRequestTest, TestTimeout) {
+ rtc::ScopedFakeClock fake_clock;
StunMessage* req = CreateStunMessage(STUN_BINDING_REQUEST, NULL);
StunMessage* res = CreateStunMessage(STUN_BINDING_RESPONSE, req);
manager_.Send(new StunRequestThunker(req, this));
- rtc::Thread::Current()->ProcessMessages(kTimeoutMs);
- EXPECT_FALSE(manager_.CheckResponse(res));
+ // Simulate the 9500 ms STUN timeout
+ SIMULATED_WAIT(false, 9500, fake_clock);
+ EXPECT_FALSE(manager_.CheckResponse(res));
EXPECT_TRUE(response_ == NULL);
EXPECT_FALSE(success_);
EXPECT_FALSE(failure_);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698