Skip to content

Commit 21772fc

Browse files
committed
test: enable core client test cases and verify io.EOF reconnection
- Uncommented and verified core client test cases in `core/cln/client_test.go`, including `SendSuccess`, `Has`, `Forget`, and multi-command scenarios. - Added `ReconnectOnEOFTestCase` to `test/core/cases_client.go` to verify reconnection logic when the client receives an `io.EOF`.
1 parent 264befc commit 21772fc

3 files changed

Lines changed: 47 additions & 15 deletions

File tree

core/cln/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ Start:
295295
err := client.receive(ctx)
296296
if err != nil {
297297
err = client.correctErr(err)
298-
if _, ok := err.(net.Error); ok || err == io.EOF { // TODO Test EOF.
298+
if _, ok := err.(net.Error); ok || err == io.EOF {
299299
if reconnectDelegate, ok := client.delegate.(core.ReconnectDelegate[T]); ok {
300300
if err = reconnectDelegate.Reconnect(); err == nil {
301301
goto Start

core/cln/client_test.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
func TestInit(t *testing.T) {
1010
for _, tc := range []test.ClientTestCase[any]{
1111
test.ReconnectTestCase(),
12+
test.ReconnectOnEOFTestCase(),
1213
test.NoReconnectOnCloseTestCase(),
1314
test.ReconnectFailTestCase(),
1415
test.KeepaliveTestCase(),
@@ -18,22 +19,22 @@ func TestInit(t *testing.T) {
1819
}
1920

2021
func TestSend(t *testing.T) {
21-
// for _, tc := range []test.ClientTestCase[any]{
22-
// test.SendSuccessTestCase(),
23-
// test.HasTestCase(),
24-
// test.ForgetTestCase(),
25-
// test.ForgetOnFailTestCase(),
26-
// test.ClosedOnReceiveErrorTestCase(),
27-
// } {
28-
// test.RunClientTestCase(t, tc)
29-
// }
22+
for _, tc := range []test.ClientTestCase[any]{
23+
test.SendSuccessTestCase(),
24+
test.HasTestCase(),
25+
test.ForgetTestCase(),
26+
test.ForgetOnFailTestCase(),
27+
test.ClosedOnReceiveErrorTestCase(),
28+
} {
29+
test.RunClientTestCase(t, tc)
30+
}
3031

3132
for _, tc := range []test.MultiSendTestCase[any]{
32-
// test.MultiSuccessTestCase(),
33-
// test.IncrementSeqTestCase(),
34-
// test.MultiResultSuccessTestCase(),
35-
// test.PartialResultsTestCase(),
36-
// test.IncrementSeqAfterFailTestCase(),
33+
test.MultiSuccessTestCase(),
34+
test.IncrementSeqTestCase(),
35+
test.MultiResultSuccessTestCase(),
36+
test.PartialResultsTestCase(),
37+
test.IncrementSeqAfterFailTestCase(),
3738
test.ErrForAllCmdsOnFlushFailTestCase(),
3839
} {
3940
test.RunMultiSendTestCase(t, tc)

test/core/cases_client.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package core
22

33
import (
44
"errors"
5+
"io"
56
"net"
67
"sync"
78
"testing"
@@ -45,6 +46,36 @@ func ReconnectTestCase() ClientTestCase[any] {
4546

4647
// -----------------------------------------------------------------------------
4748

49+
func ReconnectOnEOFTestCase() ClientTestCase[any] {
50+
name := "If the client received EOF it should try to reconnect"
51+
52+
var delegate = mock.NewReconnectDelegate()
53+
54+
delegate.RegisterReceive(
55+
func() (seq core.Seq, result core.Result, n int, err error) {
56+
return 0, nil, 0, io.EOF
57+
},
58+
).RegisterReconnect(
59+
func() error { return nil },
60+
).RegisterReceive(
61+
func() (seq core.Seq, result core.Result, n int, err error) {
62+
return 0, nil, 0, errors.New("receive error")
63+
},
64+
).RegisterClose(
65+
func() (err error) { return nil },
66+
)
67+
return ClientTestCase[any]{
68+
Name: name,
69+
Setup: ClientSetup[any]{
70+
Delegate: delegate,
71+
Opts: []cln.SetOption{},
72+
},
73+
Mocks: []*mok.Mock{delegate.Mock},
74+
}
75+
}
76+
77+
// -----------------------------------------------------------------------------
78+
4879
func NoReconnectOnCloseTestCase() ClientTestCase[any] {
4980
name := "If the client is closed it should not reconnect"
5081

0 commit comments

Comments
 (0)