[英]vows unit test got executed multiple times when the included app server uses nodejs cluster.fork
我的应用服务器使用node.js群集API cluster.fork()派生多个子进程。 这很好。
但是,当我尝试使用誓言进行单元测试时,由于对我的应用服务器内部的cluster.fork()的调用,该测试也多次运行。 当我在测试代码中实例化服务器时,如下所示:
basic-test.js
var vows = require('vows');
var MyAppServer = require('../my_app');
// start the server
var app = MyAppServer.start();
var suite = vows.describe('My Tests');
suite.discuss('connections API')
.addBatch({ ... })
.export(module);
在这种情况下,如何防止测试代码多次运行? 该测试包含在npm测试中,因此我需要一种在测试本身内部实例化我的应用服务器的方法。
在顶部,你可以做
var cluster = require('cluster');
然后将套件包装在if
:
if (cluster.isMaster) {
var suite = ...
...
}
有关isMaster
更多信息,请查看文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.