在 VSTS 中,连接到 dockerized ArangoDB 数据库的异步 Jest 测试超时

In VSTS, async Jest tests that connect to dockerized ArangoDB database time out

我正在尝试 运行 使用 Visual Studio 团队服务构建进行开玩笑测试。这些测试 运行 正常并在本地通过,但是当我在 VSTS 中 运行 它们时超时。对于连接到数据库的每个异步测试,我得到

Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

这是我的设置:

一个典型的测试是这样的:

const database = require('../models')
...
describe('database setup', () => {
    it('sets up the database and it exists', () => {
        console.log(database.db)
        const collection=database.db.collection('agents')
        console.log(collection)
        return database.db.exists().then((result) => {
            expect(result).toBeTruthy()
        }).catch(err => {console.log(err)})
        .then(x => console.log(x)) 
    })
}
...
describe('help functions', () => {
    it('gets edge count for a node', async () => {
        let result = await database.getEdgeCount('nodes/1', 'inbound')
        expect(result).toBeGreaterThan(2)
    })
})

我正在 运行使用 NPM 任务在 VSTS 中进行测试。此任务的 YAML 是基本的:

steps:
- task: Npm@1
  displayName: npm test
  inputs:
    command: custom
    workingDir: api
    verbose: false
    customCommand: 'test --runInBand'

我知道测试正在连接到数据库,因为我可以 console.log 数据库对象并获取数据库信息。

我尝试过的其他事情:

我能够解决这个问题,但我认为存在两个问题:

  1. API 实际上没有连接到数据库。我能够通过创建一个新的 docker 网络并附加数据库和 VSTS 构建代理来解决这个问题,as described in this other answer
  2. 测试在数据库完全启动之前开始。我在测试前的 bash 脚本中添加了 sleep 命令,这似乎解决了这个问题。