@@ -26,33 +26,71 @@ def after_all
26
26
override_config_reset ( "--router" )
27
27
end
28
28
29
- def test_failed_host_down_after_ttl_expires
29
+ def test_caches_failed_lookups_before_retrying
30
+ assert_negative_ttl ( NEGATIVE_TTL )
31
+ end
32
+
33
+ def test_negative_ttl_can_be_configured
34
+ negative_ttl = 3
35
+
36
+ # Ensure this negative TTL is different enough than the default that we can
37
+ # distinguish the results in tests.
38
+ assert_operator ( negative_ttl , :<= , ( NEGATIVE_TTL - TTL_BUFFER_POS ) . floor )
39
+
40
+ override_config ( {
41
+ "dns_resolver" => {
42
+ "nameservers" => [ "[127.0.0.1]:#{ $config[ "unbound" ] [ "port" ] } " ] ,
43
+ "max_stale" => 0 ,
44
+ "negative_ttl" => negative_ttl ,
45
+ } ,
46
+ } , "--router" ) do
47
+ assert_negative_ttl ( negative_ttl )
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def assert_negative_ttl ( negative_ttl )
30
54
prepend_api_backends ( [
31
55
{
32
56
:frontend_host => "127.0.0.1" ,
33
- :backend_host => "negative-caching-invalid-hostname-begins-resolving.ooga" ,
34
- :servers => [ { :host => "negative-caching-invalid-hostname-begins-resolving.ooga" , :port => 9444 } ] ,
35
- :url_matches => [ { :frontend_prefix => "/#{ unique_test_id } /negative-caching-invalid-hostname-begins-resolving/ " , :backend_prefix => "/info/" } ] ,
57
+ :backend_host => unique_test_hostname ,
58
+ :servers => [ { :host => unique_test_hostname , :port => 9444 } ] ,
59
+ :url_matches => [ { :frontend_prefix => "/#{ unique_test_id } /" , :backend_prefix => "/info/" } ] ,
36
60
} ,
37
61
] ) do
38
- # The negative TTL caching really begins as soon as the initial
39
- # configuration is put into place by runServer (since that's when the
40
- # hostname is first seen and the unresolvable status is cached). So start
41
- # our timer here.
62
+ # Make an initial request, which we expect to not succeed, since the
63
+ # hostname is bad.
64
+ wait_for_response ( "/#{ unique_test_id } /" , {
65
+ :code => 502 ,
66
+ } )
67
+
68
+ # The negative TTL caching begins after TrafficServer sees the first
69
+ # request and tries to resolve it. So start our timer after the first
70
+ # request.
42
71
start_time = Time . now . utc
43
72
44
- wait_for_response ( "/#{ unique_test_id } /negative-caching-invalid-hostname-begins-resolving/" , {
73
+ # Add the DNS record for the previously invalid domain.
74
+ set_dns_records ( [ "#{ unique_test_hostname } 60 A 127.0.0.1" ] )
75
+
76
+ # Ensure that negative caching is in place and the hostname is still not
77
+ # resolving (despite the DNS being installed now).
78
+ wait_for_response ( "/#{ unique_test_id } /" , {
45
79
:code => 502 ,
46
80
} )
47
81
48
- set_dns_records ( [ "negative-caching-invalid-hostname-begins-resolving.ooga 60 A 127.0.0.1" ] )
49
- wait_for_response ( "/#{ unique_test_id } /negative-caching-invalid-hostname-begins-resolving/" , {
82
+ # Wait for the successful response to resolve once the negative TTL has
83
+ # expired.
84
+ wait_for_response ( "/#{ unique_test_id } /" , {
50
85
:code => 200 ,
51
86
:local_interface_ip => "127.0.0.1" ,
52
87
} )
88
+
89
+ # Sanity check the results to ensure the results fit within the expected
90
+ # negative TTL values.
53
91
duration = Time . now . utc - start_time
54
- min_duration = NEGATIVE_TTL - TTL_BUFFER_NEG
55
- max_duration = NEGATIVE_TTL + TTL_BUFFER_POS
92
+ min_duration = negative_ttl - TTL_BUFFER_NEG
93
+ max_duration = negative_ttl + TTL_BUFFER_POS
56
94
assert_operator ( min_duration , :> , 0 )
57
95
assert_operator ( duration , :>= , min_duration )
58
96
assert_operator ( duration , :< , max_duration )
0 commit comments