Anonymous avatar Anonymous committed 943f828

fixed test code so that tests don't fail occasionally because of inproper handling of the output port

Comments (0)

Files changed (2)

       (lambda (temp-file _)
         (stream-file temp-file sendfile))))
  
-   ;; (test-group "sendfile main interface"
-   ;;             (test "sendfile" mb-checksum (stream-mb-buffer)))
+   (test-group "sendfile main interface"
+               (test "sendfile" mb-checksum (stream-mb-buffer)))
 
-   ;; (test-group "forcing implementation"
+   (test-group "forcing implementation"
                
-   ;;             (parameterize ((force-implementation 'read-write))
-   ;;               (test "read-write" mb-checksum (stream-mb-buffer)))
+               (parameterize ((force-implementation 'read-write))
+                 (test "read-write" mb-checksum (stream-mb-buffer)))
 
-   ;;             (if sendfile-available
-   ;;                 (parameterize ((force-implementation 'sendfile))
-   ;;                   (test "sendfile(2)" mb-checksum (stream-mb-buffer))))
+               (if sendfile-available
+                   (parameterize ((force-implementation 'sendfile))
+                     (test "sendfile(2)" mb-checksum (stream-mb-buffer))))
 
-   ;;             (if mmap-available
-   ;;                 (parameterize ((force-implementation 'mmapped))
-   ;;                   (test "mmap(2)" mb-checksum (stream-mb-buffer))))
+               (if mmap-available
+                   (parameterize ((force-implementation 'mmapped))
+                     (test "mmap(2)" mb-checksum (stream-mb-buffer))))
 
-   ;;             (parameterize ((force-implementation 'read-write-port))
-   ;;               (test "read-write-port" mb-checksum (stream-mb-buffer))))
+               (parameterize ((force-implementation 'read-write-port))
+                 (test "read-write-port" mb-checksum (stream-mb-buffer))))
 
 
-   ;; (test-group "read-write variations"
+   (test-group "read-write variations"
                
-   ;;             (call-with-temporary-file/checksum
-   ;;              (generate-buffer (mebibytes 1))
-   ;;              (lambda (temp-file expected-checksum)
-   ;;                (test "ports only"
-   ;;                      expected-checksum
-   ;;                      (call-with-connection-to-server
-   ;;                       (lambda (server-in server-out)
-   ;;                         (write-content-size server-out (mebibytes 1))
-   ;;                         (call-with-input-file temp-file
-   ;;                           (lambda (file-in)
-   ;;                             (sendfile file-in server-out)))
-   ;;                         (read-checksum server-in)))))))
+               (call-with-temporary-file/checksum
+                (generate-buffer (mebibytes 1))
+                (lambda (temp-file expected-checksum)
+                  (test "ports only"
+                        expected-checksum
+                        (call-with-connection-to-server
+                         (lambda (server-in server-out)
+                           (write-content-size server-out (mebibytes 1))
+                           (call-with-input-file temp-file
+                             (lambda (file-in)
+                               (sendfile file-in server-out)))
+                           (close-output-port server-out)
+                           (read-checksum server-in)))))))
 
 
    (test-group "content chunking"
             (let ((input (open-input-string buffer)))
               (write-content-size server-out -1)
               (proc input server-out)
-              (flush-output server-out)
+              (close-output-port server-out)
               (read-checksum server-in)))))
 
         (define-syntax test-chunking
                         (lambda (server-in server-out)
                           (write-content-size server-out (kibibytes 1))
                           (sendfile (open-input-string buffer) server-out)
-                          (flush-output server-out)
+                          (close-output-port server-out)
                           (read-checksum server-in))))))
   
    

tests/test-helper.scm

     (let* ((header (read-line input)))
       (unless (eof-object? header)
         (let* ((bytes-following (string->number header))
-               (content (read-string (if (positive? bytes-following) bytes-following #f) input)))
+               (content (read-string (and (positive? bytes-following) bytes-following) input)))
           (display (buffer-checksum content) output)
           (newline output)
           (flush-output output))))))
 
 ;; access the running server
 (define (call-with-connection-to-server proc)
-  (parameterize ((tcp-read-timeout 60000))
+  (parameterize ((tcp-read-timeout 30000))
     (receive (input output) (tcp-connect "localhost" (server-port))
       (let ((result (proc input output)))
         (close-input-port input)
        (write-content-size server-output size)
        
        (streamer file-port server-output)
-       
-       (flush-output server-output)
+      
+       (close-output-port server-output)
        (read-checksum server-input)))))
 
 (define (write-content-size port size)
   (display size port)
-  (newline port))
+  (newline port)
+  (flush-output port))
 
 (define (read-checksum port)
   (read-line port))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.