Skip to content

Commit

Permalink
fix golangci-lint 错误
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong committed May 23, 2024
1 parent 45d8506 commit 16e5cae
Show file tree
Hide file tree
Showing 15 changed files with 672 additions and 180 deletions.
4 changes: 3 additions & 1 deletion autobahn/client/autobahn-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func runTest(caseNo int) {
return
}

go c.ReadLoop()
go func() {
_ = c.ReadLoop()
}()
<-done
}

Expand Down
10 changes: 5 additions & 5 deletions autobahn/server/autobahn-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func echoNoContextDecompression(w http.ResponseWriter, r *http.Request) {
return
}

c.ReadLoop()
_ = c.ReadLoop()
}

// 2.测试不接管上下文,压缩和解压
Expand All @@ -81,7 +81,7 @@ func echoNoContextDecompressionAndCompression(w http.ResponseWriter, r *http.Req
return
}

c.ReadLoop()
_ = c.ReadLoop()
}

// 3.测试接管上下文,解压
Expand All @@ -99,7 +99,7 @@ func echoContextTakeoverDecompression(w http.ResponseWriter, r *http.Request) {
return
}

c.ReadLoop()
_ = c.ReadLoop()
}

// 4.测试接管上下文,压缩/解压缩
Expand All @@ -117,7 +117,7 @@ func echoContextTakeoverDecompressionAndCompression(w http.ResponseWriter, r *ht
return
}

c.ReadLoop()
_ = c.ReadLoop()
}
func echoReadTime(w http.ResponseWriter, r *http.Request) {
c, err := quickws.Upgrade(w, r,
Expand All @@ -133,7 +133,7 @@ func echoReadTime(w http.ResponseWriter, r *http.Request) {
return
}

c.ReadLoop()
_ = c.ReadLoop()
}

func startTLSServer(mux *http.ServeMux) {
Expand Down
6 changes: 3 additions & 3 deletions benchmark_read_write_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func Benchmark_WriteMessage(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
c.WriteMessage(opcode.Binary, buf)
_ = c.WriteMessage(opcode.Binary, buf)
buf2.Reset()
}
})
Expand Down Expand Up @@ -141,8 +141,8 @@ func Benchmark_ReadMessage(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
c.WriteMessage(opcode.Binary, wbuf)
c.ReadLoop()
_ = c.WriteMessage(opcode.Binary, wbuf)
_ = c.ReadLoop()
buf2.Reset()
}
})
Expand Down
17 changes: 15 additions & 2 deletions callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ func Test_DefaultCallback(t *testing.T) {
}
defer con.Close()

con.WriteMessage(Binary, []byte("hello"))
err = con.WriteMessage(Binary, []byte("hello"))

if err != nil {
t.Error(err)
return
}
select {
case <-done:
case <-time.After(1000 * time.Millisecond):
Expand All @@ -86,6 +91,10 @@ func Test_DefaultCallback(t *testing.T) {
}
c.StartReadLoop()
err = c.WriteMessage(Binary, []byte("hello"))
if err != nil {
t.Error(err)
return
}
atomic.AddInt32(&run, int32(1))
done <- true
}))
Expand All @@ -99,7 +108,11 @@ func Test_DefaultCallback(t *testing.T) {
}
defer con.Close()

con.WriteMessage(Binary, []byte("hello"))
err = con.WriteMessage(Binary, []byte("hello"))
if err != nil {
t.Error(err)
return
}
select {
case <-done:
case <-time.After(100 * time.Millisecond):
Expand Down
5 changes: 3 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ func (d *DialOption) Dial() (wsCon *Conn, err error) {
bufio2.ClearReader(br)
br = nil
}
// fmt.Println(brw.Reader.Buffered())
conn.SetDeadline(time.Time{})
if err := conn.SetDeadline(time.Time{}); err != nil {
return nil, err
}
wsCon = newConn(conn, true /* client is true*/, &d.Config, fr, br)
wsCon.pd = pd
return wsCon, nil
Expand Down
65 changes: 53 additions & 12 deletions client_option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ func Test_ClientOption(t *testing.T) {
t.Run("18 Dial: WithClientDialFunc.1", func(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
conn, err := Upgrade(w, r, WithServerOnMessageFunc(func(c *Conn, o Opcode, b []byte) {
c.WriteMessage(o, b)
err := c.WriteMessage(o, b)
if err != nil {
t.Error(err)
return
}
c.Close()
}))
if err != nil {
Expand All @@ -228,7 +232,11 @@ func Test_ClientOption(t *testing.T) {
t.Error(err)
}

newConn.SetDeadline(time.Now().Add(30 * time.Second))
err = newConn.SetDeadline(time.Now().Add(30 * time.Second))
if err != nil {
t.Error(err)
return
}

buf := make([]byte, 128)
if _, err := io.ReadFull(newConn, buf[:3]); err != nil {
Expand Down Expand Up @@ -274,10 +282,19 @@ func Test_ClientOption(t *testing.T) {
defer c2.Close()
done := make(chan struct{})
go func() {
io.Copy(newConn, c2)
_, err := io.Copy(newConn, c2)
if err != nil {
t.Error(err)
return
}

close(done)
}()
io.Copy(c2, newConn)
_, err = io.Copy(c2, newConn)
if err != nil {
t.Error(err)
return
}
<-done
}()

Expand All @@ -294,8 +311,12 @@ func Test_ClientOption(t *testing.T) {
}

data := []byte("hello world")
c.WriteMessage(Binary, data)
c.ReadLoop()
err = c.WriteMessage(Binary, data)
if err != nil {
t.Error(err)
return
}
_ = c.ReadLoop()

t.Log("got", string(got), "want", string(data))
if !bytes.Equal(got, data) {
Expand All @@ -306,7 +327,11 @@ func Test_ClientOption(t *testing.T) {
t.Run("18 Dial: WithClientDialFunc.2", func(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
conn, err := Upgrade(w, r, WithServerOnMessageFunc(func(c *Conn, o Opcode, b []byte) {
c.WriteMessage(o, b)
err := c.WriteMessage(o, b)
if err != nil {
t.Error(err)
return
}
c.Close()
}))
if err != nil {
Expand All @@ -328,7 +353,11 @@ func Test_ClientOption(t *testing.T) {
t.Error(err)
}

newConn.SetDeadline(time.Now().Add(30 * time.Second))
err = newConn.SetDeadline(time.Now().Add(30 * time.Second))
if err != nil {
t.Error(err)
return
}

buf := make([]byte, 128)
if _, err := io.ReadFull(newConn, buf[:3]); err != nil {
Expand Down Expand Up @@ -374,10 +403,18 @@ func Test_ClientOption(t *testing.T) {
defer c2.Close()
done := make(chan struct{})
go func() {
io.Copy(newConn, c2)
_, err = io.Copy(newConn, c2)
if err != nil {
t.Error(err)
return
}
close(done)
}()
io.Copy(c2, newConn)
_, err = io.Copy(c2, newConn)
if err != nil {
t.Error(err)
return
}
<-done
}()

Expand All @@ -394,8 +431,12 @@ func Test_ClientOption(t *testing.T) {
}

data := []byte("hello world")
c.WriteMessage(Binary, data)
c.ReadLoop()
err = c.WriteMessage(Binary, data)
if err != nil {
t.Error(err)
return
}
_ = c.ReadLoop()

t.Log("got", string(got), "want", string(data))
if !bytes.Equal(got, data) {
Expand Down
Loading

0 comments on commit 16e5cae

Please sign in to comment.