[英]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.