예제 #1
0
func TestRemoveHook(t *testing.T) {
	checker := New(time.Millisecond)

	counter := struct {
		*sync.Mutex
		called bool
	}{
		&sync.Mutex{},
		false,
	}

	checker.AddHook("testHook", func(m map[string]bool) {
		counter.Lock()
		counter.called = true
		counter.Unlock()
	})
	checker.Start()
	time.Sleep(2 * time.Millisecond)
	counter.Lock()
	if !counter.called {
		t.Error("Counter not called")
	}
	counter.called = false
	counter.Unlock()
	checker.RemoveHook("testHook")
	time.Sleep(2 * time.Millisecond)
	counter.Lock()
	if counter.called {
		t.Error("Counter should not be called")
	}
	counter.Unlock()
	checker.Stop()
}
예제 #2
0
func TestStopIfNotStarted(t *testing.T) {
	checker := New(time.Millisecond)
	err := checker.Stop()
	if err == nil {
		t.Error("Stopped not started checker")
	}
}
예제 #3
0
func TestStartAlreadyStartedChecker(t *testing.T) {
	checker := New(time.Millisecond)
	err := checker.Start()
	if err != nil {
		t.Error("Start checker failed")
	}
	err = checker.Start()
	if err == nil {
		t.Error("The already started checker cannot be started")
	}
	checker.Stop()
}
예제 #4
0
func TestBasicFunction(t *testing.T) {
	checker := New(time.Millisecond)
	checker.RegisterIndicator(&TestIndicator{
		&sync.Mutex{},
		true,
	})
	cond := make(chan bool, 0)

	checker.AddHook("testHook", func(m map[string]bool) {
		ok := m["test"]
		select {
		case cond <- ok:
			log.Println("Condition has been written")
		default:
			log.Println("Cant write condition")
		}
	})
	checker.Start()
	if !<-cond {
		t.Error("Helthchecker failed")
	}
	checker.Stop()
}