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