diff --git a/spec/h2_stream_spec.lua b/spec/h2_stream_spec.lua index 1cfed79..8901698 100644 --- a/spec/h2_stream_spec.lua +++ b/spec/h2_stream_spec.lua @@ -5,6 +5,7 @@ describe("http.h2_stream", function() local cqueues = require "cqueues" local ca = require "cqueues.auxlib" local cs = require "cqueues.socket" + local cc = require "cqueues.condition" local function new_pair() local s, c = ca.assert(cs.pair()) s = assert(h2_connection.new(s, "server")) @@ -265,4 +266,27 @@ describe("http.h2_stream", function() assert.truthy(cq:empty()) end) end) + it("errors when a server sends goaway before a stream is opened", function() + local s, c = new_pair() + local cq = cqueues.new() + local cond = cc.new() + local req_headers = new_headers() + req_headers:append(":method", "GET") + req_headers:append(":scheme", "http") + req_headers:append(":path", "/") + cq:wrap(function() + assert(cond:wait()) + local stream = c:new_stream() + assert.falsy(stream) + end) + cq:wrap(function() + -- ensure client coroutine runs first + cqueues.sleep(0.1) + assert(s:write_goaway_frame(nil,h2_error.errors.INTERNAL_ERROR.code)) + cond:signal(1) + end) + assert_loop(cq, TEST_TIMEOUT) + s:close() + c:close() + end) end)