MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestServer_RateLimit_HandleMessage

Function TestServer_RateLimit_HandleMessage

pkg/lsp/server_ratelimit_test.go:164–199  ·  view source on GitHub ↗

TestServer_RateLimit_HandleMessage tests rate limiting in message handling

(t *testing.T)

Source from the content-addressed store, hash-verified

162
163// TestServer_RateLimit_HandleMessage tests rate limiting in message handling
164func TestServer_RateLimit_HandleMessage(t *testing.T) {
165 mock := newMockReadWriter()
166 logger := log.New(io.Discard, "", 0)
167 server := NewServer(mock.input, mock.output, logger)
168
169 // Create a valid request
170 req := Request{
171 JSONRPC: "2.0",
172 ID: 1,
173 Method: "shutdown",
174 }
175 msgBytes, err := json.Marshal(req)
176 if err != nil {
177 t.Fatalf("failed to marshal request: %v", err)
178 }
179
180 // Send requests up to the limit
181 for i := 0; i < RateLimitRequests; i++ {
182 server.handleMessage(msgBytes)
183 }
184
185 // Clear output buffer to check next response
186 mock.output.Reset()
187
188 // Next request should be rate limited
189 server.handleMessage(msgBytes)
190
191 // Check that a rate limit error response was sent
192 output := mock.output.String()
193 if output != "" {
194 // Rate limited requests should get an error response
195 if !contains(output, "RequestCancelled") && !contains(output, "rate limit") {
196 t.Logf("Output after rate limit: %s", output)
197 }
198 }
199}
200
201// TestServer_RateLimit_MultipleWindows tests behavior across multiple windows
202func TestServer_RateLimit_MultipleWindows(t *testing.T) {

Callers

nothing calls this directly

Calls 7

handleMessageMethod · 0.95
newMockReadWriterFunction · 0.85
NewServerFunction · 0.85
containsFunction · 0.70
FatalfMethod · 0.65
ResetMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected