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 23 matching lines...) Expand all Loading... |
34 PlatformThread::Sleep(500); // Allow time for DLLs to fully load. | 34 PlatformThread::Sleep(500); // Allow time for DLLs to fully load. |
35 | 35 |
36 // Complete the construction of real test object. | 36 // Complete the construction of real test object. |
37 info.SetHostname(hostname1); | 37 info.SetHostname(hostname1); |
38 | 38 |
39 EXPECT_TRUE(info.NeedsDnsUpdate(hostname1)) << "error in construction state"; | 39 EXPECT_TRUE(info.NeedsDnsUpdate(hostname1)) << "error in construction state"; |
40 info.SetQueuedState(DnsHostInfo::UNIT_TEST_MOTIVATED); | 40 info.SetQueuedState(DnsHostInfo::UNIT_TEST_MOTIVATED); |
41 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) | 41 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) |
42 << "update needed after being queued"; | 42 << "update needed after being queued"; |
43 info.SetAssignedState(); | 43 info.SetAssignedState(); |
44 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) | 44 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)); |
45 << "update needed while assigned to slave"; | |
46 info.SetFoundState(); | 45 info.SetFoundState(); |
47 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) | 46 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) |
48 << "default expiration time is TOOOOO short"; | 47 << "default expiration time is TOOOOO short"; |
49 | 48 |
50 // Note that time from ASSIGNED to FOUND was VERY short (probably 0ms), so the | 49 // Note that time from ASSIGNED to FOUND was VERY short (probably 0ms), so the |
51 // object should conclude that no network activity was needed. As a result, | 50 // object should conclude that no network activity was needed. As a result, |
52 // the required time till expiration will be halved (guessing that we were | 51 // the required time till expiration will be halved (guessing that we were |
53 // half way through having the cache expire when we did the lookup. | 52 // half way through having the cache expire when we did the lookup. |
54 EXPECT_LT(info.resolve_duration().InMilliseconds(), | 53 EXPECT_LT(info.resolve_duration().InMilliseconds(), |
55 DnsHostInfo::kMaxNonNetworkDnsLookupDuration.InMilliseconds()) | 54 DnsHostInfo::kMaxNonNetworkDnsLookupDuration.InMilliseconds()) |
56 << "Non-net time is set too low"; | 55 << "Non-net time is set too low"; |
57 | 56 |
58 info.set_cache_expiration(TimeDelta::FromMilliseconds(300)); | 57 info.set_cache_expiration(TimeDelta::FromMilliseconds(300)); |
59 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; | 58 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; |
60 PlatformThread::Sleep(80); // Not enough time to pass our 300ms mark. | 59 PlatformThread::Sleep(80); // Not enough time to pass our 300ms mark. |
61 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; | 60 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; |
62 | 61 |
63 // That was a nice life when the object was found.... but next time it won't | 62 // That was a nice life when the object was found.... but next time it won't |
64 // be found. We'll sleep for a while, and then come back with not-found. | 63 // be found. We'll sleep for a while, and then come back with not-found. |
65 info.SetQueuedState(DnsHostInfo::UNIT_TEST_MOTIVATED); | 64 info.SetQueuedState(DnsHostInfo::UNIT_TEST_MOTIVATED); |
66 info.SetAssignedState(); | 65 info.SetAssignedState(); |
67 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) | 66 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)); |
68 << "update needed while assigned to slave"; | |
69 // Greater than minimal expected network latency on DNS lookup. | 67 // Greater than minimal expected network latency on DNS lookup. |
70 PlatformThread::Sleep(25); | 68 PlatformThread::Sleep(25); |
71 info.SetNoSuchNameState(); | 69 info.SetNoSuchNameState(); |
72 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) | 70 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) |
73 << "default expiration time is TOOOOO short"; | 71 << "default expiration time is TOOOOO short"; |
74 | 72 |
75 // Note that now we'll actually utilize an expiration of 300ms, | 73 // Note that now we'll actually utilize an expiration of 300ms, |
76 // since there was detected network activity time during lookup. | 74 // since there was detected network activity time during lookup. |
77 // We're assuming the caching just started with our lookup. | 75 // We're assuming the caching just started with our lookup. |
78 PlatformThread::Sleep(80); // Not enough time to pass our 300ms mark. | 76 PlatformThread::Sleep(80); // Not enough time to pass our 300ms mark. |
79 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; | 77 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; |
80 // Still not past our 300ms mark (only about 4+2ms) | 78 // Still not past our 300ms mark (only about 4+2ms) |
81 PlatformThread::Sleep(80); | 79 PlatformThread::Sleep(80); |
82 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; | 80 EXPECT_FALSE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; |
83 PlatformThread::Sleep(150); | 81 PlatformThread::Sleep(150); |
84 EXPECT_TRUE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; | 82 EXPECT_TRUE(info.NeedsDnsUpdate(hostname1)) << "expiration time not honored"; |
85 } | 83 } |
86 | 84 |
87 // 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 |
88 // hostname when already set. | 86 // hostname when already set. |
89 | 87 |
90 } // namespace | 88 } // namespace |
91 | 89 |
OLD | NEW |