Exemplo n.º 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()
}
Exemplo 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()
}