Skip to content

Commit 01700c2

Browse files
committed
Update TestPingLoop to properly test handlePong
1 parent 580be67 commit 01700c2

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

client_handlers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ func handlePong(c *Client, m *Message) {
5656
select {
5757
case c.incomingPongChan <- m.Trailing():
5858
default:
59+
// Note that this return isn't really needed, but it helps some code
60+
// coverage tools actually see this line.
61+
return
5962
}
6063
}
6164
}

client_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -388,20 +388,14 @@ func TestPingLoop(t *testing.T) {
388388

389389
// This one is just for coverage, so we know we're hitting the
390390
// branch that drops extra pings.
391-
runClientTest(t, config, io.EOF, nil, []TestAction{
391+
runClientTest(t, config, io.EOF, func(c *Client) {
392+
c.incomingPongChan = make(chan string)
393+
handlePong(c, MustParseMessage("PONG :hello 1"))
394+
}, []TestAction{
392395
ExpectLine("PASS :test_pass\r\n"),
393396
ExpectLine("NICK :test_nick\r\n"),
394397
ExpectLine("USER test_user 0.0.0.0 0.0.0.0 :test_name\r\n"),
395398
SendLine("001 :hello_world\r\n"),
396-
397-
// It's a buffered channel of 5, so we want to send at least 6 of them
398-
SendLine("PONG :hello 1\r\n"),
399-
SendLine("PONG :hello 2\r\n"),
400-
SendLine("PONG :hello 3\r\n"),
401-
SendLine("PONG :hello 4\r\n"),
402-
SendLine("PONG :hello 5\r\n"),
403-
SendLine("PONG :hello 6\r\n"),
404-
SendLine("PONG :hello 7\r\n"),
405399
})
406400

407401
// Successful ping with write error

0 commit comments

Comments
 (0)