github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/events/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  	kube_api "k8s.io/api/core/v1"
    22  	"k8s.io/heapster/events/core"
    23  	"k8s.io/heapster/events/util"
    24  )
    25  
    26  func TestFlow(t *testing.T) {
    27  	batch := &core.EventBatch{
    28  		Timestamp: time.Now(),
    29  		Events:    []*kube_api.Event{},
    30  	}
    31  
    32  	source := util.NewDummySource(batch)
    33  	sink := util.NewDummySink("sink", time.Millisecond)
    34  
    35  	manager, _ := NewManager(source, sink, time.Second)
    36  	manager.Start()
    37  
    38  	// 4-5 cycles
    39  	time.Sleep(time.Millisecond * 4500)
    40  	manager.Stop()
    41  
    42  	if sink.GetExportCount() < 4 || sink.GetExportCount() > 5 {
    43  		t.Fatalf("Wrong number of exports executed: %d", sink.GetExportCount())
    44  	}
    45  }