From c0703db094c3bdad8d7a1a144eaca29ef4f418e6 Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Mon, 26 Oct 2020 12:02:31 +0000 Subject: [PATCH] add health check to mock connector --- connector/mock.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/connector/mock.go b/connector/mock.go index d96496b..3478851 100644 --- a/connector/mock.go +++ b/connector/mock.go @@ -32,11 +32,11 @@ func (cs *Mock) Init() { rand.Seed(int64(time.Now().Nanosecond())) for i := 0; i < 4; i++ { - cs.makeContainer(3) + cs.makeContainer(3, true) } for i := 0; i < 16; i++ { - cs.makeContainer(1) + cs.makeContainer(1, false) } } @@ -50,12 +50,28 @@ func (cs *Mock) Wait() struct{} { return <-ch } -func (cs *Mock) makeContainer(aggression int64) { +var healthStates = []string{"starting", "healthy", "unhealthy"} + +func (cs *Mock) makeContainer(aggression int64, health bool) { collector := collector.NewMock(aggression) manager := manager.NewMock() c := container.New(makeID(), collector, manager) c.SetMeta("name", makeName()) c.SetState(makeState()) + if health { + var i int + c.SetMeta("health", healthStates[i]) + go func() { + for { + i++ + if i >= len(healthStates) { + i = 0 + } + c.SetMeta("health", healthStates[i]) + time.Sleep(12 * time.Second) + } + }() + } cs.containers = append(cs.containers, c) }