github.com/matrixorigin/matrixone@v1.2.0/pkg/logservice/shardinfo_test.go (about) 1 // Copyright 2021 - 2022 Matrix Origin 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package logservice 16 17 import ( 18 "testing" 19 "time" 20 21 "github.com/lni/dragonboat/v4" 22 23 "github.com/stretchr/testify/assert" 24 "github.com/stretchr/testify/require" 25 ) 26 27 func TestGetShardInfo(t *testing.T) { 28 fn := func(t *testing.T, s *Service) { 29 done := false 30 for i := 0; i < 1000; i++ { 31 si, ok, err := GetShardInfo(testServiceAddress, 1) 32 if err != nil || !ok { 33 time.Sleep(10 * time.Millisecond) 34 continue 35 } 36 done = true 37 require.NoError(t, err) 38 assert.True(t, ok) 39 assert.Equal(t, uint64(1), si.ReplicaID) 40 addr, ok := si.Replicas[si.ReplicaID] 41 assert.True(t, ok) 42 assert.Equal(t, testServiceAddress, addr) 43 break 44 } 45 if !done { 46 t.Fatalf("failed to get shard info") 47 } 48 _, ok, err := GetShardInfo(testServiceAddress, 2) 49 require.Equal(t, dragonboat.ErrShardNotFound, err) 50 assert.False(t, ok) 51 } 52 runServiceTest(t, false, true, fn) 53 }