]> git.scottworley.com Git - reliable-chat/commitdiff
Test fetch blocking
authorScott Worley <sworley@chkno.net>
Sat, 28 Jul 2012 19:06:43 +0000 (12:06 -0700)
committerScott Worley <sworley@chkno.net>
Sat, 28 Jul 2012 19:06:43 +0000 (12:06 -0700)
Fetch blocks until message is sent.
Fetches initiated before a speak return the later-spoken value.

server/server_test.go

index 9fabf81995cea230431b5a22ea2b5655b3a4d5eb..516f62ac1b3494a75c2431c3bffdce93c3632e95 100644 (file)
@@ -1,10 +1,11 @@
 package main
 
 import "testing"
 package main
 
 import "testing"
+import "runtime"
 import "time"
 
 func TestMessageInsertAndRetreive(t *testing.T) {
 import "time"
 
 func TestMessageInsertAndRetreive(t *testing.T) {
-       say := ""
+       say := "'Ello, Mister Polly Parrot!"
        at := time.Now()
        var zero_time time.Time
        store := start_store()
        at := time.Now()
        var zero_time time.Time
        store := start_store()
@@ -24,3 +25,29 @@ func TestMessageInsertAndRetreive(t *testing.T) {
        close(store.Get)
        close(store.Add)
 }
        close(store.Get)
        close(store.Add)
 }
+
+func TestFetchBlocksUntilSpeak(t *testing.T) {
+       start_fetch_wait_count := fetch_wait_count.String()
+       say := "I've got a lovely fresh cuttle fish for you"
+       at := time.Now()
+       var zero_time time.Time
+       store := start_store()
+       messages_from_store := make(chan []Message, 1)
+       store.Get <- &StoreRequest{zero_time, messages_from_store}
+       for start_fetch_wait_count == fetch_wait_count.String() {
+               runtime.Gosched()
+       }
+       store.Add <- &Message{at, say}
+       messages := <-messages_from_store
+       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)
+}