如何在使用Postgres时运行超级测试时解决“无法获取连接”错误

时间:2019-05-10 19:16:39

标签: node.js postgresql heroku-postgres

我刚刚开始使用postgres和数据库,但是在运行一些测试时遇到错误。该错误显示为“错误:无法获取连接”。

 Articles Endpoints
 1) "before all" hook: clean the table in "Articles Endpoints"


 0 passing (36ms)
 1 failing

 1) Articles Endpoints
   "before all" hook: clean the table in "Articles Endpoints":
    Error: Unable to acquire a connection
  at Client_PG.acquireConnection 
  (node_modules/knex/lib/client.js:330:39)
  at Runner.ensureConnection 
  (node_modules/knex/lib/runner.js:226:24)
  at Runner.run (node_modules/knex/lib/runner.js:33:41)
  at Builder.Target.then 
  (node_modules/knex/lib/interface.js:23:43)



  npm ERR! Test failed.  See above for more details.

我已经研究过,唯一的答案是knex连接有问题,但是我找不到它有什么问题。这是我下面的包含连接的文件。

    require("dotenv").config();
    const { expect } = require("chai");
    const knex = require("knex");
    const app = require("../src/app");

    describe.only("Articles Endpoints", function() {
      let db;

      before("make knex instance", () => {
       db = knex({
       client: "pg",
        connection: process.env.TEST_DB_URL
        });
    app.set("db", db);
     });

   after("disconnect from db", () => db.destroy());

   before("clean the table", () => 
       db("blogful_articles").truncate());

    afterEach("cleanup", () => db("blogful_articles").truncate());

0 个答案:

没有答案