在 Rails 测试中手动重新连接到数据库
好吧,我正在尝试做一些偷偷摸摸的事情来加快我的测试套件的速度。我有一个基于事件机的服务器连接到我的 Rails 应用程序与之通信的数据库。
在每次测试中启动这个 EM 服务器都需要永远,所以我希望让它在整个测试套件的执行过程中保持运行。
然而,EM 服务器进程与数据库进行对话,并且当测试数据库在每次测试结束时重置并抛出许多令人讨厌的 Postgres 错误时,它会变得非常不安。
我想如果我可以告诉 EM 服务器在每个新测试开始时重置它与测试数据库的连接,我就能够避免这个问题。
关于我如何做到这一点有什么想法吗?
Ok so I'm trying to do something a bit sneaky to speed up my test suite. I have a Event Machine based server connected to the database which my rails app talks to.
Spinning up this EM Server on each test takes forever so I was hoping to leave it running throughout the execution of the entire test suite.
However, the EM Server process talks to the DB and gets very upset when the Test DB is reset at the end of each test throwing lots of nasty looking Postgres errors.
I think I would be able to circumvent this problem if I could tell the EM server to reset it's connection to the Test DB at the start of each new test.
Any ideas on how I can do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过在适配器上调用
reconnect!
?http://apidock.com/rails/ActiveRecord/ConnectionAdapters/AbstractAdapter/reconnect%21
Have you tried calling
reconnect!
on the adapter?http://apidock.com/rails/ActiveRecord/ConnectionAdapters/AbstractAdapter/reconnect%21