]> git.scottworley.com Git - reliable-chat/blob - server/server_test.go
516f62ac1b3494a75c2431c3bffdce93c3632e95
[reliable-chat] / server / server_test.go
1 package main
2
3 import "testing"
4 import "runtime"
5 import "time"
6
7 func TestMessageInsertAndRetreive(t *testing.T) {
8 say := "'Ello, Mister Polly Parrot!"
9 at := time.Now()
10 var zero_time time.Time
11 store := start_store()
12 store.Add <- &Message{at, say}
13 messages_from_store := make(chan []Message, 1)
14 store.Get <- &StoreRequest{zero_time, messages_from_store}
15 messages := <-messages_from_store
16 if len(messages) != 1 {
17 t.Fail()
18 }
19 if messages[0].Time != at {
20 t.Fail()
21 }
22 if messages[0].Text != say {
23 t.Fail()
24 }
25 close(store.Get)
26 close(store.Add)
27 }
28
29 func TestFetchBlocksUntilSpeak(t *testing.T) {
30 start_fetch_wait_count := fetch_wait_count.String()
31 say := "I've got a lovely fresh cuttle fish for you"
32 at := time.Now()
33 var zero_time time.Time
34 store := start_store()
35 messages_from_store := make(chan []Message, 1)
36 store.Get <- &StoreRequest{zero_time, messages_from_store}
37 for start_fetch_wait_count == fetch_wait_count.String() {
38 runtime.Gosched()
39 }
40 store.Add <- &Message{at, say}
41 messages := <-messages_from_store
42 if len(messages) != 1 {
43 t.Fail()
44 }
45 if messages[0].Time != at {
46 t.Fail()
47 }
48 if messages[0].Text != say {
49 t.Fail()
50 }
51 close(store.Get)
52 close(store.Add)
53 }