Commits

Ralf Schmitt committed 3866baf

test sendall with str, unicode and array

array fails, see http://code.google.com/p/gevent/issues/detail?id=94

  • Participants
  • Parent commits 4eace16

Comments (0)

Files changed (1)

File greentest/test__socket.py

 import os
 import sys
+import array
 import gevent
 from gevent import socket
 import greentest
 class TestTCP(greentest.TestCase):
 
     TIMEOUT_ERROR = socket.timeout
+    long_data = ", ".join([str(x) for x in range(20000)])
 
     def setUp(self):
         greentest.TestCase.setUp(self)
     def create_connection(self):
         return socket.create_connection(('127.0.0.1', self.listener.getsockname()[1]))
 
+    def sendall(self, data):
+        def accept_and_read():
+            conn, addr = self.listener.accept()
+            fd = conn.makefile()
+            conn.close()
+            read = fd.read()
+            fd.close()
+            return read
+
+        server = gevent.spawn(accept_and_read)
+        try:
+            client = self.create_connection()
+            client.sendall(data)
+            client.close()
+            read = server.get()
+            assert read == self.long_data
+        finally:
+            server.kill()
+
+    def test_sendall_str(self):
+        self.sendall(self.long_data)
+
+    def test_sendall_unicode(self):
+        self.sendall(unicode(self.long_data))
+
+    def test_sendall_array(self):
+        data = array.array("B", self.long_data)
+        self.sendall(data)
+
     def test_fullduplex(self):
 
         def server():