Cleanup test file

This commit is contained in:
tidwall 2021-03-30 07:41:50 -07:00
parent 730a465d73
commit 09e3f71e1b
1 changed files with 29 additions and 29 deletions

View File

@ -200,14 +200,14 @@ func TestRandomCommands(t *testing.T) {
cnt++ cnt++
} }
if false { if false {
dur := time.Now().Sub(start) dur := time.Since(start)
fmt.Printf("%d commands in %s - %.0f ops/sec\n", cnt, dur, float64(cnt)/(float64(dur)/float64(time.Second))) fmt.Printf("%d commands in %s - %.0f ops/sec\n", cnt, dur, float64(cnt)/(float64(dur)/float64(time.Second)))
} }
} }
func testDetached(t *testing.T, conn DetachedConn) { func testDetached(conn DetachedConn) {
conn.WriteString("DETACHED") conn.WriteString("DETACHED")
if err := conn.Flush(); err != nil { if err := conn.Flush(); err != nil {
t.Fatal(err) panic(err)
} }
} }
func TestServerTCP(t *testing.T) { func TestServerTCP(t *testing.T) {
@ -231,7 +231,7 @@ func testServerNetwork(t *testing.T, network, laddr string) {
conn.WriteString("OK") conn.WriteString("OK")
conn.Close() conn.Close()
case "detach": case "detach":
go testDetached(t, conn.Detach()) go testDetached(conn.Detach())
case "int": case "int":
conn.WriteInt(100) conn.WriteInt(100)
case "bulk": case "bulk":
@ -262,17 +262,17 @@ func testServerNetwork(t *testing.T, network, laddr string) {
go func() { go func() {
time.Sleep(time.Second / 4) time.Sleep(time.Second / 4)
if err := ListenAndServeNetwork(network, laddr, func(conn Conn, cmd Command) {}, nil, nil); err == nil { if err := ListenAndServeNetwork(network, laddr, func(conn Conn, cmd Command) {}, nil, nil); err == nil {
t.Fatalf("expected an error, should not be able to listen on the same port") panic("expected an error, should not be able to listen on the same port")
} }
time.Sleep(time.Second / 4) time.Sleep(time.Second / 4)
err := s.Close() err := s.Close()
if err != nil { if err != nil {
t.Fatal(err) panic(err)
} }
err = s.Close() err = s.Close()
if err == nil { if err == nil {
t.Fatalf("expected an error") panic("expected an error")
} }
}() }()
done := make(chan bool) done := make(chan bool)
@ -283,11 +283,11 @@ func testServerNetwork(t *testing.T, network, laddr string) {
}() }()
err := <-signal err := <-signal
if err != nil { if err != nil {
t.Fatal(err) panic(err)
} }
c, err := net.Dial(network, laddr) c, err := net.Dial(network, laddr)
if err != nil { if err != nil {
t.Fatal(err) panic(err)
} }
defer c.Close() defer c.Close()
do := func(cmd string) (string, error) { do := func(cmd string) (string, error) {
@ -301,65 +301,65 @@ func testServerNetwork(t *testing.T, network, laddr string) {
} }
res, err := do("PING\r\n") res, err := do("PING\r\n")
if err != nil { if err != nil {
t.Fatal(err) panic(err)
} }
if res != "+PONG\r\n" { if res != "+PONG\r\n" {
t.Fatalf("expecting '+PONG\r\n', got '%v'", res) panic(fmt.Sprintf("expecting '+PONG\r\n', got '%v'", res))
} }
res, err = do("BULK\r\n") res, err = do("BULK\r\n")
if err != nil { if err != nil {
t.Fatal(err) panic(err)
} }
if res != "$4\r\nbulk\r\n" { if res != "$4\r\nbulk\r\n" {
t.Fatalf("expecting bulk, got '%v'", res) panic(fmt.Sprintf("expecting bulk, got '%v'", res))
} }
res, err = do("BULKBYTES\r\n") res, err = do("BULKBYTES\r\n")
if err != nil { if err != nil {
t.Fatal(err) panic(err)
} }
if res != "$9\r\nbulkbytes\r\n" { if res != "$9\r\nbulkbytes\r\n" {
t.Fatalf("expecting bulkbytes, got '%v'", res) panic(fmt.Sprintf("expecting bulkbytes, got '%v'", res))
} }
res, err = do("INT\r\n") res, err = do("INT\r\n")
if err != nil { if err != nil {
t.Fatal(err) panic(err)
} }
if res != ":100\r\n" { if res != ":100\r\n" {
t.Fatalf("expecting int, got '%v'", res) panic(fmt.Sprintf("expecting int, got '%v'", res))
} }
res, err = do("NULL\r\n") res, err = do("NULL\r\n")
if err != nil { if err != nil {
t.Fatal(err) panic(err)
} }
if res != "$-1\r\n" { if res != "$-1\r\n" {
t.Fatalf("expecting nul, got '%v'", res) panic(fmt.Sprintf("expecting nul, got '%v'", res))
} }
res, err = do("ARRAY\r\n") res, err = do("ARRAY\r\n")
if err != nil { if err != nil {
t.Fatal(err) panic(err)
} }
if res != "*2\r\n:99\r\n+Hi!\r\n" { if res != "*2\r\n:99\r\n+Hi!\r\n" {
t.Fatalf("expecting array, got '%v'", res) panic(fmt.Sprintf("expecting array, got '%v'", res))
} }
res, err = do("ERR\r\n") res, err = do("ERR\r\n")
if err != nil { if err != nil {
t.Fatal(err) panic(err)
} }
if res != "-ERR error\r\n" { if res != "-ERR error\r\n" {
t.Fatalf("expecting array, got '%v'", res) panic(fmt.Sprintf("expecting array, got '%v'", res))
} }
res, err = do("DETACH\r\n") res, err = do("DETACH\r\n")
if err != nil { if err != nil {
t.Fatal(err) panic(err)
} }
if res != "+DETACHED\r\n" { if res != "+DETACHED\r\n" {
t.Fatalf("expecting string, got '%v'", res) panic(fmt.Sprintf("expecting string, got '%v'", res))
} }
}() }()
go func() { go func() {
err := s.ListenServeAndSignal(signal) err := s.ListenServeAndSignal(signal)
if err != nil { if err != nil {
t.Fatal(err) panic(err)
} }
}() }()
<-done <-done
@ -432,12 +432,12 @@ func TestReaderRespRandom(t *testing.T) {
for h := 0; h < 10000; h++ { for h := 0; h < 10000; h++ {
var rawargs [][]string var rawargs [][]string
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
var args []string // var args []string
n := int(rand.Int() % 16) n := int(rand.Int() % 16)
for j := 0; j < n; j++ { for j := 0; j < n; j++ {
arg := make([]byte, rand.Int()%512) arg := make([]byte, rand.Int()%512)
rand.Read(arg) rand.Read(arg)
args = append(args, string(arg)) // args = append(args, string(arg))
} }
} }
rawcmds := testMakeRawCommands(rawargs) rawcmds := testMakeRawCommands(rawargs)
@ -593,7 +593,7 @@ func TestPubSub(t *testing.T) {
ps.Publish(channel, message) ps.Publish(channel, message)
} }
}() }()
t.Fatal(ListenAndServe(addr, func(conn Conn, cmd Command) { panic(ListenAndServe(addr, func(conn Conn, cmd Command) {
switch strings.ToLower(string(cmd.Args[0])) { switch strings.ToLower(string(cmd.Args[0])) {
default: default:
conn.WriteError("ERR unknown command '" + conn.WriteError("ERR unknown command '" +