我正在尝试使用CI部署我的回送应用程序,并且玩笑不会退出,因此CI无法继续。如果我停止数据库容器,在我的语言环境中也会发生同样的事情。我的测试不是针对db运行的,但是我认为当玩笑引导应用程序时,它会尝试连接,并且我试图捕获并关闭连接,但并没有帮助。这是玩笑测试的输出。
Test Suites: 3 passed, 3 total
Tests: 13 passed, 13 total
Snapshots: 0 total
Time: 6.304s
Ran all test suites.
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Connection fails: Error: connect ECONNREFUSED 127.0.0.1:5432
It will be retried for the next request.".
at BufferedConsole.error (node_modules/jest-util/build/BufferedConsole.js:136:10)
at msg (node_modules/strong-globalize/lib/globalize.js:245:13)
at packMessage (node_modules/strong-globalize/lib/globalize.js:227:16)
at Object.rfc5424 (node_modules/strong-globalize/lib/globalize.js:242:12)
at StrongGlobalize.error (node_modules/strong-globalize/lib/strong-globalize.js:163:26)
at DataSource.postInit (node_modules/loopback-datasource-juggler/lib/datasource.js:479:13)
at PendingItem.callback (node_modules/loopback-connector-postgresql/lib/postgresql.js:103:17)
at client.connect (node_modules/pg-pool/index.js:248:23)
at Connection.connectingErrorHandler (node_modules/pg/lib/client.js:140:14)
error: uncaughtException: connect ECONNREFUSED 127.0.0.1:5432 date=Fri Feb 22 2019 20:54:31 GMT+0300 (+03), pid=86092, uid=501, gid=20, cwd=/Users/hazimdikenli/workspace/ATEZ-BTD/app, execPath=/Users/hazimdikenli/.nvm/versions/node/v8.11.3/bin/node, version=v8.11.3, argv=[/Users/hazimdikenli/.nvm/versions/node/v8.11.3/bin/node, /Users/hazimdikenli/workspace/ATEZ-BTD/app/node_modules/jest-worker/build/workers/processChild.js], rss=237056000, heapTotal=201125888, heapUsed=157644632, external=419986, loadavg=[3.91162109375, 3.453125, 3.39453125], uptime=3318870, trace=[column=11, file=util.js, function=Object._errnoException, line=992, method=_errnoException, native=false, column=20, file=util.js, function=_exceptionWithHostPort, line=1014, method=null, native=false, column=14, file=net.js, function=TCPConnectWrap.afterConnect [as oncomplete], line=1186, method=afterConnect [as oncomplete], native=false], stack=[Error: connect ECONNREFUSED 127.0.0.1:5432, at Object._errnoException (util.js:992:11), at _exceptionWithHostPort (util.js:1014:20), at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)]
● process.exit called with "1"
at gracefulExit (node_modules/winston/lib/winston/logger.js:660:15)
at done (node_modules/winston/node_modules/async/lib/async.js:167:19)
at node_modules/winston/node_modules/async/lib/async.js:40:16
at Object.<anonymous>.exports.Console.onComplete (node_modules/winston/lib/winston/transports/transport.js:128:7)
at Object.<anonymous>.exports.Console.Object.<anonymous>.Console.log (node_modules/winston/lib/winston/transports/console.js:128:8)
at Object.<anonymous>.exports.Console.Object.<anonymous>.Transport.logException (node_modules/winston/lib/winston/transports/transport.js:134:8)
at logAndWait (node_modules/winston/lib/winston/logger.js:649:15)
我的测试未针对db运行,但是我认为当玩笑引导应用程序时,它会尝试连接,并且我试图捕获并关闭连接,但没有帮助。我认为这种情况是在应用程序开玩笑地启动时发生的,所以我该如何捕捉到这个消息,或者使开玩笑成功地退出。 预先感谢。
答案 0 :(得分:1)
尝试使用“ lazyConnect”将连接推迟到需要连接时
"postgres": {
"host": "/var/run/postgresql/",
"port": "5432",
"database": "dbname",
"username": "dbuser",
"password": "dbpassword",
"name": "postgres",
"connector": "postgresql",
"lazyConnect": true
}