@@ -1374,7 +1374,7 @@ def handle_error(self):
13741374@unittest .skipUnless (hasattr (os , 'sendfile' ), "test needs os.sendfile()" )
13751375class TestSendfile (unittest .TestCase ):
13761376
1377- DATA = b"12345abcde" * 1024 * 1024 # 10 Mb
1377+ DATA = b"12345abcde" * 16 * 1024 # 160 KB
13781378 SUPPORT_HEADERS_TRAILERS = not sys .platform .startswith ("linux" ) and \
13791379 not sys .platform .startswith ("solaris" ) and \
13801380 not sys .platform .startswith ("sunos" )
@@ -1432,7 +1432,7 @@ def test_send_whole_file(self):
14321432 total_sent = 0
14331433 offset = 0
14341434 nbytes = 4096
1435- while 1 :
1435+ while total_sent < len ( self . DATA ) :
14361436 sent = self .sendfile_wrapper (self .sockno , self .fileno , offset , nbytes )
14371437 if sent == 0 :
14381438 break
@@ -1445,14 +1445,15 @@ def test_send_whole_file(self):
14451445 self .client .close ()
14461446 self .server .wait ()
14471447 data = self .server .handler_instance .get_data ()
1448- self .assertEqual (hash ( data ), hash ( self .DATA ) )
1448+ self .assertEqual (data , self .DATA )
14491449
14501450 def test_send_at_certain_offset (self ):
14511451 # start sending a file at a certain offset
14521452 total_sent = 0
1453- offset = len (self .DATA ) / 2
1453+ offset = len (self .DATA ) // 2
1454+ must_send = len (self .DATA ) - offset
14541455 nbytes = 4096
1455- while 1 :
1456+ while total_sent < must_send :
14561457 sent = self .sendfile_wrapper (self .sockno , self .fileno , offset , nbytes )
14571458 if sent == 0 :
14581459 break
@@ -1463,15 +1464,21 @@ def test_send_at_certain_offset(self):
14631464 self .client .close ()
14641465 self .server .wait ()
14651466 data = self .server .handler_instance .get_data ()
1466- expected = self .DATA [int ( len (self .DATA ) / 2 ) :]
1467+ expected = self .DATA [len (self .DATA ) // 2 :]
14671468 self .assertEqual (total_sent , len (expected ))
1468- self .assertEqual (hash ( data ), hash ( expected ) )
1469+ self .assertEqual (data , expected )
14691470
14701471 def test_offset_overflow (self ):
14711472 # specify an offset > file size
14721473 offset = len (self .DATA ) + 4096
1473- sent = os .sendfile (self .sockno , self .fileno , offset , 4096 )
1474- self .assertEqual (sent , 0 )
1474+ try :
1475+ sent = os .sendfile (self .sockno , self .fileno , offset , 4096 )
1476+ except OSError as e :
1477+ # Solaris can raise EINVAL if offset >= file length, ignore.
1478+ if e .errno != errno .EINVAL :
1479+ raise
1480+ else :
1481+ self .assertEqual (sent , 0 )
14751482 self .client .close ()
14761483 self .server .wait ()
14771484 data = self .server .handler_instance .get_data ()
0 commit comments