@@ -8,6 +8,12 @@ import (
8
8
"time"
9
9
)
10
10
11
+ // TestProtocol_Connect verifies the basic connection functionality of the Protocol.
12
+ // This is a critical test as connection establishment is required for all other operations.
13
+ // It ensures that:
14
+ // 1. The protocol can successfully connect to a transport
15
+ // 2. The message handler is properly registered with the transport
16
+ // 3. The protocol is ready to send and receive messages after connection
11
17
func TestProtocol_Connect (t * testing.T ) {
12
18
p := NewProtocol (nil )
13
19
transport := newMockTransport ()
@@ -21,6 +27,13 @@ func TestProtocol_Connect(t *testing.T) {
21
27
}
22
28
}
23
29
30
+ // TestProtocol_Close tests the proper cleanup of resources when closing the protocol.
31
+ // Proper cleanup is essential to prevent resource leaks and ensure graceful shutdown.
32
+ // It verifies:
33
+ // 1. All handlers are properly deregistered
34
+ // 2. The transport is closed
35
+ // 3. No messages can be sent after closing
36
+ // 4. Multiple closes are handled safely
24
37
func TestProtocol_Close (t * testing.T ) {
25
38
p := NewProtocol (nil )
26
39
transport := newMockTransport ()
@@ -47,6 +60,14 @@ func TestProtocol_Close(t *testing.T) {
47
60
}
48
61
}
49
62
63
+ // TestProtocol_Request tests the core request-response functionality of the protocol.
64
+ // This is the most important test as it covers the primary use case of the protocol.
65
+ // It includes subtests for:
66
+ // 1. Successful request/response with proper correlation
67
+ // 2. Request timeout handling
68
+ // 3. Request cancellation via context
69
+ // These scenarios ensure the protocol can handle both successful and error cases
70
+ // while maintaining proper message correlation and resource cleanup.
50
71
func TestProtocol_Request (t * testing.T ) {
51
72
p := NewProtocol (nil )
52
73
transport := newMockTransport ()
@@ -121,6 +142,12 @@ func TestProtocol_Request(t *testing.T) {
121
142
})
122
143
}
123
144
145
+ // TestProtocol_Notification tests the handling of one-way notifications.
146
+ // Notifications are important for events that don't require responses.
147
+ // The test verifies:
148
+ // 1. Notifications can be sent successfully
149
+ // 2. The transport receives the correct notification format
150
+ // 3. No response handling is attempted for notifications
124
151
func TestProtocol_Notification (t * testing.T ) {
125
152
p := NewProtocol (nil )
126
153
transport := newMockTransport ()
@@ -150,6 +177,13 @@ func TestProtocol_Notification(t *testing.T) {
150
177
}
151
178
}
152
179
180
+ // TestProtocol_RequestHandler tests the registration and invocation of request handlers.
181
+ // Request handlers are crucial for servers implementing RPC methods.
182
+ // It ensures:
183
+ // 1. Handlers can be registered for specific methods
184
+ // 2. Handlers receive the correct request parameters
185
+ // 3. Handler responses are properly sent back to clients
186
+ // 4. Handler errors are properly propagated
153
187
func TestProtocol_RequestHandler (t * testing.T ) {
154
188
p := NewProtocol (nil )
155
189
transport := newMockTransport ()
@@ -195,6 +229,13 @@ func TestProtocol_RequestHandler(t *testing.T) {
195
229
}
196
230
}
197
231
232
+ // TestProtocol_NotificationHandler tests the handling of incoming notifications.
233
+ // This is important for asynchronous events and status updates.
234
+ // It verifies:
235
+ // 1. Notification handlers can be registered
236
+ // 2. Handlers are called with correct notification data
237
+ // 3. Multiple handlers can be registered for different methods
238
+ // 4. Unknown notifications are handled gracefully
198
239
func TestProtocol_NotificationHandler (t * testing.T ) {
199
240
p := NewProtocol (nil )
200
241
transport := newMockTransport ()
@@ -224,6 +265,13 @@ func TestProtocol_NotificationHandler(t *testing.T) {
224
265
}
225
266
}
226
267
268
+ // TestProtocol_Progress tests the progress tracking functionality.
269
+ // Progress tracking is essential for long-running operations.
270
+ // The test covers:
271
+ // 1. Progress notifications can be sent and received
272
+ // 2. Progress tokens are properly correlated with requests
273
+ // 3. Progress callbacks are invoked with correct values
274
+ // 4. Progress handling works alongside normal request processing
227
275
func TestProtocol_Progress (t * testing.T ) {
228
276
p := NewProtocol (nil )
229
277
transport := newMockTransport ()
@@ -295,6 +343,13 @@ func TestProtocol_Progress(t *testing.T) {
295
343
}
296
344
}
297
345
346
+ // TestProtocol_ErrorHandling tests various error conditions in the protocol.
347
+ // Proper error handling is crucial for reliability and debugging.
348
+ // It verifies:
349
+ // 1. Transport errors are properly propagated
350
+ // 2. Protocol-level errors are handled correctly
351
+ // 3. Error responses include appropriate error codes and messages
352
+ // 4. Resources are cleaned up after errors
298
353
func TestProtocol_ErrorHandling (t * testing.T ) {
299
354
p := NewProtocol (nil )
300
355
transport := newMockTransport ()
0 commit comments