Esempio n. 1
0
func TestUnregister(t *testing.T) {
	checker := New(time.Millisecond)
	indicator := &TestIndicator{
		&sync.Mutex{},
		false,
	}
	checker.RegisterIndicator(indicator)
	checker.Start()
	time.Sleep(2 * time.Millisecond)
	checker.UnregisterIndicator(indicator)
	indicator.Lock()
	indicator.hasBeenCalled = false
	indicator.Unlock()
	time.Sleep(2 * time.Millisecond)

	if indicator.hasBeenCalled {
		t.Error("Unregistration not sucessfull")
	}
}
Esempio n. 2
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()
}