From 3eb8396c501bc8b1048273e6ca88c91d3426b744 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Sun, 10 Jun 2018 14:54:05 +0300 Subject: tests --- service/container_test.go | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'service/container_test.go') diff --git a/service/container_test.go b/service/container_test.go index 5278efe7..bba0056f 100644 --- a/service/container_test.go +++ b/service/container_test.go @@ -8,9 +8,11 @@ import ( "encoding/json" "errors" "time" + "sync" ) type testService struct { + mu sync.Mutex waitForServe chan interface{} delay time.Duration ok bool @@ -33,21 +35,41 @@ func (t *testService) Serve() error { return t.serveE } - if t.waitForServe != nil { - close(t.waitForServe) - t.waitForServe = nil + if c := t.waitChan(); c != nil { + close(c) + t.setChan(nil) } + t.mu.Lock() t.serving = make(chan interface{}) + t.mu.Unlock() + <-t.serving return nil } func (t *testService) Stop() { + t.mu.Lock() + defer t.mu.Unlock() + close(t.serving) } +func (t *testService) waitChan() chan interface{} { + t.mu.Lock() + defer t.mu.Unlock() + + return t.waitForServe +} + +func (t *testService) setChan(c chan interface{}) { + t.mu.Lock() + defer t.mu.Unlock() + + t.waitForServe = c +} + type testCfg struct{ cfg string } func (cfg *testCfg) Get(name string) Config { @@ -237,7 +259,7 @@ func TestContainer_Serve(t *testing.T) { assert.NoError(t, c.Serve()) }() - <-svc.waitForServe + <-svc.waitChan() s, st := c.Get("test") assert.IsType(t, &testService{}, s) -- cgit v1.2.3