X-Git-Url: http://git.scottworley.com/reliable-chat/blobdiff_plain/70a65c051dc20b4b8875b6a7cfd9bca3bd05f5a3..777027a86dcc56e57327d9084ab53942070fdabc:/server/server_test.go diff --git a/server/server_test.go b/server/server_test.go index 8fd648f..b9a7c92 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -3,8 +3,7 @@ * * 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. + * published by the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -241,3 +240,46 @@ func TestTypicalFlow(t *testing.T) { } expectMessage(t, &messages2[0], at2, id2, say2) } + +func TestExpiryDueToLimit(t *testing.T) { + previous_limit := *max_messages + defer func() { *max_messages = previous_limit }() + *max_messages = 2 + + start_speak_count := atoi(speak_count.String()) + start_drop_count := atoi(drop_due_to_limit_count.String()) + id1 := "12" + id2 := "13" + id3 := "14" + say1 := "'E's passed on!" + say2 := "This parrot is no more!" + say3 := "He has ceased to be!" + base := time.Now() + at1 := base.Add(parseDuration("-3m")) + 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} + for atoi(speak_count.String()) != start_speak_count+3 { + runtime.Gosched() + } + if atoi(drop_due_to_limit_count.String()) != start_drop_count+1 { + t.Fail() + } + messages_from_store := make(chan []Message, 1) + var zero_time time.Time + store.Get <- &StoreRequest{zero_time, messages_from_store} + messages := <-messages_from_store + if len(messages) != 2 { + t.FailNow() + } + expectMessage(t, &messages[0], at2, id2, say2) + expectMessage(t, &messages[1], at3, id3, say3) +}