google.golang.org/grpc@v1.62.1/xds/internal/balancer/priority/ignore_resolve_now_test.go (about) 1 /* 2 * 3 * Copyright 2021 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 package priority 20 21 import ( 22 "context" 23 "testing" 24 "time" 25 26 "google.golang.org/grpc/internal/testutils" 27 "google.golang.org/grpc/resolver" 28 ) 29 30 func (s) TestIgnoreResolveNowClientConn(t *testing.T) { 31 cc := testutils.NewBalancerClientConn(t) 32 ignoreCC := newIgnoreResolveNowClientConn(cc, false) 33 34 // Call ResolveNow() on the CC, it should be forwarded. 35 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) 36 defer cancel() 37 38 ignoreCC.ResolveNow(resolver.ResolveNowOptions{}) 39 select { 40 case <-cc.ResolveNowCh: 41 case <-ctx.Done(): 42 t.Fatalf("Timeout waiting for ResolveNow()") 43 } 44 45 // Update ignoreResolveNow to true, call ResolveNow() on the CC, they should 46 // all be ignored. 47 ignoreCC.updateIgnoreResolveNow(true) 48 for i := 0; i < 5; i++ { 49 ignoreCC.ResolveNow(resolver.ResolveNowOptions{}) 50 } 51 select { 52 case <-cc.ResolveNowCh: 53 t.Fatalf("got unexpected ResolveNow() call") 54 case <-time.After(defaultTestShortTimeout): 55 } 56 57 // Update ignoreResolveNow to false, new ResolveNow() calls should be 58 // forwarded. 59 ignoreCC.updateIgnoreResolveNow(false) 60 ignoreCC.ResolveNow(resolver.ResolveNowOptions{}) 61 select { 62 case <-cc.ResolveNowCh: 63 case <-ctx.Done(): 64 t.Fatalf("timeout waiting for ResolveNow()") 65 } 66 }