Naming, layout and comments: descriptive full-word names, one item per line in wrapped calls and literals, and doc comments on exported names

Short and single-letter names in application code become full words (tests
keep theirs). Wrapped calls, signatures and composite literals put one item
per line, and one-line function bodies are expanded. Exported names and
groups of constants get doc comments, and comments refer to the renamed
identifiers.
This commit is contained in:
bwilliams committed 2026-10-15 16:12:56 +01:00
1 parent 043e307663
commit 465358609a
78 files changed
+2374 -1402

No files matched your search

+42 -12
View File
@@ -69,8 +69,14 @@ func dialTCP(t *testing.T, addr string) *tcpClient {
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { conn.Close() })
return &tcpClient{t: t, conn: conn, r: bufio.NewReader(conn)}
t.Cleanup(func() {
conn.Close()
})
return &tcpClient{
t: t,
conn: conn,
r: bufio.NewReader(conn),
}
}
func (c *tcpClient) send(line string) {
@@ -155,7 +161,9 @@ func TestTCPMessages(t *testing.T) {
// With no write timeout, messages are still sent: a zero timeout must not
// mean one that has already expired.
func TestTCPNoWriteTimeout(t *testing.T) {
_, addr := tcpHub(t, func(c *config.JSCServerWebSocket) { c.WriteTimeout = 0 })
_, addr := tcpHub(t, func(c *config.JSCServerWebSocket) {
c.WriteTimeout = 0
})
c := dialTCP(t, addr)
if e := c.read(); e.Type != TypeWelcome {
t.Fatalf("want welcome, got %+v", e)
@@ -177,7 +185,9 @@ func TestTCPClientDisconnect(t *testing.T) {
// A line longer than max_message_size drops the connection.
func TestTCPLineTooLong(t *testing.T) {
h, addr := tcpHub(t, func(c *config.JSCServerWebSocket) { c.MaxMessageSize = 64 })
h, addr := tcpHub(t, func(c *config.JSCServerWebSocket) {
c.MaxMessageSize = 64
})
c := dialTCP(t, addr)
c.read() // welcome
c.send(`{"type":"echo","payload":"` + strings.Repeat("x", 100) + `"}` + "\n")
@@ -244,12 +254,21 @@ func TestTCPPing(t *testing.T) {
// full. net.Pipe has no buffer, so writes to it block until the peer reads.
func TestTCPSlowConsumer(t *testing.T) {
h := NewHub(
config.JSCServerWebSocket{WriteTimeout: 50 * time.Millisecond}, WithLogger(discardLog),
config.JSCServerWebSocket{
WriteTimeout: 50 * time.Millisecond,
},
WithLogger(discardLog),
)
server, peer := net.Pipe()
t.Cleanup(func() { server.Close(); peer.Close() })
t.Cleanup(func() {
server.Close()
peer.Close()
})
done := make(chan struct{})
go func() { h.ServeTCP(context.Background(), server); close(done) }()
go func() {
h.ServeTCP(context.Background(), server)
close(done)
}()
waitCount(t, h, 1)
for range clientSendBuffer + 1 {
@@ -283,7 +302,9 @@ func TestTCPNoPongTimeout(t *testing.T) {
// A max_message_size of 0 uses the default limit.
func TestTCPDefaultMessageSize(t *testing.T) {
_, addr := tcpHub(t, func(c *config.JSCServerWebSocket) { c.MaxMessageSize = 0 })
_, addr := tcpHub(t, func(c *config.JSCServerWebSocket) {
c.MaxMessageSize = 0
})
c := dialTCP(t, addr)
c.read() // welcome
c.send(`{"type":"echo","id":"1","payload":"` + strings.Repeat("x", 4096) + `"}` + "\n")
@@ -299,7 +320,10 @@ func TestTCPDefaultMessageSize(t *testing.T) {
func pipeConn(t *testing.T, closeTimeout time.Duration) (*tcpConn, net.Conn) {
t.Helper()
server, peer := net.Pipe()
t.Cleanup(func() { server.Close(); peer.Close() })
t.Cleanup(func() {
server.Close()
peer.Close()
})
return newTCPConn(server, 0, closeTimeout), peer
}
@@ -370,13 +394,17 @@ func TestTCPConnClose(t *testing.T) {
func TestTCPConnCloseNowDuringClose(t *testing.T) {
tc, _ := pipeConn(t, 0) // no timeout: Close would wait for ever
closed := make(chan error, 1)
go func() { closed <- tc.Close(ws.StatusGoingAway, "bye") }()
go func() {
closed <- tc.Close(ws.StatusGoingAway, "bye")
}()
for !tc.isClosed() {
time.Sleep(time.Millisecond)
}
done := make(chan error, 1)
go func() { done <- tc.CloseNow() }()
go func() {
done <- tc.CloseNow()
}()
select {
case err := <-done:
if err != nil {
@@ -396,7 +424,9 @@ func TestTCPConnCloseNowDuringClose(t *testing.T) {
func TestTCPConnCloseTimeout(t *testing.T) {
tc, _ := pipeConn(t, 20*time.Millisecond)
done := make(chan error, 1)
go func() { done <- tc.Close(ws.StatusGoingAway, "bye") }()
go func() {
done <- tc.Close(ws.StatusGoingAway, "bye")
}()
select {
case err := <-done:
if err != nil {