Commits

David Krentzlin committed 79bac89

added regression test for the bug that made sendfile fail for files > 1 mebibyte

  • Participants
  • Parent commits 171cbc7

Comments (0)

Files changed (2)

File tests/run2.scm

 
 
 (with-running-server
+
+ (let* ((mb-buffer (generate-buffer (mebibytes 1)))
+        (mb-checksum (buffer-checksum mb-buffer)))
  
- (test-group "sendfile main interface"
+   (test-group "sendfile main interface"
+               (test "sendfile"
+                     mb-checksum
+                     (call-with-temporary-file/checksum
+                      mb-buffer
+                      (lambda (temp-file _)
+                        (stream-file temp-file sendfile)))))
 
-             (call-with-temporary-file/checksum
-              (generate-buffer (mibibytes 1))
-              (lambda (temp-file expected-checksum)
+   (test-group "regression"               
+               (call-with-buffer/checksum
+                (kibibytes 1)
+                (lambda (buffer checksum)
+                  (test "custom input port without fd [bug #542]"
+                        checksum
+                        (call-with-connection-to-server
+                         (lambda (server-in server-out)
+                           (write-content-size server-out (kibibytes 1))
+                           (sendfile (open-input-string buffer) server-out)
+                           (read-checksum server-in))))))
+   
+    
+               (call-with-temporary-file/checksum
+                (generate-buffer (mebibytes 2))
+                (lambda (temp-file expected-checksum)
+                  (test "send files > 1 mibibyte"
+                        expected-checksum
+                        (stream-file temp-file sendfile)))))))
 
-                (test "sendfile"
-                      expected-checksum
-                      (stream-file temp-file sendfile)))))
-
- (test-group "regression")
-
- )
-

File tests/test-helper.scm

         (close-output-port output)
         result))))
 
+
 (define (stream-file path streamer)
   (let ((size (file-size path))
         (file-port (file-open path (bitwise-ior open/rdonly open/binary))))
     (call-with-connection-to-server
      (lambda (server-input server-output)
-       (display size server-output)
-       (newline server-output)
+       (write-content-size server-output size)
        
        (streamer file-port server-output)
        
        (flush-output server-output)
-       (read-line server-input)))))
+       (read-checksum server-input)))))
+
+(define (write-content-size port size)
+  (display size port)
+  (newline port))
+
+(define (read-checksum port)
+  (read-line port))
 
 ;generate a string of bytes bytes
 (define (call-with-buffer bytes proc)
 
 
 
-(define (mibibytes amount)
+(define (mebibytes amount)
   (* amount (kibibytes 1024)))
 
 (define (kibibytes amount)