]> git.scottworley.com Git - reliable-chat/commitdiff
Shut down the message store after each test
authorScott Worley <sworley@chkno.net>
Sat, 28 Jul 2012 18:28:37 +0000 (11:28 -0700)
committerScott Worley <sworley@chkno.net>
Sat, 28 Jul 2012 18:28:37 +0000 (11:28 -0700)
server/server.go
server/server_test.go

index bfe10669e7f0bd34368984dffbde1c7fe8adcd55..7572447610372c8dd45c6c6dc063924df36bcecf 100644 (file)
@@ -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 {
index d1bababe56686e455d876bf16985f763e0743dd4..9fabf81995cea230431b5a22ea2b5655b3a4d5eb 100644 (file)
@@ -21,4 +21,6 @@ func TestMessageInsertAndRetreive(t *testing.T) {
        if messages[0].Text != say {
                t.Fail()
        }
+       close(store.Get)
+       close(store.Add)
 }