在完成所有测试之前,摩卡结束测试运行

时间:2016-04-15 17:42:04

标签: javascript node.js jenkins mocha xunit

我目前在使用Jenkins的CI流程中工作,触发针对nodejs服务器后端的mocha测试。

对于一些reasong xunit测试记者没有与詹金斯合作。 test-resul.xml是空的,工作仍然失败。我们能够通过运行来实现它:

npm install mocha-jenkins-reporter

在测试触发之前,如下所示:

JUNIT_REPORT_PATH=test_report.xml JUNIT_REPORT_STACK=1 NODE_ENV=test node ./node_modules/.bin/mocha --globals * --reporter mocha-jenkins-reporter --no-colors

现在我得到了部分结果,因为某些原因并非所有测试都在运行。他们停在测试套件的中间,没有任何通知或错误消息。我还注意到生成的xml缺少关闭标记的根元素。我通过运行来解决这个问题:

echo '</testsuites>' >> test-result.xml

除此之外,我还注意到在测试执行期间内存消耗激增。 这是npm安装输出,这一步是这项工作的第一步:

+ npm -v
3.8.6
+ npm install
npm WARN deprecated sequelize@3.14.2: security/injection issue with limit/offset fixed in 3.17.0
npm WARN deprecated lodash@0.9.2: Grunt needs your help! See https://github.com/gruntjs/grunt/issues/1403.
npm WARN deprecated graceful-fs@1.2.3: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.
npm WARN deprecated jade@0.26.3: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated graceful-fs@2.0.3: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.

> ws@0.6.5 install /home/jenkins/workspace/Rufus_Test_DEV/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)


> actionhero@10.0.3 postinstall /home/jenkins/workspace/Rufus_Test_DEV
> echo 'To generate a new actionhero project, run "node ./node_modules/.bin/actionhero generate"'

To generate a new actionhero project, run "node ./node_modules/.bin/actionhero generate"
actionhero@10.0.3 /home/jenkins/workspace/Rufus_Test_DEV
+-- async@0.9.2 
+-- aws-sdk@2.3.3 
| +-- jmespath@0.15.0 
| +-- sax@1.1.5 
| +-- xml2js@0.4.15 
| `-- xmlbuilder@2.6.2 
|   `-- lodash@3.5.0 
+-- bcrypt-nodejs@0.0.3 
+-- blanket@1.2.3 
| +-- acorn@1.2.2 
| +-- falafel@1.2.0 
| +-- foreach@2.0.5 
| +-- isarray@0.0.1 
| +-- object-keys@1.0.9 
| `-- xtend@4.0.1 
+-- braintree@1.37.1 
| +-- dateformat@1.0.1-1.2.3 
| +-- depd@1.1.0 
| +-- readable-stream@1.1.10 
| | +-- core-util-is@1.0.2 
| | +-- debuglog@0.0.2 
| | `-- string_decoder@0.10.31 
| +-- semver@5.1.0 
| +-- source-map-support@0.2.9 
| | `-- source-map@0.1.32 
| +-- underscore@1.3.1 
| `-- xml2js@0.1.13 
+-- browser_fingerprint@0.0.6 
+-- circular-json@0.1.6 
| `-- wru@0.2.7 
+-- coveralls@2.11.9 
| +-- js-yaml@3.0.1 
| | +-- argparse@0.1.16 
| | | +-- underscore@1.7.0 
| | | `-- underscore.string@2.4.0 
| | `-- esprima@1.0.4 
| +-- lcov-parse@0.0.6 
| +-- log-driver@1.2.4 
| +-- minimist@1.2.0 
| `-- request@2.67.0 
|   +-- bl@1.0.3 
|   | `-- readable-stream@2.0.6 
|   |   `-- isarray@1.0.0 
|   `-- qs@5.2.0 
+-- easy-table@0.3.0 
+-- emailjs@1.0.4 
| +-- addressparser@0.3.2 
| +-- bufferjs@1.1.0 
| +-- mimelib@0.2.14 
| | +-- addressparser@0.2.1 
| | `-- encoding@0.1.12 
| |   `-- iconv-lite@0.4.13 
| +-- moment@2.11.2 
| `-- starttls@1.0.1 
+-- fakeredis@0.3.4 
| `-- redis@2.1.0 
+-- formidable@1.0.17 
+-- geolib@2.0.20 
+-- grunt@0.4.5 
| +-- async@0.1.22 
| +-- coffee-script@1.3.3 
| +-- colors@0.6.2 
| +-- dateformat@1.0.2-1.2.3 
| +-- eventemitter2@0.4.14 
| +-- exit@0.1.2 
| +-- findup-sync@0.1.3 
| | +-- glob@3.2.11 
| | | `-- minimatch@0.3.0 
| | `-- lodash@2.4.2 
| +-- getobject@0.1.0 
| +-- glob@3.1.21 
| | +-- graceful-fs@1.2.3 
| | `-- inherits@1.0.2 
| +-- grunt-legacy-log@0.1.3 
| | +-- grunt-legacy-log-utils@0.1.1 
| | | +-- lodash@2.4.2 
| | | `-- underscore.string@2.3.3 
| | +-- lodash@2.4.2 
| | `-- underscore.string@2.3.3 
| +-- grunt-legacy-util@0.2.0 
| | +-- async@0.1.22 
| | `-- lodash@0.9.2 
| +-- hooker@0.2.3 
| +-- iconv-lite@0.2.11 
| +-- js-yaml@2.0.5 
| +-- lodash@0.9.2 
| +-- minimatch@0.2.14 
| | +-- lru-cache@2.7.3 
| | `-- sigmund@1.0.1 
| +-- nopt@1.0.10 
| | `-- abbrev@1.0.7 
| +-- rimraf@2.2.8 
| +-- underscore.string@2.2.1 
| `-- which@1.0.9 
+-- jsonwebtoken@5.4.1 
| +-- jws@3.1.3 
| | +-- base64url@1.0.6 
| | | +-- concat-stream@1.4.10 
| | | `-- meow@2.0.0 
| | |   +-- camelcase-keys@1.0.0 
| | |   | `-- map-obj@1.0.1 
| | |   +-- indent-string@1.2.2 
| | |   | +-- get-stdin@4.0.1 
| | |   | `-- repeating@1.1.3 
| | |   |   `-- is-finite@1.0.1 
| | |   |     `-- number-is-nan@1.0.0 
| | |   `-- object-assign@1.0.0 
| | `-- jwa@1.1.3 
| |   +-- buffer-equal-constant-time@1.0.1 
| |   `-- ecdsa-sig-formatter@1.0.5 
| |     `-- base64-url@1.2.2 
| `-- ms@0.7.1 
+-- le_node@1.2.0 
| +-- babel-runtime@5.4.7 
| | `-- core-js@0.9.16 
| +-- codependency@0.1.3 
| | `-- semver@2.2.1 
| +-- json-stringify-safe@5.0.1 
| +-- lodash@3.9.3 
| `-- semver@5.1.0 
+-- lodash@4.11.1 
+-- machina@1.1.2 
| `-- lodash@3.10.1 
+-- mime@1.2.11 
+-- mocha@2.4.5 
| +-- commander@2.3.0 
| +-- debug@2.2.0 
| +-- diff@1.4.0 
| +-- escape-string-regexp@1.0.2 
| +-- glob@3.2.3 
| | +-- graceful-fs@2.0.3 
| | `-- inherits@2.0.1 
| +-- growl@1.8.1 
| +-- jade@0.26.3 
| | +-- commander@0.6.1 
| | `-- mkdirp@0.3.0 
| +-- mkdirp@0.5.1 
| | `-- minimist@0.0.8 
| `-- supports-color@1.2.0 
+-- mocha-lcov-reporter@0.0.1 
+-- moment@2.10.6 
+-- moment-timezone@0.4.1 
+-- mysql@2.10.2 
| +-- bignumber.js@2.1.4 
| `-- readable-stream@1.1.14 
+-- node-gcm@0.12.1 
| `-- debug@0.8.1 
+-- node-resque@0.11.6 
+-- node-schedule@0.2.9 
| +-- cron-parser@0.6.2 
| `-- long-timeout@0.0.2 
+-- node-uuid@1.4.7 
+-- optimist@0.6.1 
| +-- minimist@0.0.10 
| `-- wordwrap@0.0.3 
+-- paypal-ipn@3.0.0 
+-- primus@2.4.12 
| +-- access-control@0.0.8 
| | +-- millisecond@0.1.2 
| | `-- vary@1.0.1 
| +-- create-server@0.0.7 
| | `-- connected@0.0.2 
| +-- diagnostics@0.0.4 
| | +-- color@0.7.3 
| | | +-- color-convert@0.5.3 
| | | `-- color-string@0.2.4 
| | |   `-- color-name@1.0.1 
| | +-- colornames@0.0.2 
| | +-- env-variable@0.0.3 
| | +-- kuler@0.0.0 
| | `-- text-hex@0.0.0 
| +-- eventemitter3@0.1.6 
| +-- forwarded-for@0.1.1 
| +-- fusing@0.4.0 
| | +-- emits@1.0.2 
| | `-- predefine@0.1.2 
| |   `-- extendible@0.1.1 
| +-- load@1.0.2 
| +-- setheader@0.0.4 
| | `-- debug@0.7.4 
| `-- ultron@1.0.2 
+-- qrcode-js@0.0.2 
+-- querystring@0.2.0 
+-- redis@0.12.1 
+-- redis-sentinel-client@0.2.5 
| `-- redis@0.10.3 
+-- request@2.71.0  invalid
| +-- aws-sign2@0.6.0 
| +-- aws4@1.3.2 
| | `-- lru-cache@4.0.1 
| |   +-- pseudomap@1.0.2 
| |   `-- yallist@2.0.0 
| +-- bl@1.1.2 
| | `-- readable-stream@2.0.6 
| |   +-- isarray@1.0.0 
| |   +-- process-nextick-args@1.0.6 
| |   `-- util-deprecate@1.0.2 
| +-- caseless@0.11.0 
| +-- combined-stream@1.0.5 
| | `-- delayed-stream@1.0.0 
| +-- extend@3.0.0 
| +-- forever-agent@0.6.1 
| +-- form-data@1.0.0-rc4 
| | `-- async@1.5.2 
| +-- har-validator@2.0.6 
| | +-- chalk@1.1.3 
| | | +-- ansi-styles@2.2.1 
| | | +-- escape-string-regexp@1.0.5 
| | | +-- has-ansi@2.0.0 
| | | | `-- ansi-regex@2.0.0 
| | | +-- strip-ansi@3.0.1 
| | | `-- supports-color@2.0.0 
| | +-- commander@2.9.0 
| | | `-- graceful-readlink@1.0.1 
| | +-- is-my-json-valid@2.13.1 
| | | +-- generate-function@2.0.0 
| | | +-- generate-object-property@1.2.0 
| | | | `-- is-property@1.0.2 
| | | `-- jsonpointer@2.0.0 
| | `-- pinkie-promise@2.0.1 
| |   `-- pinkie@2.0.4 
| +-- hawk@3.1.3 
| | +-- boom@2.10.1 
| | +-- cryptiles@2.0.5 
| | +-- hoek@2.16.3 
| | `-- sntp@1.0.9 
| +-- http-signature@1.1.1 
| | +-- assert-plus@0.2.0 
| | +-- jsprim@1.2.2 
| | | +-- extsprintf@1.0.2 
| | | +-- json-schema@0.2.2 
| | | `-- verror@1.3.6 
| | `-- sshpk@1.7.4 
| |   +-- asn1@0.2.3 
| |   +-- dashdash@1.13.0 
| |   | `-- assert-plus@1.0.0 
| |   +-- ecc-jsbn@0.1.1 
| |   +-- jodid25519@1.0.2 
| |   +-- jsbn@0.1.0 
| |   `-- tweetnacl@0.14.3 
| +-- is-typedarray@1.0.0 
| +-- isstream@0.1.2 
| +-- json-stringify-safe@5.0.1 
| +-- mime-types@2.1.10 
| | `-- mime-db@1.22.0 
| +-- oauth-sign@0.8.1 
| +-- qs@6.1.0 
| +-- stringstream@0.0.5 
| +-- tough-cookie@2.2.2 
| `-- tunnel-agent@0.4.2 
+-- sequelize@3.14.2 
| +-- bluebird@3.3.5 
| +-- dottie@1.1.1 
| +-- generic-pool@2.2.1 
| +-- inflection@1.9.0 
| +-- lodash@3.10.1 
| +-- shimmer@1.1.0 
| +-- toposort-class@1.0.1 
| +-- validator@4.9.0 
| +-- wellknown@0.4.1 
| | +-- concat-stream@1.5.1 
| | | +-- readable-stream@2.0.6 
| | | | `-- isarray@1.0.0 
| | | `-- typedarray@0.0.6 
| | `-- minimist@1.1.3 
| `-- wkx@0.1.0 
+-- should@4.6.5 
| +-- should-equal@0.3.1 
| +-- should-format@0.0.7 
| `-- should-type@0.0.4 
+-- uglify-js@2.4.24 
| +-- async@0.2.10 
| +-- source-map@0.1.34 
| | `-- amdefine@1.0.0 
| +-- uglify-to-browserify@1.0.2 
| `-- yargs@3.5.4 
|   +-- camelcase@1.2.1 
|   +-- decamelize@1.2.0 
|   +-- window-size@0.1.0 
|   `-- wordwrap@0.0.2 
+-- winston@0.8.3 
| +-- async@0.2.10 
| +-- cycle@1.0.3 
| +-- eyes@0.1.8 
| +-- pkginfo@0.3.1 
| `-- stack-trace@0.0.9 
+-- winston-loggly@1.3.1 
| `-- loggly@1.1.0 
|   +-- request@2.67.0 
|   | +-- bl@1.0.3 
|   | | `-- readable-stream@2.0.6 
|   | |   `-- isarray@1.0.0 
|   | `-- qs@5.2.0 
|   `-- timespan@2.3.0 
`-- ws@0.6.5 
  +-- nan@1.4.3 
  `-- options@0.0.6 

npm WARN actionhero@10.0.3 No license field.

1 个答案:

答案 0 :(得分:1)

内存峰值似乎很可能是一支冒烟的枪 - 你超过资源配额并被杀,或者只是崩溃。这似乎可以通过创建的部分文件得到证实 - 文件最终会在片段中间结束,这是一个强烈的崩溃或强制杀戮指示。

我自己使用ActionHero,它使用的内存非常少。 Sequelize是其大部分用法,即便如此,我在生产API节点上使用超过180MB的RAM也是罕见的。您没有具体说明“内存峰值”有多大,但我会先调查一下您的流程使用的程度以及分配方式。有很多工具可用于此,但我建议使用类似StrongLoop,PM2,NewRelic或Ruxit的东西,只是因为它可以帮助您快速找到它。所有这些工具都有免费或试用选项。

除此之外,您还可以通过单独运行测试来进行一些调查。当您致电mocha时,您可以传入一个测试套件来执行

最后,如果您使用Bash作为shell,请尝试删除--globals *作为测试。 Bash可能会在执行Mocha之前扩展它,将其替换为当前工作目录中的文件列表。如果结果是抛出任何东西,你可以把它放在引号中或创建一个mocha.opts文件。这是我的,作为一个例子:

--recursive
--reporter spec
--timeout 15000
--ignore-leaks
--slow 3000
--globals api,assert
--require test/bootstrap
test

请注意,命令行参数可以覆盖opts-file设置。这就是我在这里--reporter spec的原因 - 这减少了我在我的本地开发环境中手动运行mocha的输入(我可以只运行mocha而没有参数)。您仍然可以将报告者设置为CI堆栈中所需的报告者。