mirror of https://github.com/0xERR0R/blocky.git
refactor(config): rename `StartStrategyType` to `InitStrategy`
This commit is contained in:
parent
7a3c054b43
commit
a6654dcd57
|
@ -17,14 +17,14 @@ type Blocking struct {
|
||||||
|
|
||||||
// Deprecated options
|
// Deprecated options
|
||||||
Deprecated struct {
|
Deprecated struct {
|
||||||
DownloadTimeout *Duration `yaml:"downloadTimeout"`
|
DownloadTimeout *Duration `yaml:"downloadTimeout"`
|
||||||
DownloadAttempts *uint `yaml:"downloadAttempts"`
|
DownloadAttempts *uint `yaml:"downloadAttempts"`
|
||||||
DownloadCooldown *Duration `yaml:"downloadCooldown"`
|
DownloadCooldown *Duration `yaml:"downloadCooldown"`
|
||||||
RefreshPeriod *Duration `yaml:"refreshPeriod"`
|
RefreshPeriod *Duration `yaml:"refreshPeriod"`
|
||||||
FailStartOnListError *bool `yaml:"failStartOnListError"`
|
FailStartOnListError *bool `yaml:"failStartOnListError"`
|
||||||
ProcessingConcurrency *uint `yaml:"processingConcurrency"`
|
ProcessingConcurrency *uint `yaml:"processingConcurrency"`
|
||||||
StartStrategy *StartStrategyType `yaml:"startStrategy"`
|
StartStrategy *InitStrategy `yaml:"startStrategy"`
|
||||||
MaxErrorsPerFile *int `yaml:"maxErrorsPerFile"`
|
MaxErrorsPerFile *int `yaml:"maxErrorsPerFile"`
|
||||||
} `yaml:",inline"`
|
} `yaml:",inline"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ func (c *Blocking) migrate(logger *logrus.Entry) bool {
|
||||||
"refreshPeriod": Move(To("loading.refreshPeriod", &c.Loading)),
|
"refreshPeriod": Move(To("loading.refreshPeriod", &c.Loading)),
|
||||||
"failStartOnListError": Apply(To("loading.strategy", &c.Loading.Init), func(oldValue bool) {
|
"failStartOnListError": Apply(To("loading.strategy", &c.Loading.Init), func(oldValue bool) {
|
||||||
if oldValue {
|
if oldValue {
|
||||||
c.Loading.Strategy = StartStrategyTypeFailOnError
|
c.Loading.Strategy = InitStrategyFailOnError
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
"processingConcurrency": Move(To("loading.concurrency", &c.Loading)),
|
"processingConcurrency": Move(To("loading.concurrency", &c.Loading)),
|
||||||
|
|
|
@ -109,19 +109,19 @@ func (v *TLSVersion) validate(logger *logrus.Entry) {
|
||||||
// )
|
// )
|
||||||
type QueryLogType int16
|
type QueryLogType int16
|
||||||
|
|
||||||
// StartStrategyType upstart strategy ENUM(
|
// InitStrategy startup strategy ENUM(
|
||||||
// blocking // synchronously download blocking lists on startup
|
// blocking // synchronously download blocking lists on startup
|
||||||
// failOnError // synchronously download blocking lists on startup and shutdown on error
|
// failOnError // synchronously download blocking lists on startup and shutdown on error
|
||||||
// fast // asyncronously download blocking lists on startup
|
// fast // asyncronously download blocking lists on startup
|
||||||
// )
|
// )
|
||||||
type StartStrategyType uint16
|
type InitStrategy uint16
|
||||||
|
|
||||||
func (s StartStrategyType) Do(ctx context.Context, init func(context.Context) error, logErr func(error)) error {
|
func (s InitStrategy) Do(ctx context.Context, init func(context.Context) error, logErr func(error)) error {
|
||||||
init = recoverToError(init, func(panicVal any) error {
|
init = recoverToError(init, func(panicVal any) error {
|
||||||
return fmt.Errorf("panic during initialization: %v", panicVal)
|
return fmt.Errorf("panic during initialization: %v", panicVal)
|
||||||
})
|
})
|
||||||
|
|
||||||
if s == StartStrategyTypeFast {
|
if s == InitStrategyFast {
|
||||||
go func() {
|
go func() {
|
||||||
err := init(ctx)
|
err := init(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -136,7 +136,7 @@ func (s StartStrategyType) Do(ctx context.Context, init func(context.Context) er
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logErr(err)
|
logErr(err)
|
||||||
|
|
||||||
if s == StartStrategyTypeFailOnError {
|
if s == InitStrategyFailOnError {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ func (c *toEnable) LogConfig(logger *logrus.Entry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Init struct {
|
type Init struct {
|
||||||
Strategy StartStrategyType `yaml:"strategy" default:"blocking"`
|
Strategy InitStrategy `yaml:"strategy" default:"blocking"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Init) LogConfig(logger *logrus.Entry) {
|
func (c *Init) LogConfig(logger *logrus.Entry) {
|
||||||
|
@ -563,9 +563,9 @@ func (cfg *Config) migrate(logger *logrus.Entry) bool {
|
||||||
"dohUserAgent": Move(To("upstreams.userAgent", &cfg.Upstreams)),
|
"dohUserAgent": Move(To("upstreams.userAgent", &cfg.Upstreams)),
|
||||||
"startVerifyUpstream": Apply(To("upstreams.init.strategy", &cfg.Upstreams.Init), func(value bool) {
|
"startVerifyUpstream": Apply(To("upstreams.init.strategy", &cfg.Upstreams.Init), func(value bool) {
|
||||||
if value {
|
if value {
|
||||||
cfg.Upstreams.Init.Strategy = StartStrategyTypeFailOnError
|
cfg.Upstreams.Init.Strategy = InitStrategyFailOnError
|
||||||
} else {
|
} else {
|
||||||
cfg.Upstreams.Init.Strategy = StartStrategyTypeFast
|
cfg.Upstreams.Init.Strategy = InitStrategyFast
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
|
@ -100,6 +100,95 @@ func (x *IPVersion) UnmarshalText(text []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
// InitStrategyBlocking is a InitStrategy of type Blocking.
|
||||||
|
// synchronously download blocking lists on startup
|
||||||
|
InitStrategyBlocking InitStrategy = iota
|
||||||
|
// InitStrategyFailOnError is a InitStrategy of type FailOnError.
|
||||||
|
// synchronously download blocking lists on startup and shutdown on error
|
||||||
|
InitStrategyFailOnError
|
||||||
|
// InitStrategyFast is a InitStrategy of type Fast.
|
||||||
|
// asyncronously download blocking lists on startup
|
||||||
|
InitStrategyFast
|
||||||
|
)
|
||||||
|
|
||||||
|
var ErrInvalidInitStrategy = fmt.Errorf("not a valid InitStrategy, try [%s]", strings.Join(_InitStrategyNames, ", "))
|
||||||
|
|
||||||
|
const _InitStrategyName = "blockingfailOnErrorfast"
|
||||||
|
|
||||||
|
var _InitStrategyNames = []string{
|
||||||
|
_InitStrategyName[0:8],
|
||||||
|
_InitStrategyName[8:19],
|
||||||
|
_InitStrategyName[19:23],
|
||||||
|
}
|
||||||
|
|
||||||
|
// InitStrategyNames returns a list of possible string values of InitStrategy.
|
||||||
|
func InitStrategyNames() []string {
|
||||||
|
tmp := make([]string, len(_InitStrategyNames))
|
||||||
|
copy(tmp, _InitStrategyNames)
|
||||||
|
return tmp
|
||||||
|
}
|
||||||
|
|
||||||
|
// InitStrategyValues returns a list of the values for InitStrategy
|
||||||
|
func InitStrategyValues() []InitStrategy {
|
||||||
|
return []InitStrategy{
|
||||||
|
InitStrategyBlocking,
|
||||||
|
InitStrategyFailOnError,
|
||||||
|
InitStrategyFast,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _InitStrategyMap = map[InitStrategy]string{
|
||||||
|
InitStrategyBlocking: _InitStrategyName[0:8],
|
||||||
|
InitStrategyFailOnError: _InitStrategyName[8:19],
|
||||||
|
InitStrategyFast: _InitStrategyName[19:23],
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the Stringer interface.
|
||||||
|
func (x InitStrategy) String() string {
|
||||||
|
if str, ok := _InitStrategyMap[x]; ok {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("InitStrategy(%d)", x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValid provides a quick way to determine if the typed value is
|
||||||
|
// part of the allowed enumerated values
|
||||||
|
func (x InitStrategy) IsValid() bool {
|
||||||
|
_, ok := _InitStrategyMap[x]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
var _InitStrategyValue = map[string]InitStrategy{
|
||||||
|
_InitStrategyName[0:8]: InitStrategyBlocking,
|
||||||
|
_InitStrategyName[8:19]: InitStrategyFailOnError,
|
||||||
|
_InitStrategyName[19:23]: InitStrategyFast,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseInitStrategy attempts to convert a string to a InitStrategy.
|
||||||
|
func ParseInitStrategy(name string) (InitStrategy, error) {
|
||||||
|
if x, ok := _InitStrategyValue[name]; ok {
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
return InitStrategy(0), fmt.Errorf("%s is %w", name, ErrInvalidInitStrategy)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalText implements the text marshaller method.
|
||||||
|
func (x InitStrategy) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(x.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalText implements the text unmarshaller method.
|
||||||
|
func (x *InitStrategy) UnmarshalText(text []byte) error {
|
||||||
|
name := string(text)
|
||||||
|
tmp, err := ParseInitStrategy(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*x = tmp
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// NetProtocolTcpUdp is a NetProtocol of type Tcp+Udp.
|
// NetProtocolTcpUdp is a NetProtocol of type Tcp+Udp.
|
||||||
// TCP and UDP protocols
|
// TCP and UDP protocols
|
||||||
|
@ -388,95 +477,6 @@ func (x *QueryLogType) UnmarshalText(text []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
// StartStrategyTypeBlocking is a StartStrategyType of type Blocking.
|
|
||||||
// synchronously download blocking lists on startup
|
|
||||||
StartStrategyTypeBlocking StartStrategyType = iota
|
|
||||||
// StartStrategyTypeFailOnError is a StartStrategyType of type FailOnError.
|
|
||||||
// synchronously download blocking lists on startup and shutdown on error
|
|
||||||
StartStrategyTypeFailOnError
|
|
||||||
// StartStrategyTypeFast is a StartStrategyType of type Fast.
|
|
||||||
// asyncronously download blocking lists on startup
|
|
||||||
StartStrategyTypeFast
|
|
||||||
)
|
|
||||||
|
|
||||||
var ErrInvalidStartStrategyType = fmt.Errorf("not a valid StartStrategyType, try [%s]", strings.Join(_StartStrategyTypeNames, ", "))
|
|
||||||
|
|
||||||
const _StartStrategyTypeName = "blockingfailOnErrorfast"
|
|
||||||
|
|
||||||
var _StartStrategyTypeNames = []string{
|
|
||||||
_StartStrategyTypeName[0:8],
|
|
||||||
_StartStrategyTypeName[8:19],
|
|
||||||
_StartStrategyTypeName[19:23],
|
|
||||||
}
|
|
||||||
|
|
||||||
// StartStrategyTypeNames returns a list of possible string values of StartStrategyType.
|
|
||||||
func StartStrategyTypeNames() []string {
|
|
||||||
tmp := make([]string, len(_StartStrategyTypeNames))
|
|
||||||
copy(tmp, _StartStrategyTypeNames)
|
|
||||||
return tmp
|
|
||||||
}
|
|
||||||
|
|
||||||
// StartStrategyTypeValues returns a list of the values for StartStrategyType
|
|
||||||
func StartStrategyTypeValues() []StartStrategyType {
|
|
||||||
return []StartStrategyType{
|
|
||||||
StartStrategyTypeBlocking,
|
|
||||||
StartStrategyTypeFailOnError,
|
|
||||||
StartStrategyTypeFast,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var _StartStrategyTypeMap = map[StartStrategyType]string{
|
|
||||||
StartStrategyTypeBlocking: _StartStrategyTypeName[0:8],
|
|
||||||
StartStrategyTypeFailOnError: _StartStrategyTypeName[8:19],
|
|
||||||
StartStrategyTypeFast: _StartStrategyTypeName[19:23],
|
|
||||||
}
|
|
||||||
|
|
||||||
// String implements the Stringer interface.
|
|
||||||
func (x StartStrategyType) String() string {
|
|
||||||
if str, ok := _StartStrategyTypeMap[x]; ok {
|
|
||||||
return str
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("StartStrategyType(%d)", x)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsValid provides a quick way to determine if the typed value is
|
|
||||||
// part of the allowed enumerated values
|
|
||||||
func (x StartStrategyType) IsValid() bool {
|
|
||||||
_, ok := _StartStrategyTypeMap[x]
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
var _StartStrategyTypeValue = map[string]StartStrategyType{
|
|
||||||
_StartStrategyTypeName[0:8]: StartStrategyTypeBlocking,
|
|
||||||
_StartStrategyTypeName[8:19]: StartStrategyTypeFailOnError,
|
|
||||||
_StartStrategyTypeName[19:23]: StartStrategyTypeFast,
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseStartStrategyType attempts to convert a string to a StartStrategyType.
|
|
||||||
func ParseStartStrategyType(name string) (StartStrategyType, error) {
|
|
||||||
if x, ok := _StartStrategyTypeValue[name]; ok {
|
|
||||||
return x, nil
|
|
||||||
}
|
|
||||||
return StartStrategyType(0), fmt.Errorf("%s is %w", name, ErrInvalidStartStrategyType)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalText implements the text marshaller method.
|
|
||||||
func (x StartStrategyType) MarshalText() ([]byte, error) {
|
|
||||||
return []byte(x.String()), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalText implements the text unmarshaller method.
|
|
||||||
func (x *StartStrategyType) UnmarshalText(text []byte) error {
|
|
||||||
name := string(text)
|
|
||||||
tmp, err := ParseStartStrategyType(name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*x = tmp
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// TLSVersion10 is a TLSVersion of type 1.0.
|
// TLSVersion10 is a TLSVersion of type 1.0.
|
||||||
TLSVersion10 TLSVersion = iota + 769
|
TLSVersion10 TLSVersion = iota + 769
|
||||||
|
|
|
@ -54,16 +54,16 @@ var _ = Describe("Config", func() {
|
||||||
c.Blocking.Deprecated.FailStartOnListError = ptrOf(true)
|
c.Blocking.Deprecated.FailStartOnListError = ptrOf(true)
|
||||||
})
|
})
|
||||||
It("should change loading.strategy blocking to failOnError", func() {
|
It("should change loading.strategy blocking to failOnError", func() {
|
||||||
c.Blocking.Loading.Strategy = StartStrategyTypeBlocking
|
c.Blocking.Loading.Strategy = InitStrategyBlocking
|
||||||
c.migrate(logger)
|
c.migrate(logger)
|
||||||
Expect(hook.Messages).Should(ContainElement(ContainSubstring("blocking.loading.strategy")))
|
Expect(hook.Messages).Should(ContainElement(ContainSubstring("blocking.loading.strategy")))
|
||||||
Expect(c.Blocking.Loading.Strategy).Should(Equal(StartStrategyTypeFailOnError))
|
Expect(c.Blocking.Loading.Strategy).Should(Equal(InitStrategyFailOnError))
|
||||||
})
|
})
|
||||||
It("shouldn't change loading.strategy if set to fast", func() {
|
It("shouldn't change loading.strategy if set to fast", func() {
|
||||||
c.Blocking.Loading.Strategy = StartStrategyTypeFast
|
c.Blocking.Loading.Strategy = InitStrategyFast
|
||||||
c.migrate(logger)
|
c.migrate(logger)
|
||||||
Expect(hook.Messages).Should(ContainElement(ContainSubstring("blocking.loading.strategy")))
|
Expect(hook.Messages).Should(ContainElement(ContainSubstring("blocking.loading.strategy")))
|
||||||
Expect(c.Blocking.Loading.Strategy).Should(Equal(StartStrategyTypeFast))
|
Expect(c.Blocking.Loading.Strategy).Should(Equal(InitStrategyFast))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ var _ = Describe("Config", func() {
|
||||||
c.Deprecated.StartVerifyUpstream = ptrOf(true)
|
c.Deprecated.StartVerifyUpstream = ptrOf(true)
|
||||||
c.migrate(logger)
|
c.migrate(logger)
|
||||||
Expect(hook.Messages).Should(ContainElement(ContainSubstring("startVerifyUpstream")))
|
Expect(hook.Messages).Should(ContainElement(ContainSubstring("startVerifyUpstream")))
|
||||||
Expect(c.Upstreams.Init.Strategy).Should(Equal(StartStrategyTypeFailOnError))
|
Expect(c.Upstreams.Init.Strategy).Should(Equal(InitStrategyFailOnError))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -590,10 +590,10 @@ bootstrapDns:
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("StartStrategyType", func() {
|
Describe("InitStrategy", func() {
|
||||||
Describe("StartStrategyTypeBlocking", func() {
|
Describe("InitStrategyBlocking", func() {
|
||||||
It("runs in the current goroutine", func() {
|
It("runs in the current goroutine", func() {
|
||||||
sut := StartStrategyTypeBlocking
|
sut := InitStrategyBlocking
|
||||||
panicVal := new(int)
|
panicVal := new(int)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -611,7 +611,7 @@ bootstrapDns:
|
||||||
})
|
})
|
||||||
|
|
||||||
It("logs errors and doesn't return them", func() {
|
It("logs errors and doesn't return them", func() {
|
||||||
sut := StartStrategyTypeBlocking
|
sut := InitStrategyBlocking
|
||||||
expectedErr := errors.New("test")
|
expectedErr := errors.New("test")
|
||||||
|
|
||||||
err := sut.Do(context.Background(), func(context.Context) error {
|
err := sut.Do(context.Background(), func(context.Context) error {
|
||||||
|
@ -624,7 +624,7 @@ bootstrapDns:
|
||||||
})
|
})
|
||||||
|
|
||||||
It("logs panics and doesn't convert them to errors", func() {
|
It("logs panics and doesn't convert them to errors", func() {
|
||||||
sut := StartStrategyTypeBlocking
|
sut := InitStrategyBlocking
|
||||||
|
|
||||||
logged := false
|
logged := false
|
||||||
err := sut.Do(context.Background(), func(context.Context) error {
|
err := sut.Do(context.Background(), func(context.Context) error {
|
||||||
|
@ -639,9 +639,9 @@ bootstrapDns:
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("StartStrategyTypeFailOnError", func() {
|
Describe("InitStrategyFailOnError", func() {
|
||||||
It("runs in the current goroutine", func() {
|
It("runs in the current goroutine", func() {
|
||||||
sut := StartStrategyTypeFailOnError
|
sut := InitStrategyFailOnError
|
||||||
panicVal := new(int)
|
panicVal := new(int)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -659,7 +659,7 @@ bootstrapDns:
|
||||||
})
|
})
|
||||||
|
|
||||||
It("logs errors and returns them", func() {
|
It("logs errors and returns them", func() {
|
||||||
sut := StartStrategyTypeFailOnError
|
sut := InitStrategyFailOnError
|
||||||
expectedErr := errors.New("test")
|
expectedErr := errors.New("test")
|
||||||
|
|
||||||
err := sut.Do(context.Background(), func(context.Context) error {
|
err := sut.Do(context.Background(), func(context.Context) error {
|
||||||
|
@ -672,7 +672,7 @@ bootstrapDns:
|
||||||
})
|
})
|
||||||
|
|
||||||
It("returns logs panics and converts them to errors", func() {
|
It("returns logs panics and converts them to errors", func() {
|
||||||
sut := StartStrategyTypeFailOnError
|
sut := InitStrategyFailOnError
|
||||||
|
|
||||||
logged := false
|
logged := false
|
||||||
err := sut.Do(context.Background(), func(context.Context) error {
|
err := sut.Do(context.Background(), func(context.Context) error {
|
||||||
|
@ -687,9 +687,9 @@ bootstrapDns:
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("StartStrategyTypeFast", func() {
|
Describe("InitStrategyFast", func() {
|
||||||
It("runs in a new goroutine", func() {
|
It("runs in a new goroutine", func() {
|
||||||
sut := StartStrategyTypeFast
|
sut := InitStrategyFast
|
||||||
events := make(chan string)
|
events := make(chan string)
|
||||||
wait := make(chan struct{})
|
wait := make(chan struct{})
|
||||||
|
|
||||||
|
@ -709,7 +709,7 @@ bootstrapDns:
|
||||||
})
|
})
|
||||||
|
|
||||||
It("logs errors", func() {
|
It("logs errors", func() {
|
||||||
sut := StartStrategyTypeFast
|
sut := InitStrategyFast
|
||||||
expectedErr := errors.New("test")
|
expectedErr := errors.New("test")
|
||||||
wait := make(chan struct{})
|
wait := make(chan struct{})
|
||||||
|
|
||||||
|
@ -725,7 +725,7 @@ bootstrapDns:
|
||||||
})
|
})
|
||||||
|
|
||||||
It("logs panics", func() {
|
It("logs panics", func() {
|
||||||
sut := StartStrategyTypeFast
|
sut := InitStrategyFast
|
||||||
expectedErr := errors.New("test")
|
expectedErr := errors.New("test")
|
||||||
wait := make(chan struct{})
|
wait := make(chan struct{})
|
||||||
|
|
||||||
|
@ -778,7 +778,7 @@ bootstrapDns:
|
||||||
})
|
})
|
||||||
It("handles panics", func() {
|
It("handles panics", func() {
|
||||||
sut := SourceLoadingConfig{
|
sut := SourceLoadingConfig{
|
||||||
Init: Init{Strategy: StartStrategyTypeFailOnError},
|
Init: Init{Strategy: InitStrategyFailOnError},
|
||||||
}
|
}
|
||||||
|
|
||||||
panicMsg := "panic value"
|
panicMsg := "panic value"
|
||||||
|
@ -794,7 +794,7 @@ bootstrapDns:
|
||||||
|
|
||||||
It("periodically calls refresh", func() {
|
It("periodically calls refresh", func() {
|
||||||
sut := SourceLoadingConfig{
|
sut := SourceLoadingConfig{
|
||||||
Init: Init{Strategy: StartStrategyTypeFast},
|
Init: Init{Strategy: InitStrategyFast},
|
||||||
RefreshPeriod: Duration(5 * time.Millisecond),
|
RefreshPeriod: Duration(5 * time.Millisecond),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -850,7 +850,7 @@ bootstrapDns:
|
||||||
|
|
||||||
func defaultTestFileConfig(config *Config) {
|
func defaultTestFileConfig(config *Config) {
|
||||||
Expect(config.Ports.DNS).Should(Equal(ListenConfig{"55553", ":55554", "[::1]:55555"}))
|
Expect(config.Ports.DNS).Should(Equal(ListenConfig{"55553", ":55554", "[::1]:55555"}))
|
||||||
Expect(config.Upstreams.Init.Strategy).Should(Equal(StartStrategyTypeFailOnError))
|
Expect(config.Upstreams.Init.Strategy).Should(Equal(InitStrategyFailOnError))
|
||||||
Expect(config.Upstreams.UserAgent).Should(Equal("testBlocky"))
|
Expect(config.Upstreams.UserAgent).Should(Equal("testBlocky"))
|
||||||
Expect(config.Upstreams.Groups["default"]).Should(HaveLen(3))
|
Expect(config.Upstreams.Groups["default"]).Should(HaveLen(3))
|
||||||
Expect(config.Upstreams.Groups["default"][0].Host).Should(Equal("8.8.8.8"))
|
Expect(config.Upstreams.Groups["default"][0].Host).Should(Equal("8.8.8.8"))
|
||||||
|
|
|
@ -352,7 +352,7 @@ var _ = Describe("ListCache", func() {
|
||||||
When("Text file has too many errors", func() {
|
When("Text file has too many errors", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
sutConfig.MaxErrorsPerSource = 0
|
sutConfig.MaxErrorsPerSource = 0
|
||||||
sutConfig.Strategy = config.StartStrategyTypeFailOnError
|
sutConfig.Strategy = config.InitStrategyFailOnError
|
||||||
lists = map[string][]config.BytesSource{
|
lists = map[string][]config.BytesSource{
|
||||||
"gr1": {
|
"gr1": {
|
||||||
config.TextBytesSource("invaliddomain!"), // too many errors since `maxErrorsPerSource` is 0
|
config.TextBytesSource("invaliddomain!"), // too many errors since `maxErrorsPerSource` is 0
|
||||||
|
@ -421,10 +421,10 @@ var _ = Describe("ListCache", func() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("StartStrategy", func() {
|
Describe("loading strategy", func() {
|
||||||
When("async load is enabled", func() {
|
When("async load is enabled", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
sutConfig.Strategy = config.StartStrategyTypeFast
|
sutConfig.Strategy = config.InitStrategyFast
|
||||||
|
|
||||||
lists = map[string][]config.BytesSource{
|
lists = map[string][]config.BytesSource{
|
||||||
"gr1": config.NewBytesSources("doesnotexist"),
|
"gr1": config.NewBytesSources("doesnotexist"),
|
||||||
|
|
|
@ -159,7 +159,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Blocking with fast start strategy", func() {
|
Describe("Blocking with fast init strategy", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
sutConfig = config.Blocking{
|
sutConfig = config.Blocking{
|
||||||
BlockType: "ZEROIP",
|
BlockType: "ZEROIP",
|
||||||
|
@ -171,7 +171,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {
|
||||||
"default": {"gr1"},
|
"default": {"gr1"},
|
||||||
},
|
},
|
||||||
Loading: config.SourceLoadingConfig{
|
Loading: config.SourceLoadingConfig{
|
||||||
Init: config.Init{Strategy: config.StartStrategyTypeFast},
|
Init: config.Init{Strategy: config.InitStrategyFast},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1127,7 +1127,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {
|
||||||
BlackLists: map[string][]config.BytesSource{"gr1": config.NewBytesSources("wrongPath")},
|
BlackLists: map[string][]config.BytesSource{"gr1": config.NewBytesSources("wrongPath")},
|
||||||
WhiteLists: map[string][]config.BytesSource{"whitelist": config.NewBytesSources("wrongPath")},
|
WhiteLists: map[string][]config.BytesSource{"whitelist": config.NewBytesSources("wrongPath")},
|
||||||
Loading: config.SourceLoadingConfig{
|
Loading: config.SourceLoadingConfig{
|
||||||
Init: config.Init{Strategy: config.StartStrategyTypeFailOnError},
|
Init: config.Init{Strategy: config.InitStrategyFailOnError},
|
||||||
},
|
},
|
||||||
BlockType: "zeroIp",
|
BlockType: "zeroIp",
|
||||||
}, nil, systemResolverBootstrap)
|
}, nil, systemResolverBootstrap)
|
||||||
|
|
|
@ -397,7 +397,7 @@ var _ = Describe("ClientResolver", Label("clientNamesResolver"), func() {
|
||||||
b := newTestBootstrap(ctx, &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: dns.RcodeServerFailure}})
|
b := newTestBootstrap(ctx, &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: dns.RcodeServerFailure}})
|
||||||
|
|
||||||
upstreamsCfg := defaultUpstreamsConfig
|
upstreamsCfg := defaultUpstreamsConfig
|
||||||
upstreamsCfg.Init.Strategy = config.StartStrategyTypeFailOnError
|
upstreamsCfg.Init.Strategy = config.InitStrategyFailOnError
|
||||||
|
|
||||||
r, err := NewClientNamesResolver(ctx, config.ClientLookup{
|
r, err := NewClientNamesResolver(ctx, config.ClientLookup{
|
||||||
Upstream: config.Upstream{Host: "example.com"},
|
Upstream: config.Upstream{Host: "example.com"},
|
||||||
|
|
|
@ -197,7 +197,7 @@ var _ = Describe("ConditionalUpstreamResolver", Label("conditionalResolver"), fu
|
||||||
b := newTestBootstrap(ctx, &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: dns.RcodeServerFailure}})
|
b := newTestBootstrap(ctx, &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: dns.RcodeServerFailure}})
|
||||||
|
|
||||||
upstreamsCfg := defaultUpstreamsConfig
|
upstreamsCfg := defaultUpstreamsConfig
|
||||||
upstreamsCfg.Init.Strategy = config.StartStrategyTypeFailOnError
|
upstreamsCfg.Init.Strategy = config.InitStrategyFailOnError
|
||||||
|
|
||||||
sutConfig := config.ConditionalUpstream{
|
sutConfig := config.ConditionalUpstream{
|
||||||
Mapping: config.ConditionalUpstreamMapping{
|
Mapping: config.ConditionalUpstreamMapping{
|
||||||
|
|
|
@ -97,7 +97,7 @@ func NewParallelBestResolver(
|
||||||
) (*ParallelBestResolver, error) {
|
) (*ParallelBestResolver, error) {
|
||||||
r := newParallelBestResolver(
|
r := newParallelBestResolver(
|
||||||
cfg,
|
cfg,
|
||||||
[]Resolver{bootstrap}, // if start strategy is fast, use bootstrap until init finishes
|
[]Resolver{bootstrap}, // if init strategy is fast, use bootstrap until init finishes
|
||||||
)
|
)
|
||||||
|
|
||||||
return initGroupResolvers(ctx, r, cfg, bootstrap)
|
return initGroupResolvers(ctx, r, cfg, bootstrap)
|
||||||
|
|
|
@ -15,10 +15,10 @@ import (
|
||||||
|
|
||||||
var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
|
var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
|
||||||
var (
|
var (
|
||||||
sut *ParallelBestResolver
|
sut *ParallelBestResolver
|
||||||
sutStrategy config.UpstreamStrategy
|
sutStrategy config.UpstreamStrategy
|
||||||
sutStartStrategy config.StartStrategyType
|
sutInitStrategy config.InitStrategy
|
||||||
upstreams []config.Upstream
|
upstreams []config.Upstream
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancelFn context.CancelFunc
|
cancelFn context.CancelFunc
|
||||||
|
@ -40,7 +40,7 @@ var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
|
||||||
|
|
||||||
upstreams = []config.Upstream{{Host: "wrong"}, {Host: "127.0.0.2"}}
|
upstreams = []config.Upstream{{Host: "wrong"}, {Host: "127.0.0.2"}}
|
||||||
|
|
||||||
sutStartStrategy = config.StartStrategyTypeBlocking
|
sutInitStrategy = config.InitStrategyBlocking
|
||||||
sutStrategy = config.UpstreamStrategyParallelBest
|
sutStrategy = config.UpstreamStrategyParallelBest
|
||||||
|
|
||||||
bootstrap = systemResolverBootstrap
|
bootstrap = systemResolverBootstrap
|
||||||
|
@ -49,7 +49,7 @@ var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
|
||||||
JustBeforeEach(func() {
|
JustBeforeEach(func() {
|
||||||
upstreamsCfg := config.Upstreams{
|
upstreamsCfg := config.Upstreams{
|
||||||
Init: config.Init{
|
Init: config.Init{
|
||||||
Strategy: sutStartStrategy,
|
Strategy: sutInitStrategy,
|
||||||
},
|
},
|
||||||
Strategy: sutStrategy,
|
Strategy: sutStrategy,
|
||||||
Timeout: config.Duration(timeout),
|
Timeout: config.Duration(timeout),
|
||||||
|
@ -90,7 +90,7 @@ var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
|
||||||
|
|
||||||
When("using InitStrategyFailOnError", func() {
|
When("using InitStrategyFailOnError", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
sutStartStrategy = config.StartStrategyTypeFailOnError
|
sutInitStrategy = config.InitStrategyFailOnError
|
||||||
})
|
})
|
||||||
It("should fail to start", func() {
|
It("should fail to start", func() {
|
||||||
Expect(err).Should(HaveOccurred())
|
Expect(err).Should(HaveOccurred())
|
||||||
|
@ -99,7 +99,7 @@ var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
|
||||||
|
|
||||||
When("using InitStrategyBlocking", func() {
|
When("using InitStrategyBlocking", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
sutStartStrategy = config.StartStrategyTypeBlocking
|
sutInitStrategy = config.InitStrategyBlocking
|
||||||
})
|
})
|
||||||
It("should start", func() {
|
It("should start", func() {
|
||||||
Expect(err).Should(Succeed())
|
Expect(err).Should(Succeed())
|
||||||
|
@ -125,7 +125,7 @@ var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
|
||||||
|
|
||||||
When("using InitStrategyFailOnError", func() {
|
When("using InitStrategyFailOnError", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
sutStartStrategy = config.StartStrategyTypeFailOnError
|
sutInitStrategy = config.InitStrategyFailOnError
|
||||||
})
|
})
|
||||||
It("should fail to start", func() {
|
It("should fail to start", func() {
|
||||||
Expect(err).Should(HaveOccurred())
|
Expect(err).Should(HaveOccurred())
|
||||||
|
@ -134,7 +134,7 @@ var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
|
||||||
|
|
||||||
When("using InitStrategyBlocking", func() {
|
When("using InitStrategyBlocking", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
sutStartStrategy = config.StartStrategyTypeBlocking
|
sutInitStrategy = config.InitStrategyBlocking
|
||||||
})
|
})
|
||||||
It("should start", func() {
|
It("should start", func() {
|
||||||
Expect(err).Should(Succeed())
|
Expect(err).Should(Succeed())
|
||||||
|
@ -162,7 +162,7 @@ var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
|
||||||
|
|
||||||
When("using InitStrategyFailOnError", func() {
|
When("using InitStrategyFailOnError", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
sutStartStrategy = config.StartStrategyTypeFailOnError
|
sutInitStrategy = config.InitStrategyFailOnError
|
||||||
})
|
})
|
||||||
It("should fail to start", func() {
|
It("should fail to start", func() {
|
||||||
Expect(err).Should(HaveOccurred())
|
Expect(err).Should(HaveOccurred())
|
||||||
|
@ -171,7 +171,7 @@ var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
|
||||||
|
|
||||||
When("using InitStrategyBlocking", func() {
|
When("using InitStrategyBlocking", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
sutStartStrategy = config.StartStrategyTypeBlocking
|
sutInitStrategy = config.InitStrategyBlocking
|
||||||
})
|
})
|
||||||
It("should start", func() {
|
It("should start", func() {
|
||||||
Expect(err).Should(Succeed())
|
Expect(err).Should(Succeed())
|
||||||
|
@ -357,7 +357,7 @@ var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
|
||||||
b := newTestBootstrap(ctx, &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: dns.RcodeServerFailure}})
|
b := newTestBootstrap(ctx, &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: dns.RcodeServerFailure}})
|
||||||
|
|
||||||
upstreamsCfg := sut.cfg.Upstreams
|
upstreamsCfg := sut.cfg.Upstreams
|
||||||
upstreamsCfg.Init.Strategy = config.StartStrategyTypeFailOnError
|
upstreamsCfg.Init.Strategy = config.InitStrategyFailOnError
|
||||||
|
|
||||||
group := config.NewUpstreamGroup("test", upstreamsCfg, []config.Upstream{{Host: "example.com"}})
|
group := config.NewUpstreamGroup("test", upstreamsCfg, []config.Upstream{{Host: "example.com"}})
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ func NewStrictResolver(
|
||||||
) (*StrictResolver, error) {
|
) (*StrictResolver, error) {
|
||||||
r := newStrictResolver(
|
r := newStrictResolver(
|
||||||
cfg,
|
cfg,
|
||||||
[]Resolver{bootstrap}, // if start strategy is fast, use bootstrap until init finishes
|
[]Resolver{bootstrap}, // if init strategy is fast, use bootstrap until init finishes
|
||||||
)
|
)
|
||||||
|
|
||||||
return initGroupResolvers(ctx, r, cfg, bootstrap)
|
return initGroupResolvers(ctx, r, cfg, bootstrap)
|
||||||
|
|
|
@ -16,9 +16,9 @@ import (
|
||||||
|
|
||||||
var _ = Describe("StrictResolver", Label("strictResolver"), func() {
|
var _ = Describe("StrictResolver", Label("strictResolver"), func() {
|
||||||
var (
|
var (
|
||||||
sut *StrictResolver
|
sut *StrictResolver
|
||||||
sutStartStrategy config.StartStrategyType
|
sutInitStrategy config.InitStrategy
|
||||||
upstreams []config.Upstream
|
upstreams []config.Upstream
|
||||||
|
|
||||||
err error
|
err error
|
||||||
|
|
||||||
|
@ -47,14 +47,14 @@ var _ = Describe("StrictResolver", Label("strictResolver"), func() {
|
||||||
{Host: "127.0.0.2"},
|
{Host: "127.0.0.2"},
|
||||||
}
|
}
|
||||||
|
|
||||||
sutStartStrategy = config.StartStrategyTypeBlocking
|
sutInitStrategy = config.InitStrategyBlocking
|
||||||
|
|
||||||
bootstrap = systemResolverBootstrap
|
bootstrap = systemResolverBootstrap
|
||||||
})
|
})
|
||||||
|
|
||||||
JustBeforeEach(func() {
|
JustBeforeEach(func() {
|
||||||
upstreamsCfg := defaultUpstreamsConfig
|
upstreamsCfg := defaultUpstreamsConfig
|
||||||
upstreamsCfg.Init.Strategy = sutStartStrategy
|
upstreamsCfg.Init.Strategy = sutInitStrategy
|
||||||
|
|
||||||
sutConfig := config.NewUpstreamGroup("test", upstreamsCfg, upstreams)
|
sutConfig := config.NewUpstreamGroup("test", upstreamsCfg, upstreams)
|
||||||
sutConfig.Timeout = config.Duration(timeout)
|
sutConfig.Timeout = config.Duration(timeout)
|
||||||
|
@ -120,7 +120,7 @@ var _ = Describe("StrictResolver", Label("strictResolver"), func() {
|
||||||
|
|
||||||
When("strict checking is enabled", func() {
|
When("strict checking is enabled", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
sutStartStrategy = config.StartStrategyTypeFailOnError
|
sutInitStrategy = config.InitStrategyFailOnError
|
||||||
})
|
})
|
||||||
It("should fail to start", func() {
|
It("should fail to start", func() {
|
||||||
Expect(err).Should(HaveOccurred())
|
Expect(err).Should(HaveOccurred())
|
||||||
|
@ -129,7 +129,7 @@ var _ = Describe("StrictResolver", Label("strictResolver"), func() {
|
||||||
|
|
||||||
When("strict checking is disabled", func() {
|
When("strict checking is disabled", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
sutStartStrategy = config.StartStrategyTypeBlocking
|
sutInitStrategy = config.InitStrategyBlocking
|
||||||
})
|
})
|
||||||
It("should start", func() {
|
It("should start", func() {
|
||||||
Expect(err).Should(Succeed())
|
Expect(err).Should(Succeed())
|
||||||
|
|
|
@ -132,9 +132,9 @@ var _ = Describe("UpstreamTreeResolver", Label("upstreamTreeResolver"), func() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
When("start strategy is failOnError", func() {
|
When("init strategy is failOnError", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
sutConfig.Init.Strategy = config.StartStrategyTypeFailOnError
|
sutConfig.Init.Strategy = config.InitStrategyFailOnError
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should fail", func() {
|
It("should fail", func() {
|
||||||
|
|
Loading…
Reference in New Issue