OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // Single threaded tests of DnsHostInfo functionality. | 5 // Single threaded tests of DnsHostInfo functionality. |
6 | 6 |
7 #include <time.h> | 7 #include <time.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/platform_thread.h" | 10 #include "base/platform_thread.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // We're assuming the caching just started with our lookup. | 75 // We're assuming the caching just started with our lookup. |
76 PlatformThread::Sleep(80); // Not enough time to pass our 300ms mark. | 76 PlatformThread::Sleep(80); // Not enough time to pass our 300ms mark. |
77 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; | 77 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; |
78 // Still not past our 300ms mark (only about 4+2ms) | 78 // Still not past our 300ms mark (only about 4+2ms) |
79 PlatformThread::Sleep(80); | 79 PlatformThread::Sleep(80); |
80 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; | 80 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; |
81 PlatformThread::Sleep(150); | 81 PlatformThread::Sleep(150); |
82 EXPECT_TRUE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; | 82 EXPECT_TRUE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; |
83 } | 83 } |
84 | 84 |
85 // When a system gets "congested" relative to DNS, it means it is doing too many | |
86 // DNS resolutions, and bogging down the system. When we detect such a | |
87 // situation, we divert the sequence of states a DnsHostInfo instance moves | |
88 // through. Rather than proceeding from QUEUED (waiting in a name queue for a | |
89 // worker thread that can resolve the name) to ASSIGNED (where a worker thread | |
90 // actively resolves the name), we enter the ASSIGNED state (without actually | |
91 // getting sent to a resolver thread) and reset our state to what it was before | |
92 // the corresponding name was put in the work_queue_. This test drives through | |
93 // the state transitions used in such congestion handling. | |
94 TEST(DnsHostInfoTest, CongestionResetStateTest) { | |
95 DnsHostInfo info; | |
96 std::string hostname1("domain1.com"); | |
97 | |
98 info.SetHostname(hostname1); | |
99 info.SetQueuedState(DnsHostInfo::UNIT_TEST_MOTIVATED); | |
100 info.SetAssignedState(); | |
101 EXPECT_TRUE(info.is_assigned()); | |
102 | |
103 info.RemoveFromQueue(); // Do the reset. | |
104 EXPECT_FALSE(info.is_assigned()); | |
105 | |
106 // Since this was a new info instance, and it never got resolved, we land back | |
107 // in a PENDING state rather than FOUND or NO_SUCH_NAME. | |
108 EXPECT_FALSE(info.was_found()); | |
109 EXPECT_FALSE(info.was_nonexistant()); | |
110 | |
111 // Make sure we're completely re-usable, by going throug a normal flow. | |
112 info.SetQueuedState(DnsHostInfo::UNIT_TEST_MOTIVATED); | |
113 info.SetAssignedState(); | |
114 info.SetFoundState(); | |
115 EXPECT_TRUE(info.was_found()); | |
116 | |
117 // Use the congestion flow, and check that we end up in the found state. | |
118 info.SetQueuedState(DnsHostInfo::UNIT_TEST_MOTIVATED); | |
119 info.SetAssignedState(); | |
120 info.RemoveFromQueue(); // Do the reset. | |
121 EXPECT_FALSE(info.is_assigned()); | |
122 EXPECT_TRUE(info.was_found()); // Back to what it was before being queued. | |
123 } | |
124 | |
125 | |
126 // TODO(jar): Add death test for illegal state changes, and also for setting | 85 // TODO(jar): Add death test for illegal state changes, and also for setting |
127 // hostname when already set. | 86 // hostname when already set. |
128 | 87 |
129 } // namespace | 88 } // namespace |
OLD | NEW |