github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/metrics/manager/manager_test.go (about)

     1  // Copyright 2015 Google Inc. All Rights Reserved.
     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  
    15  package manager
    16  
    17  import (
    18  	"testing"
    19  	"time"
    20  
    21  	"k8s.io/heapster/metrics/core"
    22  	"k8s.io/heapster/metrics/util"
    23  )
    24  
    25  func TestFlow(t *testing.T) {
    26  	source := util.NewDummyMetricsSource("src", time.Millisecond)
    27  	sink := util.NewDummySink("sink", time.Millisecond)
    28  	processor := util.NewDummyDataProcessor(time.Millisecond)
    29  
    30  	manager, _ := NewManager(source, []core.DataProcessor{processor}, sink, time.Second, time.Millisecond, 1)
    31  	manager.Start()
    32  
    33  	// 4-5 cycles
    34  	time.Sleep(time.Millisecond * 4500)
    35  	manager.Stop()
    36  
    37  	if sink.GetExportCount() < 4 || sink.GetExportCount() > 5 {
    38  		t.Fatalf("Wrong number of exports executed: %d", sink.GetExportCount())
    39  	}
    40  }
    41  
    42  func TestThrottling(t *testing.T) {
    43  	source := util.NewDummyMetricsSource("src", time.Millisecond)
    44  	sink := util.NewDummySink("sink", 4*time.Second)
    45  	processor := util.NewDummyDataProcessor(5 * time.Millisecond)
    46  
    47  	manager, _ := NewManager(source, []core.DataProcessor{processor}, sink, time.Second, time.Millisecond, 1)
    48  	manager.Start()
    49  
    50  	// 4-5 cycles
    51  	time.Sleep(time.Millisecond * 9500)
    52  	manager.Stop()
    53  
    54  	if sink.GetExportCount() < 2 || sink.GetExportCount() > 3 {
    55  		t.Fatalf("Wrong number of exports executed: %d", sink.GetExportCount())
    56  	}
    57  }