使用expresso和socket.io-client测试服务器,但测试过程没有停止
我想使用 socket.io-client 来测试我的 socket.io 服务器。我尝试使用以下文件运行expresso。数据打印在控制台中。然后该进程挂在那里,并且 beforeExit 永远不会执行,直到我使用 Ctrl-C 终止该进程。我想在服务器完成回调后,应该调用 beforeExit,然后进程停止。但事实并非如此,为什么呢?
var assert = require('assert');
exports.testAsync = function(beforeExit){
var io = require('socket.io-client');
var socket = io.connect('http://localhost:8000');
socket.on('connect', function(err) {
assert.isUndefined(err);
socket.emit('set nickname', 'apple', function(data) {
assert.equal(data, 'ok');
console.log(data);
});
});
beforeExit(function(){
console.log("exit");
socket.disconnect();
});
};
I wanna use socket.io-client to test my socket.io server. And I tried to run expresso with the following file. The data is printed in console. Then the process hangs there and beforeExit is never executed until I terminate the process with Ctrl-C. I suppose after the callback is done from the server, beforeExit should be called and then the process stops. But it is not like that, Why?
var assert = require('assert');
exports.testAsync = function(beforeExit){
var io = require('socket.io-client');
var socket = io.connect('http://localhost:8000');
socket.on('connect', function(err) {
assert.isUndefined(err);
socket.emit('set nickname', 'apple', function(data) {
assert.equal(data, 'ok');
console.log(data);
});
});
beforeExit(function(){
console.log("exit");
socket.disconnect();
});
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
奇怪的。我正在使用 Expresso 0.9.2,并且与您编写的代码完全相同,可以按预期工作。但当然,我没有运行任何服务器。
这是您的测试文件的全部内容吗?
Strange. I'm using Expresso 0.9.2 and exactly the same code you wrote works as expected. But of course, I don't have any server running.
Is this the entire content of your test file?