【问题标题】:connect ETIMEDOUT when connecting cypress with DB连接 cypress 与 DB 时连接 ETIMEDOUT
【发布时间】:2022-10-21 22:39:25
【问题描述】:

我试图在 cypress 的测试中从 Db 获取令牌,但连接超时 10 次中有 8 次在下面附加错误和堆栈跟踪

当我尝试通过 Db Visualizer 发送查询或通过连接到同一个 Db 的测试 Web 应用程序访问数据时,它工作正常并且没有超时想知道它是否与我正在使用的代码或服务器有关我的索引文件中的以下代码进行连接

////////connect to DB////////////
const mysql = require('mysql');
function queryTestDb(query, config) {
  // creates a new mysql connection using credentials from cypress.json env's
  const connection = mysql.createConnection(config.env.db);
  // start connection to db
  connection.connect();
  // exec query + disconnect to db as a Promise
  return new Promise((resolve, reject) => {
    connection.query(query, (error, results) => {
      if (error) {
        connection.end();
        reject(error);
      } else {
        connection.end();
        // console.log(results)
        return resolve(results);
      }
    });
  });
}

module.exports = (on, config) => {
  // Usage: cy.task('queryDb', query)
  on('task', {
    queryDb: (query) => {
      return queryTestDb(query, config);
    },
  });
};

【问题讨论】:

  • 服务器连接似乎有问题,现在一切正常。
  • 你试过一段时间后,同样的代码对你有用???我面临同样的问题。尝试了很多但同样的问题存在。如果您对连接进行任何更改,请分享

标签: mysql node.js automated-tests cypress cypress-custom-commands


【解决方案1】:

Estou com o mesmo problema, alguém tem alguma solução ?

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-06-24
  • 2019-12-17
  • 2018-04-25
  • 1970-01-01
  • 2017-02-13
  • 2022-11-18
  • 2014-11-11
  • 1970-01-01
相关资源
最近更新 更多