@@ -1290,3 +1290,45 @@ func (s) TestMinResolutionInterval(t *testing.T) {
12901290r .ResolveNow (resolver.ResolveNowOptions {})
12911291}
12921292}
1293+
1294+ // TestMinResolutionInterval_NoExtraDelay verifies that there is no extra delay
1295+ // between two resolution requests apart from [MinResolutionInterval]
1296+ // i.e. if a request is made after [MinResolutionInterval], it should resolve
1297+ // immediately. Test sets [MinResolutionInterval] to 1 second and calls
1298+ // ResolveNow() 4 times with a wait of 1 second between each request.
1299+ // A correct implementation should resolve all requests without timing out in
1300+ // test duration of 5 seconds.
1301+ func (s ) TestMinResolutionInterval_NoExtraDelay (t * testing.T ) {
1302+ const target = "foo.bar.com"
1303+
1304+ overrideResolutionInterval (t , 1 * time .Second )
1305+ tr := & testNetResolver {
1306+ hostLookupTable : map [string ][]string {
1307+ "foo.bar.com" : {"1.2.3.4" , "5.6.7.8" },
1308+ },
1309+ txtLookupTable : map [string ][]string {
1310+ "_grpc_config.foo.bar.com" : txtRecordServiceConfig (txtRecordGood ),
1311+ },
1312+ }
1313+ overrideNetResolver (t , tr )
1314+
1315+ r , stateCh , _ := buildResolverWithTestClientConn (t , target )
1316+
1317+ wantAddrs := []resolver.Address {{Addr : "1.2.3.4" + colonDefaultPort }, {Addr : "5.6.7.8" + colonDefaultPort }}
1318+ wantSC := scJSON
1319+
1320+ // set context timeout to test duration of 5 seconds
1321+ // to make sure all 4 resolutions happen successfully
1322+ ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
1323+ defer cancel ()
1324+
1325+ // We chose to make 4 requests to strike a balance between coverage and
1326+ // test duration. This number is sufficiently large to validate the
1327+ // behavior across multiple resolution attempts, while also reducing
1328+ // the likelihood of flakiness due to timing issues.
1329+ for i := 0 ; i < 4 ; i ++ {
1330+ verifyUpdateFromResolver (ctx , t , stateCh , wantAddrs , nil , wantSC )
1331+ time .Sleep (1 * time .Second ) // respect resolution rate of 1 second for re-resolve
1332+ r .ResolveNow (resolver.ResolveNowOptions {})
1333+ }
1334+ }
0 commit comments