1
0
mirror of https://github.com/umputun/reproxy.git synced 2025-09-16 08:46:17 +02:00

adjust tests for delayed events

This commit is contained in:
Umputun
2021-04-12 02:29:17 -05:00
parent 0e5998d540
commit 1ac2f23504
5 changed files with 11 additions and 14 deletions

View File

@@ -51,8 +51,8 @@ const (
)
// NewService makes service with given providers
func NewService(providers []Provider) *Service {
return &Service{providers: providers, interval: time.Second}
func NewService(providers []Provider, interval time.Duration) *Service {
return &Service{providers: providers, interval: interval}
}
// Run runs blocking loop getting events from all providers

View File

@@ -38,8 +38,7 @@ func TestService_Do(t *testing.T) {
}, nil
},
}
svc := NewService([]Provider{p1, p2})
svc.interval = time.Millisecond * 100
svc := NewService([]Provider{p1, p2}, time.Millisecond*10)
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancel()
@@ -85,8 +84,7 @@ func TestService_Match(t *testing.T) {
}, nil
},
}
svc := NewService([]Provider{p1, p2})
svc.interval = time.Millisecond * 100
svc := NewService([]Provider{p1, p2}, time.Millisecond*100)
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancel()
@@ -147,8 +145,7 @@ func TestService_Servers(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancel()
svc := NewService([]Provider{p1, p2})
svc.interval = time.Millisecond * 100
svc := NewService([]Provider{p1, p2}, time.Millisecond*100)
err := svc.Run(ctx)
require.Error(t, err)
assert.Equal(t, context.DeadlineExceeded, err)

View File

@@ -98,7 +98,7 @@ func main() {
log.Fatalf("[ERROR] failed to make providers, %v", err)
}
svc := discovery.NewService(providers)
svc := discovery.NewService(providers, time.Second)
if len(providers) > 0 {
go func() {
if e := svc.Run(context.Background()); e != nil {

View File

@@ -43,7 +43,7 @@ func TestHttp_healthHandler(t *testing.T) {
"localhost,^/api/(.*)," + ds.URL + "/123/$1," + ps.URL + "/123/ping",
"127.0.0.1,^/api/(.*)," + ds.URL + "/567/$1," + ps.URL + "/567/ping",
},
}})
}}, time.Millisecond*10)
go func() {
_ = svc.Run(context.Background())

View File

@@ -36,13 +36,13 @@ func TestHttp_Do(t *testing.T) {
"localhost,^/api/(.*)," + ds.URL + "/123/$1,",
"127.0.0.1,^/api/(.*)," + ds.URL + "/567/$1,",
},
}})
}}, time.Millisecond*10)
go func() {
_ = svc.Run(context.Background())
}()
time.Sleep(10 * time.Millisecond)
time.Sleep(50 * time.Millisecond)
h.Matcher = svc
go func() {
_ = h.Run(ctx)
@@ -109,12 +109,12 @@ func TestHttp_DoWithAssets(t *testing.T) {
"localhost,^/api/(.*)," + ds.URL + "/123/$1,",
"127.0.0.1,^/api/(.*)," + ds.URL + "/567/$1,",
},
}})
}}, time.Millisecond*10)
go func() {
_ = svc.Run(context.Background())
}()
time.Sleep(10 * time.Millisecond)
time.Sleep(50 * time.Millisecond)
h.Matcher = svc
go func() {
_ = h.Run(ctx)