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

Unified Diff: content/renderer/scheduler/resource_dispatch_throttler_unittest.cc

Issue 1834853003: Allow continuous request dispatch below the throttle rate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: LogFLush Created 4 years, 9 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 | « content/renderer/scheduler/resource_dispatch_throttler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/scheduler/resource_dispatch_throttler_unittest.cc
diff --git a/content/renderer/scheduler/resource_dispatch_throttler_unittest.cc b/content/renderer/scheduler/resource_dispatch_throttler_unittest.cc
index a1dbcac7076b45fde695105bc068a5bb6f60c0ad..15a233430c4138611b216ea9c48d16566d3a1361 100644
--- a/content/renderer/scheduler/resource_dispatch_throttler_unittest.cc
+++ b/content/renderer/scheduler/resource_dispatch_throttler_unittest.cc
@@ -75,6 +75,7 @@ class ResourceDispatchThrottlerForTest : public ResourceDispatchThrottler {
scheduler,
base::TimeDelta::FromSecondsD(kFlushPeriodSeconds),
kRequestsPerFlush),
+ now_(base::TimeTicks() + base::TimeDelta::FromDays(1)),
flush_scheduled_(false) {}
~ResourceDispatchThrottlerForTest() override {}
@@ -252,6 +253,45 @@ TEST_F(ResourceDispatchThrottlerTest, NotThrottledIfSufficientTimePassed) {
}
}
+TEST_F(ResourceDispatchThrottlerTest, NotThrottledIfSendRateSufficientlyLow) {
+ SetHighPriorityWorkAnticipated(true);
+
+ // Continuous dispatch of resource requests below the allowed send rate
+ // should never throttled.
+ const base::TimeDelta kAllowedContinuousSendInterval =
+ base::TimeDelta::FromSecondsD((kFlushPeriodSeconds / kRequestsPerFlush) +
+ .00001);
+ for (size_t i = 0; i < kRequestsPerFlush * 10; ++i) {
+ Advance(kAllowedContinuousSendInterval);
+ RequestResource();
+ EXPECT_EQ(1U, GetAndResetSentMessageCount());
+ EXPECT_FALSE(FlushScheduled());
+ }
+}
+
+TEST_F(ResourceDispatchThrottlerTest, ThrottledIfSendRateSufficientlyHigh) {
+ SetHighPriorityWorkAnticipated(true);
+
+ // Continuous dispatch of resource requests above the allowed send rate
+ // should be throttled.
+ const base::TimeDelta kThrottledContinuousSendInterval =
+ base::TimeDelta::FromSecondsD((kFlushPeriodSeconds / kRequestsPerFlush) -
+ .00001);
+
+ for (size_t i = 0; i < kRequestsPerFlush * 10; ++i) {
+ Advance(kThrottledContinuousSendInterval);
+ RequestResource();
+ // Only the first batch of requests under the limit should be unthrottled.
+ if (i < kRequestsPerFlush) {
+ EXPECT_EQ(1U, GetAndResetSentMessageCount());
+ EXPECT_FALSE(FlushScheduled());
+ } else {
+ EXPECT_EQ(0U, GetAndResetSentMessageCount());
+ EXPECT_TRUE(FlushScheduled());
+ }
+ }
+}
+
TEST_F(ResourceDispatchThrottlerTest, NotThrottledIfSyncMessage) {
SetHighPriorityWorkAnticipated(true);
« no previous file with comments | « content/renderer/scheduler/resource_dispatch_throttler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698