1 # Copyright (C) Internet Systems Consortium, Inc. ("ISC") 2 # 3 # SPDX-License-Identifier: MPL-2.0 4 # 5 # This Source Code Form is subject to the terms of the Mozilla Public 6 # License, v. 2.0. If a copy of the MPL was not distributed with this 7 # file, you can obtain one at https://mozilla.org/MPL/2.0/. 8 # 9 # See the COPYRIGHT file distributed with this work for additional 10 # information regarding copyright ownership. 11 12 import time 13 14 15 import isctest 16 17 18 def test_resolver_cache_reloadfails(ns1, templates): 19 ns1.rndc("flush") 20 msg = isctest.query.create("www.example.org.", "A") 21 res = isctest.query.udp(msg, "10.53.0.1") 22 isctest.check.noerror(res) 23 assert res.answer[0].ttl == 300 24 templates.render( 25 "ns1/named.conf", {"wrongoption": True}, template="ns1/named2.conf.j2" 26 ) 27 28 # The first reload fails, and the old cache list will be preserved 29 cmd = ns1.rndc("reload", raise_on_exception=False) 30 assert cmd.rc != 0 31 32 templates.render("ns1/named.conf", {"wrongoption": False}) 33 # The second reload succeed, and the cache is still there, as preserved 34 # from the old cache list 35 ns1.rndc("reload") 36 time.sleep(3) 37 msg = isctest.query.create("www.example.org.", "A") 38 res = isctest.query.udp(msg, "10.53.0.1") 39 isctest.check.noerror(res) 40 41 # The ttl being lower than 300 (provided by fake authoritative) proves 42 # the cache is still in use 43 assert res.answer[0].ttl < 300 44