MCPcopy Create free account
hub / github.com/microsoft/debugpy / test_fuzz

Method test_fuzz

tests/debugpy/common/test_messaging.py:508–658  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

506 ]
507
508 def test_fuzz(self):
509 # Set up two channels over the same stream that send messages to each other
510 # asynchronously, and record everything that they send and receive.
511 # All records should match at the end.
512
513 class Fuzzer(object):
514 def __init__(self, name):
515 self.name = name
516 self.lock = threading.Lock()
517 self.sent = []
518 self.received = []
519 self.responses_sent = []
520 self.responses_received = []
521 self.done = False
522
523 def start(self, channel):
524 self._worker = threading.Thread(
525 name=self.name,
526 target=lambda: self._send_requests_and_events(channel),
527 )
528 self._worker.daemon = True
529 self._worker.start()
530
531 def wait(self):
532 self._worker.join()
533
534 def done_event(self, event):
535 with self.lock:
536 self.done = True
537
538 def fizz_event(self, event):
539 assert event.event == "fizz"
540 with self.lock:
541 self.received.append(("event", "fizz", event.body))
542
543 def buzz_event(self, event):
544 assert event.event == "buzz"
545 with self.lock:
546 self.received.append(("event", "buzz", event.body))
547
548 def event(self, event):
549 with self.lock:
550 self.received.append(("event", event.event, event.body))
551
552 def make_and_log_response(self, request):
553 x = random.randint(-100, 100)
554 if x < 0:
555 exc_type = (
556 messaging.InvalidMessageError
557 if x % 2
558 else messaging.MessageHandlingError
559 )
560 x = exc_type(str(x), request)
561 with self.lock:
562 self.responses_sent.append((request.seq, x))
563 return x
564
565 def fizz_request(self, request):

Callers

nothing calls this directly

Calls 8

startMethod · 0.95
startMethod · 0.95
waitMethod · 0.95
FuzzerClass · 0.85
listenMethod · 0.80
connectMethod · 0.45
joinMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected