sockit-to-me
Advanced tools
Comparing version 0.2.1 to 0.2.2
{ | ||
"name": "sockit-to-me", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"author": "Ghislain 'Aus' Lacroix <aus@mozilla.com>", | ||
@@ -5,0 +5,0 @@ "description": "A synchronous socket API for node.js.", |
@@ -21,5 +21,9 @@ var assert = require('assert'); | ||
var subject = null; | ||
// global flag set to true if we kill the server | ||
// needed for the close / disconnect | ||
var server_killed = false; | ||
setup(function(done) { | ||
subject = new Sockit.Sockit(); | ||
server_killed = false; | ||
// Start the child process. | ||
@@ -42,15 +46,19 @@ server = ChildProcess.fork(__dirname + '/../test_support/server.js'); | ||
subject.close(); | ||
// Register listener to shutdown child process once the server has | ||
// successfully closed it's listening socket. | ||
server.on('message', function(message) { | ||
// Server has actually stopped. | ||
if(message.reply == 'stopped') { | ||
// Disconnect child process. | ||
server.disconnect(); | ||
// Teardown complete. | ||
done(); | ||
} | ||
}); | ||
// Ask server to stop. | ||
server.send({ command: 'stop' }); | ||
if (!server_killed) { | ||
// Register listener to shutdown child process once the server has | ||
// successfully closed it's listening socket. | ||
server.on('message', function(message) { | ||
// Server has actually stopped. | ||
if(message.reply == 'stopped') { | ||
// Disconnect child process. | ||
server.disconnect(); | ||
// Teardown complete. | ||
done(); | ||
} | ||
}); | ||
// Ask server to stop. | ||
server.send({ command: 'stop' }); | ||
} else { | ||
done(); | ||
} | ||
}); | ||
@@ -214,2 +222,33 @@ | ||
test('socket closing', function(done) { | ||
subject.setPollTimeout(1000); | ||
// Register a listener to ensure that the server really is ready | ||
server.on('message', function(message) { | ||
// Connected, ask server to send NOTHING. | ||
if(message.reply == 'connected') { | ||
var err; | ||
server.kill('SIGKILL'); | ||
server_killed = true; | ||
try { | ||
// Read the response. | ||
var response = subject.read(helo.length); | ||
} | ||
catch(e) { | ||
err = e; | ||
} | ||
assert.ok(err instanceof Error); | ||
done(); | ||
} | ||
}) | ||
// Connect to server. | ||
subject.connect({ host: host, port: port }); | ||
}); | ||
}); | ||
@@ -216,0 +255,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
197526
403