From: Scott Worley Date: Sat, 28 Jul 2012 18:28:37 +0000 (-0700) Subject: Shut down the message store after each test X-Git-Url: http://git.scottworley.com/reliable-chat/commitdiff_plain/c282d87802c8a36e1ef5e4b367e7e753c2ba05f5 Shut down the message store after each test --- diff --git a/server/server.go b/server/server.go index bfe1066..7572447 100644 --- a/server/server.go +++ b/server/server.go @@ -28,9 +28,13 @@ func manage_store(store Store) { message_count := 0 max_messages := 1000 waiting := list.New() +main: for { select { - case new_message := <-store.Add: + case new_message, ok := <-store.Add: + if !ok { + break main + } messages.PushBack(new_message) for waiter := waiting.Front(); waiter != nil; waiter = waiter.Next() { waiter.Value.(*StoreRequest).Messages <- []Message{*new_message} @@ -42,7 +46,10 @@ func manage_store(store Store) { } else { messages.Remove(messages.Front()) } - case request := <-store.Get: + case request, ok := <-store.Get: + if !ok { + break main + } if messages.Back() == nil || !request.StartTime.Before(messages.Back().Value.(*Message).Time) { waiting.PushBack(request) } else { diff --git a/server/server_test.go b/server/server_test.go index d1babab..9fabf81 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -21,4 +21,6 @@ func TestMessageInsertAndRetreive(t *testing.T) { if messages[0].Text != say { t.Fail() } + close(store.Get) + close(store.Add) }