github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/pkg/config/messages_test.go (about) 1 // Copyright 2021 PingCAP, 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 14 package config 15 16 import ( 17 "testing" 18 "time" 19 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestDefaultMessageServerConfig(t *testing.T) { 24 // This test case does a sanity check on default config. 25 // In case there is any unsatisfied condition, the MessageServer will not work properly. 26 serverConfig := defaultMessageConfig.ToMessageServerConfig() 27 require.Greater(t, serverConfig.MaxPendingMessageCountPerTopic, 0) 28 require.Greater(t, serverConfig.MaxPendingTaskCount, 0) 29 require.Greater(t, serverConfig.SendChannelSize, 0) 30 require.Greater(t, serverConfig.AckInterval, time.Duration(0)) 31 require.Less(t, serverConfig.AckInterval, 10*time.Second) 32 require.Greater(t, serverConfig.WorkerPoolSize, 0) 33 require.Greater(t, serverConfig.SendRateLimitPerStream, 0.1) 34 require.Greater(t, serverConfig.MaxPeerCount, 0) 35 require.Greater(t, serverConfig.WaitUnregisterHandleTimeoutThreshold, time.Duration(0)) 36 require.EqualValues(t, serverConfig.MaxRecvMsgSize, defaultMaxRecvMsgSize) 37 } 38 39 func TestDefaultMessageClientConfig(t *testing.T) { 40 clientConfig := defaultMessageConfig.ToMessageClientConfig() 41 require.Greater(t, clientConfig.SendChannelSize, 0) 42 require.Greater(t, clientConfig.BatchSendInterval, time.Duration(0)) 43 require.Greater(t, clientConfig.MaxBatchBytes, 0) 44 require.Greater(t, clientConfig.MaxBatchCount, 0) 45 require.Greater(t, clientConfig.RetryRateLimitPerSecond, 0.1) 46 require.Greater(t, clientConfig.DialTimeout, time.Duration(0)) 47 require.EqualValues(t, clientConfig.MaxRecvMsgSize, defaultMaxRecvMsgSize) 48 } 49 50 func TestMessagesConfigClone(t *testing.T) { 51 config := defaultMessageConfig.Clone() 52 require.Equal(t, defaultMessageConfig, config) 53 } 54 55 func TestMessagesConfigValidateAndAdjust(t *testing.T) { 56 emptyConfig := &MessagesConfig{} 57 err := emptyConfig.ValidateAndAdjust() 58 require.NoError(t, err) 59 require.Equal(t, defaultMessageConfig, emptyConfig) 60 61 illegalConfig := defaultMessageConfig.Clone() 62 illegalConfig.ServerAckInterval = TomlDuration(time.Second * 20) 63 err = illegalConfig.ValidateAndAdjust() 64 require.Error(t, err) 65 require.Regexp(t, ".*ErrInvalidServerOption.*", err.Error()) 66 67 illegalConfig = defaultMessageConfig.Clone() 68 illegalConfig.ClientMaxBatchInterval = TomlDuration(time.Second * 20) 69 err = illegalConfig.ValidateAndAdjust() 70 require.Error(t, err) 71 require.Regexp(t, ".*ErrInvalidServerOption.*", err.Error()) 72 73 illegalConfig = defaultMessageConfig.Clone() 74 illegalConfig.ServerWorkerPoolSize = 64 75 err = illegalConfig.ValidateAndAdjust() 76 require.Error(t, err) 77 require.Regexp(t, ".*ErrInvalidServerOption.*", err.Error()) 78 79 illegalConfig = defaultMessageConfig.Clone() 80 illegalConfig.MaxRecvMsgSize = -1 81 err = illegalConfig.ValidateAndAdjust() 82 require.Error(t, err) 83 }