-
Notifications
You must be signed in to change notification settings - Fork 1
/
testutils.go
65 lines (52 loc) · 1.45 KB
/
testutils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package pool
import (
"fmt"
"time"
"github.com/gateway-fm/service-pool/discovery"
"github.com/gateway-fm/service-pool/service"
)
type healthyService struct {
HCheckCounter int
*service.BaseService
}
func (s *healthyService) HealthCheck() error {
if s != nil {
s.HCheckCounter = s.HCheckCounter + 1
s.SetStatus(service.StatusHealthy)
}
return nil
}
func healthySrvMutationFunc(srv service.IService) (service.IService, error) {
baseSrv, ok := srv.(*service.BaseService)
if !ok {
return nil, fmt.Errorf("service is not BaseService")
}
return &healthyService{
0,
baseSrv,
}, nil
}
func dummyMutationFunc(srv service.IService) (service.IService, error) {
return srv, nil
}
func newHealthyService(addr string) service.IService {
srv := service.NewService(addr, "", nil)
baseSrv := srv.(*service.BaseService)
baseSrv.SetStatus(service.StatusHealthy)
return baseSrv
}
func newServicesPool(discoveryInterval time.Duration, hcInterval time.Duration, mutationFunc func(srv service.IService) (service.IService, error)) IServicesPool {
manualDisc, _ := discovery.NewManualDiscovery(discovery.TransportHttp, nil, "localhost")
opts := &ServicesPoolsOpts{
Name: "TestServicePool",
Discovery: manualDisc,
DiscoveryInterval: discoveryInterval,
ListOpts: &ServicesListOpts{
TryUpTries: 5,
TryUpInterval: 1 * time.Second,
ChecksInterval: hcInterval,
},
MutationFnc: mutationFunc,
}
return NewServicesPool(opts)
}