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

Side by Side Diff: net/nqe/socket_watcher_unittest.cc

Issue 2690113004: Throttle Socket watcher RTT notifications from QUIC (Closed)
Patch Set: ps Created 3 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/nqe/socket_watcher.h"
6
7 #include <memory>
8
9 #include "base/bind.h"
10 #include "base/test/simple_test_tick_clock.h"
11 #include "base/threading/thread_task_runner_handle.h"
12 #include "base/time/time.h"
13 #include "net/socket/socket_performance_watcher.h"
14 #include "net/socket/socket_performance_watcher_factory.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace net {
18
19 namespace nqe {
20
21 namespace internal {
22
23 namespace {
24
25 void OnUpdatedRTTAvailable(SocketPerformanceWatcherFactory::Protocol protocol,
26 const base::TimeDelta& rtt) {}
27
28 // Verify that the buffer size is never exceeded.
29 TEST(NetworkQualitySocketWatcherTest, NotificationsThrottled) {
30 SocketWatcher socket_watcher(SocketPerformanceWatcherFactory::PROTOCOL_QUIC,
31 base::TimeDelta::FromMilliseconds(2000),
32 base::ThreadTaskRunnerHandle::Get(),
33 base::Bind(OnUpdatedRTTAvailable));
34
35 std::unique_ptr<base::SimpleTestTickClock> tick_clock(
36 new base::SimpleTestTickClock());
37 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get();
38 tick_clock_ptr->SetNowTicks(base::TimeTicks::Now());
39
40 socket_watcher.SetTickClockForTesting(std::move(tick_clock));
RyanSturm 2017/02/15 17:42:08 nit: I'd prefer this passed a constructor param, a
tbansal1 2017/02/15 20:37:42 Done.
41
42 EXPECT_TRUE(socket_watcher.ShouldNotifyUpdatedRTT());
43 socket_watcher.OnUpdatedRTTAvailable(base::TimeDelta::FromSeconds(10));
44
45 EXPECT_FALSE(socket_watcher.ShouldNotifyUpdatedRTT());
46
47 tick_clock_ptr->Advance(base::TimeDelta::FromMilliseconds(1000));
48 // Minimum interval between consecutive notifications is 2000 msec.
49 EXPECT_FALSE(socket_watcher.ShouldNotifyUpdatedRTT());
50
51 // Advance the clock by 1000 msec more so that the current time is at least
52 // 2000 msec more than the last time |socket_watcher| received a notification.
53 tick_clock_ptr->Advance(base::TimeDelta::FromMilliseconds(1000));
54 EXPECT_TRUE(socket_watcher.ShouldNotifyUpdatedRTT());
55 }
56
57 } // namespace
58
59 } // namespace internal
60
61 } // namespace nqe
62
63 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698