gpt4 book ai didi

javascript - knex 中的排水管连接需要比预期更多的时间

转载 作者:太空宇宙 更新时间:2023-11-04 01:59:36 24 4
gpt4 key购买 nike

我正在对使用 knex 池的项目进行 Mocha 测试。

我遇到的问题是,当测试结束时,它会一直等待,直到 knex 池耗尽,并且需要额外的秒数(大约 5-10 秒)才能完成 mocha 运行。

代码示例:

knex 初始化:

const Knex = require('knex');
const knex = new Knex({
client: 'pg',
pool: { min: 1, max: 10 },
connection: {},
searchPath: 'knex,public',
// debug: true,
});

Mocha 测试排水管连接:

  after((done) => {
knex.destroy().then(done);
})

我想要完成的是两者中的任何一个:

  1. 更快地耗尽 knex 连接
  2. 不知何故 Mocha 完成测试而无需等待 knex 排水

有什么建议吗?

最佳答案

此功能之前在 Mocha 中已更改

2879: By default, Mocha will no longer force the process to exit once all tests complete. This means any test code (or code under test)

which would normally prevent node from exiting will do so when run inMocha. Supply the --exit flag to revert to pre-v4.0.0 behavior(@ScottFreeCode, @boneskull)

https://github.com/mochajs/mocha/blob/master/CHANGELOG.md

如果上述方法没有帮助,您可以随时在done中调用process.exit(0)来强制终止带有成功退出代码的进程。

据我所知,在 knex 端,没有用于强制终止连接的强制选项。

关于javascript - knex 中的排水管连接需要比预期更多的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46572132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com