@@ -37,70 +37,6 @@ import (
37
37
"github.com/ethereum/go-ethereum/log"
38
38
)
39
39
40
- // unsubscribeBlocker will wait for the quit channel to process an unsubscribe
41
- // request.
42
- type unsubscribeBlocker struct {
43
- ServerCodec
44
- quit chan struct {}
45
- }
46
-
47
- func (b * unsubscribeBlocker ) readBatch () ([]* jsonrpcMessage , bool , error ) {
48
- msgs , batch , err := b .ServerCodec .readBatch ()
49
- for _ , msg := range msgs {
50
- if msg .isUnsubscribe () {
51
- <- b .quit
52
- }
53
- }
54
- return msgs , batch , err
55
- }
56
-
57
- // TestUnsubscribeTimeout verifies that calling the client's Unsubscribe
58
- // function will eventually timeout and not block forever in case the serve does
59
- // not respond.
60
- // It reproducers the issue https://github.com/ethereum/go-ethereum/issues/30156
61
- func TestUnsubscribeTimeout (t * testing.T ) {
62
- srv := NewServer ()
63
- srv .RegisterName ("nftest" , new (notificationTestService ))
64
-
65
- // Setup middleware to block on unsubscribe.
66
- p1 , p2 := net .Pipe ()
67
- blocker := & unsubscribeBlocker {ServerCodec : NewCodec (p1 ), quit : make (chan struct {})}
68
- defer close (blocker .quit )
69
-
70
- // Serve the middleware.
71
- go srv .ServeCodec (blocker , OptionMethodInvocation | OptionSubscriptions )
72
- defer srv .Stop ()
73
-
74
- // Create the client on the other end of the pipe.
75
- cfg := new (clientConfig )
76
- client , _ := newClient (context .Background (), cfg , func (context.Context ) (ServerCodec , error ) {
77
- return NewCodec (p2 ), nil
78
- })
79
- defer client .Close ()
80
-
81
- // Start subscription.
82
- sub , err := client .Subscribe (context .Background (), "nftest" , make (chan int ), "someSubscription" , 1 , 1 )
83
- if err != nil {
84
- t .Fatalf ("failed to subscribe: %v" , err )
85
- }
86
-
87
- // Now on a separate thread, attempt to unsubscribe. Since the middleware
88
- // won't return, the function will only return if it times out on the request.
89
- done := make (chan struct {})
90
- go func () {
91
- sub .Unsubscribe ()
92
- done <- struct {}{}
93
- }()
94
-
95
- // Wait for the timeout. If the expected time for the timeout elapses, the
96
- // test is considered failed.
97
- select {
98
- case <- done :
99
- case <- time .After (10 * time .Second + 50 * time .Millisecond ):
100
- t .Fatalf ("Unsubscribe did not return within %s" , "10" )
101
- }
102
- }
103
-
104
40
func TestClientRequest (t * testing.T ) {
105
41
server := newTestServer ()
106
42
defer server .Stop ()
0 commit comments