Skip to content

Commit

Permalink
tests: test-tls-client-econnreset
Browse files Browse the repository at this point in the history
Introduce a test for the tls client getting an error in the middle of
the stream. This found a couple of bugs which are fixed early in this
set of commits.

Aside: While writing this test I did something stupid.  I was trying to
pcall child.stdin.write with self being passed in being child.stdin.

I think I need to send a patch to libuv to have uv_write send back an
error instead of asserting so we can handle that more gracefully, easy
mistake to make.

Also increase logging around this test a bit.
  • Loading branch information
philips authored and Brandon Philips committed Aug 14, 2012
1 parent eaa46eb commit 1ac93de
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/test-tls-client-econnreset.lua
@@ -0,0 +1,65 @@
require('helper')
local fixture = require('./fixture-tls')
local childprocess = require('childprocess')
local os = require('os')
local tls = require('tls')
local timer = require('timer')

local args = {
's_server',
'-accept', fixture.commonPort,
'-key', 'fixtures/keys/agent1-key.pem',
'-cert', 'fixtures/keys/agent1-cert.pem',
}

local child = childprocess.spawn('openssl', args)
child:on('error', function(err)
p(err)
end)
child:on('exit', function(exit_status)
print('server exited')
end)
child:on('error', function(err)
p(err)
end)
child.stdout:on('data', function(data)
print('server: ' .. data)
end)
child.stderr:on('data', function(data)
print('server: ' .. data)
end)

interval = timer.setInterval(100, function()
local success, err = pcall(child.stdin.write, child.stdin, "Hello world")
end)

timer.setTimeout(200,function ()
local c
c = tls.connect({port = fixture.commonPort, host = '127.0.0.1'})
c:on('error', function(err)
print("got connection error")
p(err)
end)
c:on('closed', function()
print('got closed signal')
end)
c:on('data', function(data)
print('client got: ' .. data)
end)
c:on('end', function()
c:destroy()
end)
end)

timer.setTimeout(1000, function()
child:kill(9)
end)

timer.setTimeout(1010, function()
process.exit(0)
end)

process:on('error', function(err)
assert(false)
p(err)
end)

0 comments on commit 1ac93de

Please sign in to comment.