github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/petri/acyclic/tenant/fail_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 // +build !windows 14 15 package tenant 16 17 import ( 18 "context" 19 "math" 20 "net" 21 "os" 22 "sync" 23 "testing" 24 "time" 25 26 . "github.com/whtcorpsinc/check" 27 "github.com/whtcorpsinc/failpoint" 28 "github.com/whtcorpsinc/BerolinaSQL/terror" 29 "github.com/whtcorpsinc/milevadb/soliton/logutil" 30 "github.com/whtcorpsinc/milevadb/soliton/testleak" 31 "go.etcd.io/etcd/clientv3" 32 "google.golang.org/grpc" 33 ) 34 35 // Ignore this test on the windows platform, because calling unix socket with address in 36 // host:port format fails on windows. 37 func TestT(t *testing.T) { 38 CustomVerboseFlag = true 39 logLevel := os.Getenv("log_level") 40 logutil.InitLogger(logutil.NewLogConfig(logLevel, "", "", logutil.EmptyFileLogConfig, false)) 41 TestingT(t) 42 } 43 44 var _ = Suite(&testSuite{}) 45 46 type testSuite struct { 47 } 48 49 func (s *testSuite) SetUpSuite(c *C) { 50 } 51 52 func (s *testSuite) TearDownSuite(c *C) { 53 } 54 55 var ( 56 endpoints = []string{"unix://new_stochastik:12379"} 57 dialTimeout = 5 * time.Second 58 retryCnt = math.MaxInt32 59 ) 60 61 func (s *testSuite) TestFailNewStochastik(c *C) { 62 ln, err := net.Listen("unix", "new_stochastik:0") 63 c.Assert(err, IsNil) 64 srv := grpc.NewServer(grpc.ConnectionTimeout(time.Minute)) 65 var stop sync.WaitGroup 66 stop.Add(1) 67 go func() { 68 if err = srv.Serve(ln); err != nil { 69 c.Errorf("can't serve gRPC requests %v", err) 70 } 71 stop.Done() 72 }() 73 74 leakFunc := testleak.AfterTest(c) 75 defer func() { 76 srv.Stop() 77 stop.Wait() 78 leakFunc() 79 }() 80 81 func() { 82 cli, err := clientv3.New(clientv3.Config{ 83 Endpoints: endpoints, 84 DialTimeout: dialTimeout, 85 }) 86 c.Assert(err, IsNil) 87 defer func() { 88 if cli != nil { 89 cli.Close() 90 } 91 c.Assert(failpoint.Disable("github.com/whtcorpsinc/milevadb/tenant/closeClient"), IsNil) 92 }() 93 c.Assert(failpoint.Enable("github.com/whtcorpsinc/milevadb/tenant/closeClient", `return(true)`), IsNil) 94 _, err = NewStochastik(context.Background(), "fail_new_serssion", cli, retryCnt, ManagerStochastikTTL) 95 isContextDone := terror.ErrorEqual(grpc.ErrClientConnClosing, err) || terror.ErrorEqual(context.Canceled, err) 96 c.Assert(isContextDone, IsTrue, Commentf("err %v", err)) 97 }() 98 99 func() { 100 cli, err := clientv3.New(clientv3.Config{ 101 Endpoints: endpoints, 102 DialTimeout: dialTimeout, 103 }) 104 c.Assert(err, IsNil) 105 defer func() { 106 if cli != nil { 107 cli.Close() 108 } 109 c.Assert(failpoint.Disable("github.com/whtcorpsinc/milevadb/tenant/closeGrpc"), IsNil) 110 }() 111 c.Assert(failpoint.Enable("github.com/whtcorpsinc/milevadb/tenant/closeGrpc", `return(true)`), IsNil) 112 _, err = NewStochastik(context.Background(), "fail_new_serssion", cli, retryCnt, ManagerStochastikTTL) 113 isContextDone := terror.ErrorEqual(grpc.ErrClientConnClosing, err) || terror.ErrorEqual(context.Canceled, err) 114 c.Assert(isContextDone, IsTrue, Commentf("err %v", err)) 115 }() 116 117 }