You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
stario/circle_test.go

62 lines
996 B
Go

package stario
import (
"fmt"
"sync/atomic"
"testing"
"time"
)
func Test_Circle(t *testing.T) {
buf := NewStarBuffer(2048)
go func() {
for {
//fmt.Println("write start")
buf.Write([]byte("中华人民共和国\n"))
//fmt.Println("write success")
time.Sleep(time.Millisecond * 50)
}
}()
cpp := ""
go func() {
time.Sleep(time.Second * 3)
for {
cache := make([]byte, 64)
ints, err := buf.Read(cache)
if err != nil {
fmt.Println("read error", err)
return
}
if ints != 0 {
cpp += string(cache[:ints])
}
}
}()
time.Sleep(time.Second * 13)
fmt.Println(cpp)
}
func Test_Circle_Speed(t *testing.T) {
buf := NewStarBuffer(1048976)
count := uint64(0)
for i := 1; i <= 10; i++ {
go func() {
for {
buf.putByte('a')
}
}()
}
for i := 1; i <= 10; i++ {
go func() {
for {
_,err:=buf.getByte()
if err == nil {
atomic.AddUint64(&count, 1)
}
}
}()
}
time.Sleep(time.Second * 10)
fmt.Println(count)
}