diff --git a/internal/mysql/switch_helper.go b/internal/mysql/switch_helper.go index 943afa98..d6d342ba 100644 --- a/internal/mysql/switch_helper.go +++ b/internal/mysql/switch_helper.go @@ -10,33 +10,23 @@ type ISwitchHelper interface { GetPriorityChoiceMaxLag() time.Duration } -type DefaultSwitchHelper struct { - config *config.Config -} - -type AsyncSwitchHelper struct { - config *config.Config +type SwitchHelper struct { + priorityChoiceMaxLag time.Duration } func NewSwitchHelper(config *config.Config) ISwitchHelper { + priorityChoiceMaxLag := config.PriorityChoiceMaxLag if config.ASync { - return &AsyncSwitchHelper{ - config: config, + AsyncAllowedLagTime := time.Duration(config.AsyncAllowedLag) * time.Second + if AsyncAllowedLagTime > config.PriorityChoiceMaxLag { + priorityChoiceMaxLag = AsyncAllowedLagTime } } - return &DefaultSwitchHelper{ - config: config, + return &SwitchHelper{ + priorityChoiceMaxLag: priorityChoiceMaxLag, } } -func (sh *DefaultSwitchHelper) GetPriorityChoiceMaxLag() time.Duration { - return sh.config.PriorityChoiceMaxLag -} - -func (sh *AsyncSwitchHelper) GetPriorityChoiceMaxLag() time.Duration { - AsyncAllowedLagTime := time.Duration(sh.config.AsyncAllowedLag) * time.Second - if AsyncAllowedLagTime > sh.config.PriorityChoiceMaxLag { - return AsyncAllowedLagTime - } - return sh.config.PriorityChoiceMaxLag +func (sh *SwitchHelper) GetPriorityChoiceMaxLag() time.Duration { + return sh.priorityChoiceMaxLag } diff --git a/tests/features/async_setting.feature b/tests/features/async_setting.feature index 68907e22..a37c8855 100644 --- a/tests/features/async_setting.feature +++ b/tests/features/async_setting.feature @@ -53,7 +53,7 @@ Feature: mysync async mode tests """ INSERT INTO mysql.test_table1 VALUES ("D"), ("E"), ("F") """ - And I wait for "70" seconds + And I wait for "40" seconds When I run SQL on mysql host "mysql2" """ SELECT GROUP_CONCAT(value) as val from (SELECT value from mysql.test_table1 order by value) as t