plow-technologies / servant-streaming

Support for servant requests and responses via the 'streaming' library
13 stars 3 forks source link

Adhoc test case for streaming a file #1

Closed domenkozar closed 6 years ago

domenkozar commented 6 years ago
Failures:                                                       

  test/Servant/Streaming/ServerSpec.hs:106:                
  1) Servant.Streaming.Server, StreamResponse instance, streams a 
huge file as response body                                               expected: "foobar"                     
        but got: ""     

In tests I don't see the output, but with an example serving the API I also see:

 hello.txt: hGetBufSome: illegal operation (handle is closed)

cc @jkarni this is a test case for what we discussed yesterday on #servant

domenkozar commented 6 years ago

Ah, had an issue in the test case, now it correctly reproduces:

hello.txt: hGetBufSome: illegal operation (handle is closed)
    streams a huge file as response body FAILED [1]

Failures:

  test/Servant/Streaming/ServerSpec.hs:100: 
  1) Servant.Streaming.Server, StreamResponse instance, streams a huge file as response body
       uncaught exception: HttpException (HttpExceptionRequest Request {
         host                 = "localhost"
         port                 = 33951
         secure               = False
         requestHeaders       = [("Content-Type","application/json")]
         path                 = "getfile"
         queryString          = ""
         method               = "POST"
         proxy                = Nothing
         rawBody              = False
         redirectCount        = 10
         responseTimeout      = ResponseTimeoutNone
         requestVersion       = HTTP/1.1
       }
        NoResponseDataReceived)
domenkozar commented 6 years ago

I've used @edsko snippet from https://github.com/haskell-servant/servant/issues/271#issuecomment-258079285 and tests pass locally.

(still need to make sure hello.txt gets deleted at the end of the test)

jkarni commented 6 years ago

Ah, I spent some time looking into this, but would not have thought of this solution. (I think I still don't have a good mental model for ResourceT). Thank you so much!

(There's a separate issue that's causing the CI failure that I'll fix)