]> git.scottworley.com Git - reliable-chat/commitdiff
Test multiple listeners
authorScott Worley <sworley@chkno.net>
Sat, 28 Jul 2012 19:14:25 +0000 (12:14 -0700)
committerScott Worley <sworley@chkno.net>
Sat, 28 Jul 2012 19:14:25 +0000 (12:14 -0700)
server/server_test.go

index 516f62ac1b3494a75c2431c3bffdce93c3632e95..fd4a4c87a108a964b509ad095036c20cfd1346fc 100644 (file)
@@ -51,3 +51,31 @@ func TestFetchBlocksUntilSpeak(t *testing.T) {
        close(store.Get)
        close(store.Add)
 }
+
+func TestMultipleListeners(t *testing.T) {
+       say := "This is your nine o'clock alarm call!"
+       at := time.Now()
+       var zero_time time.Time
+       store := start_store()
+       const num_clients = 13
+       var messages_from_store [num_clients]chan []Message
+       for i := 0; i < num_clients; i++ {
+               messages_from_store[i] = make(chan []Message, 1)
+               store.Get <- &StoreRequest{zero_time, messages_from_store[i]}
+       }
+       store.Add <- &Message{at, say}
+       for i := 0; i < num_clients; i++ {
+               messages := <-messages_from_store[i]
+               if len(messages) != 1 {
+                       t.Fail()
+               }
+               if messages[0].Time != at {
+                       t.Fail()
+               }
+               if messages[0].Text != say {
+                       t.Fail()
+               }
+       }
+       close(store.Get)
+       close(store.Add)
+}