X-Git-Url: http://git.scottworley.com/reliable-chat/blobdiff_plain/1c4255180393ac0b6dbea555855aa8c94c2edcdb..70a65c051dc20b4b8875b6a7cfd9bca3bd05f5a3:/server/server_test.go diff --git a/server/server_test.go b/server/server_test.go index fb20ddc..8fd648f 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -1,3 +1,20 @@ +/* reliable-chat - multipath chat + * Copyright (C) 2012 Scott Worley + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package main import "testing" @@ -23,6 +40,11 @@ func TestMessageInsertAndRetreive(t *testing.T) { at := time.Now() var zero_time time.Time store := start_store() + defer func() { + close(store.Get) + close(store.Add) + }() + store.Add <- &Message{at, id, say} messages_from_store := make(chan []Message, 1) store.Get <- &StoreRequest{zero_time, messages_from_store} @@ -31,8 +53,6 @@ func TestMessageInsertAndRetreive(t *testing.T) { t.FailNow() } expectMessage(t, &messages[0], at, id, say) - close(store.Get) - close(store.Add) } func TestFetchBlocksUntilSpeak(t *testing.T) { @@ -42,6 +62,11 @@ func TestFetchBlocksUntilSpeak(t *testing.T) { at := time.Now() var zero_time time.Time store := start_store() + defer func() { + close(store.Get) + close(store.Add) + }() + messages_from_store := make(chan []Message, 1) store.Get <- &StoreRequest{zero_time, messages_from_store} for start_fetch_wait_count == fetch_wait_count.String() { @@ -53,8 +78,6 @@ func TestFetchBlocksUntilSpeak(t *testing.T) { t.FailNow() } expectMessage(t, &messages[0], at, id, say) - close(store.Get) - close(store.Add) } func TestMultipleListeners(t *testing.T) { @@ -63,6 +86,11 @@ func TestMultipleListeners(t *testing.T) { at := time.Now() var zero_time time.Time store := start_store() + defer func() { + close(store.Get) + close(store.Add) + }() + const num_clients = 13 var messages_from_store [num_clients]chan []Message for i := 0; i < num_clients; i++ { @@ -75,10 +103,8 @@ func TestMultipleListeners(t *testing.T) { if len(messages) != 1 { t.FailNow() } - expectMessage(t,& messages[0], at, id, say) + expectMessage(t, &messages[0], at, id, say) } - close(store.Get) - close(store.Add) } func parseDuration(s string) time.Duration { @@ -111,6 +137,11 @@ func TestPartialRetreive(t *testing.T) { at2 := base.Add(parseDuration("-2m")) at3 := base.Add(parseDuration("-1m")) store := start_store() + defer func() { + close(store.Get) + close(store.Add) + }() + store.Add <- &Message{at1, id1, say1} store.Add <- &Message{at2, id2, say2} store.Add <- &Message{at3, id3, say3} @@ -125,8 +156,6 @@ func TestPartialRetreive(t *testing.T) { } expectMessage(t, &messages[0], at2, id2, say2) expectMessage(t, &messages[1], at3, id3, say3) - close(store.Get) - close(store.Add) } func TestPrecisePartialRetreive(t *testing.T) { @@ -143,6 +172,11 @@ func TestPrecisePartialRetreive(t *testing.T) { at3 := base.Add(parseDuration("-1m")) since := at2 store := start_store() + defer func() { + close(store.Get) + close(store.Add) + }() + store.Add <- &Message{at1, id1, say1} store.Add <- &Message{at2, id2, say2} store.Add <- &Message{at3, id3, say3} @@ -156,8 +190,6 @@ func TestPrecisePartialRetreive(t *testing.T) { t.FailNow() } expectMessage(t, &messages[0], at3, id3, say3) - close(store.Get) - close(store.Add) } func TestTypicalFlow(t *testing.T) { @@ -166,6 +198,10 @@ func TestTypicalFlow(t *testing.T) { say1 := "The Norwegian Blue prefers kippin' on it's back!" say2 := "Remarkable bird, innit, squire? Lovely plumage!" store := start_store() + defer func() { + close(store.Get) + close(store.Add) + }() // A waiting zero-time fetch. var zero_time time.Time @@ -204,7 +240,4 @@ func TestTypicalFlow(t *testing.T) { t.FailNow() } expectMessage(t, &messages2[0], at2, id2, say2) - - close(store.Get) - close(store.Add) }