MCPcopy Index your code
hub / github.com/python/cpython / _sock_operation

Method _sock_operation

Lib/test/test_timeout.py:114–134  ·  view source on GitHub ↗

Test the specified socket method. The method is run at most `count` times and must raise a TimeoutError within `timeout` + self.fuzz seconds.

(self, count, timeout, method, *args)

Source from the content-addressed store, hash-verified

112 raise NotImplementedError()
113
114 def _sock_operation(self, count, timeout, method, *args):
115 """
116 Test the specified socket method.
117
118 The method is run at most `count` times and must raise a TimeoutError
119 within `timeout` + self.fuzz seconds.
120 """
121 self.sock.settimeout(timeout)
122 method = getattr(self.sock, method)
123 for i in range(count):
124 t1 = time.monotonic()
125 try:
126 method(*args)
127 except TimeoutError as e:
128 delta = time.monotonic() - t1
129 break
130 else:
131 self.fail('TimeoutError was not raised')
132 # These checks should account for timing unprecision
133 self.assertLess(delta, timeout + self.fuzz)
134 self.assertGreater(delta, timeout - 1.0)
135
136
137class TCPTimeoutTestCase(TimeoutTestCase):

Callers 7

testConnectTimeoutMethod · 0.80
testRecvTimeoutMethod · 0.80
testAcceptTimeoutMethod · 0.80
testSendMethod · 0.80
testSendtoMethod · 0.80
testSendallMethod · 0.80
testRecvfromTimeoutMethod · 0.80

Calls 5

methodFunction · 0.85
assertGreaterMethod · 0.80
settimeoutMethod · 0.45
failMethod · 0.45
assertLessMethod · 0.45

Tested by

no test coverage detected