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

Side by Side Diff: net/spdy/write_blocked_list_test.cc

Issue 989523005: Avoid duplicates in SPDY's write blocked list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use hash_map. Created 5 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 unified diff | Download patch
« net/quic/quic_session.cc ('K') | « net/spdy/write_blocked_list.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/spdy/write_blocked_list.h" 5 #include "net/spdy/write_blocked_list.h"
6 6
7 #include <deque> 7 #include <deque>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace { 11 namespace {
12 12
13 class WriteBlockedListPeer { 13 class WriteBlockedListPeer {
14 public: 14 public:
15 static std::deque<int>* GetWriteBlockedList( 15 static std::deque<int>* GetWriteBlockedList(
16 int i, 16 int i,
17 net::WriteBlockedList<int>* list) { 17 net::WriteBlockedList<int>* list) {
18 return &list->write_blocked_lists_[i]; 18 return &list->write_blocked_lists_[i];
19 } 19 }
20 }; 20 };
21 21
22 } // namespace 22 } // namespace
23 23
24 namespace net { 24 namespace net {
25 namespace test { 25 namespace test {
26 namespace { 26 namespace {
27 typedef WriteBlockedList<int> IntWriteBlockedList; 27 typedef WriteBlockedList<int> IntWriteBlockedList;
28 28
29 TEST(WriteBlockedListTest, GetHighestPriority) { 29 class WriteBlockedListTest : public ::testing::TestWithParam<bool> {
30 public:
31 WriteBlockedListTest() : list(GetParam()) {}
32
30 IntWriteBlockedList list; 33 IntWriteBlockedList list;
34 };
35
36 TEST_P(WriteBlockedListTest, GetHighestPriority) {
31 EXPECT_FALSE(list.HasWriteBlockedStreams()); 37 EXPECT_FALSE(list.HasWriteBlockedStreams());
32 list.PushBack(1, 1); 38 list.PushBack(1, 1);
33 EXPECT_TRUE(list.HasWriteBlockedStreams()); 39 EXPECT_TRUE(list.HasWriteBlockedStreams());
34 EXPECT_EQ(1, list.GetHighestPriorityWriteBlockedList()); 40 EXPECT_EQ(1, list.GetHighestPriorityWriteBlockedList());
35 list.PushBack(1, 0); 41 list.PushBack(1, 0);
36 EXPECT_TRUE(list.HasWriteBlockedStreams()); 42 EXPECT_TRUE(list.HasWriteBlockedStreams());
37 EXPECT_EQ(0, list.GetHighestPriorityWriteBlockedList()); 43 EXPECT_EQ(0, list.GetHighestPriorityWriteBlockedList());
38 } 44 }
39 45
40 TEST(WriteBlockedListTest, HasWriteBlockedStreamsOfGreaterThanPriority) { 46 TEST_P(WriteBlockedListTest, HasWriteBlockedStreamsOfGreaterThanPriority) {
41 IntWriteBlockedList list;
42 list.PushBack(1, 4); 47 list.PushBack(1, 4);
43 EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(5)); 48 EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(5));
44 EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(4)); 49 EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(4));
45 list.PushBack(1, 2); 50 list.PushBack(2, 2);
46 EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(3)); 51 EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(3));
47 EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(2)); 52 EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(2));
48 } 53 }
49 54
50 TEST(WriteBlockedListTest, RemoveStreamFromWriteBlockedList) { 55 TEST_P(WriteBlockedListTest, RemoveStreamFromWriteBlockedList) {
51 IntWriteBlockedList list;
52
53 list.PushBack(1, 4); 56 list.PushBack(1, 4);
54 EXPECT_TRUE(list.HasWriteBlockedStreams()); 57 EXPECT_TRUE(list.HasWriteBlockedStreams());
55 58
56 list.RemoveStreamFromWriteBlockedList(1, 5); 59 list.RemoveStreamFromWriteBlockedList(1, 5);
57 EXPECT_TRUE(list.HasWriteBlockedStreams()); 60 EXPECT_TRUE(list.HasWriteBlockedStreams());
58 61
59 list.PushBack(2, 4); 62 list.PushBack(2, 4);
60 list.PushBack(1, 4); 63 list.PushBack(1, 4);
61 list.RemoveStreamFromWriteBlockedList(1, 4); 64 list.RemoveStreamFromWriteBlockedList(1, 4);
62 list.RemoveStreamFromWriteBlockedList(2, 4); 65 list.RemoveStreamFromWriteBlockedList(2, 4);
63 EXPECT_FALSE(list.HasWriteBlockedStreams()); 66 EXPECT_FALSE(list.HasWriteBlockedStreams());
64 67
65 list.PushBack(1, 7); 68 list.PushBack(1, 7);
66 EXPECT_TRUE(list.HasWriteBlockedStreams()); 69 EXPECT_TRUE(list.HasWriteBlockedStreams());
67 } 70 }
68 71
69 TEST(WriteBlockedListTest, PopFront) { 72 TEST_P(WriteBlockedListTest, PopFront) {
70 IntWriteBlockedList list;
71
72 list.PushBack(1, 4); 73 list.PushBack(1, 4);
73 EXPECT_EQ(1u, list.NumBlockedStreams()); 74 EXPECT_EQ(1u, list.NumBlockedStreams());
74 list.PushBack(2, 4); 75 list.PushBack(2, 4);
75 list.PushBack(1, 4); 76 list.PushBack(1, 4);
76 list.PushBack(3, 4); 77 list.PushBack(3, 4);
77 EXPECT_EQ(4u, list.NumBlockedStreams()); 78 if (GetParam()) {
79 EXPECT_EQ(3u, list.NumBlockedStreams());
80 } else {
81 EXPECT_EQ(4u, list.NumBlockedStreams());
82 }
78 83
79 EXPECT_EQ(1, list.PopFront(4)); 84 EXPECT_EQ(1, list.PopFront(4));
80 EXPECT_EQ(2, list.PopFront(4)); 85 EXPECT_EQ(2, list.PopFront(4));
81 EXPECT_EQ(1, list.PopFront(4)); 86 EXPECT_EQ(1, list.PopFront(4));
87 if (!GetParam()) {
88 EXPECT_EQ(1, list.PopFront(4));
89 }
82 EXPECT_EQ(1u, list.NumBlockedStreams()); 90 EXPECT_EQ(1u, list.NumBlockedStreams());
83 EXPECT_EQ(3, list.PopFront(4)); 91 EXPECT_EQ(3, list.PopFront(4));
84 } 92 }
85 93
86 TEST(WriteBlockedListTest, UpdateStreamPriorityInWriteBlockedList) { 94 TEST_P(WriteBlockedListTest, UpdateStreamPriorityInWriteBlockedList) {
87 IntWriteBlockedList list; 95 if (GetParam()) {
96 list.PushBack(1, 1);
97 list.PushBack(2, 2);
98 list.PushBack(3, 3);
99 list.PushBack(1, 3); // Re-prioritizes stream 1 at priority 3.
100 list.PushBack(1, 3); // No effect.
101 EXPECT_EQ(3u, list.NumBlockedStreams());
102 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
103 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
104 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
88 105
89 list.PushBack(1, 1); 106 list.UpdateStreamPriorityInWriteBlockedList(1, 3, 2);
90 list.PushBack(2, 2); 107 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
91 list.PushBack(3, 3); 108 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
92 list.PushBack(1, 3); 109 list.UpdateStreamPriorityInWriteBlockedList(3, 3, 1);
93 list.PushBack(1, 3); 110 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
94 EXPECT_EQ(5u, list.NumBlockedStreams()); 111 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
95 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
96 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
97 EXPECT_EQ(3u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
98 112
99 list.UpdateStreamPriorityInWriteBlockedList(1, 1, 2); 113 // Redundant update.
100 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size()); 114 list.UpdateStreamPriorityInWriteBlockedList(1, 2, 2);
101 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size()); 115 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
102 list.UpdateStreamPriorityInWriteBlockedList(3, 3, 1);
103 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
104 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
105 116
106 // Redundant update. 117 // No entries for given stream_id / old_priority pair.
107 list.UpdateStreamPriorityInWriteBlockedList(1, 3, 3); 118 list.UpdateStreamPriorityInWriteBlockedList(4, 4, 1);
108 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size()); 119 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
120 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
121 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(4, &list)->size());
109 122
110 // No entries for given stream_id / old_priority pair. 123 EXPECT_EQ(3, list.PopFront(1));
111 list.UpdateStreamPriorityInWriteBlockedList(4, 4, 1); 124 EXPECT_EQ(2, list.PopFront(2));
112 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size()); 125 EXPECT_EQ(1, list.PopFront(2));
113 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size()); 126 EXPECT_EQ(0u, list.NumBlockedStreams());
114 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(4, &list)->size()); 127 } else {
128 list.PushBack(1, 1);
129 list.PushBack(2, 2);
130 list.PushBack(3, 3);
131 list.PushBack(1, 3);
132 list.PushBack(1, 3);
133 EXPECT_EQ(5u, list.NumBlockedStreams());
134 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
135 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
136 EXPECT_EQ(3u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
115 137
116 // Update multiple entries. 138 list.UpdateStreamPriorityInWriteBlockedList(1, 1, 2);
117 list.UpdateStreamPriorityInWriteBlockedList(1, 3, 4); 139 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
118 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size()); 140 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
119 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(4, &list)->size()); 141 list.UpdateStreamPriorityInWriteBlockedList(3, 3, 1);
142 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
143 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
120 144
121 EXPECT_EQ(3, list.PopFront(1)); 145 // Redundant update.
122 EXPECT_EQ(2, list.PopFront(2)); 146 list.UpdateStreamPriorityInWriteBlockedList(1, 3, 3);
123 EXPECT_EQ(1, list.PopFront(2)); 147 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
124 EXPECT_EQ(1, list.PopFront(4)); 148
125 EXPECT_EQ(0u, list.NumBlockedStreams()); 149 // No entries for given stream_id / old_priority pair.
150 list.UpdateStreamPriorityInWriteBlockedList(4, 4, 1);
151 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
152 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
153 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(4, &list)->size());
154
155 // Update multiple entries.
156 list.UpdateStreamPriorityInWriteBlockedList(1, 3, 4);
157 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
158 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(4, &list)->size());
159
160 EXPECT_EQ(3, list.PopFront(1));
161 EXPECT_EQ(2, list.PopFront(2));
162 EXPECT_EQ(1, list.PopFront(2));
163 EXPECT_EQ(1, list.PopFront(4));
164 EXPECT_EQ(0u, list.NumBlockedStreams());
165 }
126 } 166 }
127 167
128 } // namespace 168 } // namespace
129 } // namespace test 169 } // namespace test
130 } // namespace net 170 } // namespace net
OLDNEW
« net/quic/quic_session.cc ('K') | « net/spdy/write_blocked_list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698