-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbroadcast_test.go
56 lines (50 loc) · 1.22 KB
/
broadcast_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
// func TestBroadcast(t *testing.T) {
// bs := NewBroadcastString()
// bs.WriteMessage("hello")
// time.Sleep(10 * time.Millisecond)
// c1 := bs.AddListener(nil)
// go func() {
// bs.WriteMessage("world")
// }()
// message := <-c1
// if message != "world" {
// t.Fatalf("expect message world, but got %s", message)
// }
// c2 := bs.AddListener(nil)
// go func() {
// bs.WriteMessage("tab")
// }()
// // test write multi
// wg := sync.WaitGroup{}
// wg.Add(2)
// go func() {
// message = <-c2
// if message != "tab" {
// t.Errorf("expect tab, but got %s", message)
// }
// wg.Done()
// }()
// go func() {
// message = <-c1
// if message != "tab" {
// t.Errorf("expect tab, but got %s", message)
// }
// wg.Done()
// }()
// wg.Wait()
// }
func TestRingBuffer(t *testing.T) {
Convey("Write some string to ring buffer", t, func() {
// buf := rbuf.NewFixedSizeRingBuf(5)
// buf.Write([]byte("abcde"))
// So(string(buf.Bytes()), ShouldEqual, "abcde")
// buf.Advance(2)
// buf.Write([]byte("fg"))
// So(string(buf.Bytes()), ShouldEqual, "cdefg")
})
}