github.com/uber/kraken@v0.1.4/lib/healthcheck/monitor_test.go (about) 1 // Copyright (c) 2016-2019 Uber Technologies, 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package healthcheck 15 16 import ( 17 "testing" 18 "time" 19 20 "github.com/uber/kraken/lib/hostlist" 21 "github.com/uber/kraken/mocks/lib/healthcheck" 22 "github.com/uber/kraken/utils/stringset" 23 24 "github.com/golang/mock/gomock" 25 "github.com/stretchr/testify/require" 26 ) 27 28 func TestActiveMonitor(t *testing.T) { 29 require := require.New(t) 30 31 ctrl := gomock.NewController(t) 32 defer ctrl.Finish() 33 34 x := "x:80" 35 y := "y:80" 36 37 filter := mockhealthcheck.NewMockFilter(ctrl) 38 39 filter.EXPECT().Run(stringset.New(x, y)).Return(stringset.New(x)) 40 41 m := NewMonitor( 42 MonitorConfig{Interval: time.Second}, 43 hostlist.Fixture(x, y), 44 filter) 45 defer m.Stop() 46 47 require.Equal(stringset.New(x, y), m.Resolve()) 48 49 time.Sleep(1250 * time.Millisecond) 50 51 require.Equal(stringset.New(x), m.Resolve()) 52 }