在 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.
这是我的设置:
- graphql API 使用 Apollo 服务器
- ArangoDB 数据库内幕一个docker容器
一个典型的测试是这样的:
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
数据库对象并获取数据库信息。
我尝试过的其他事情:
承诺不命中数据库的测试,例如
it('foo', async () => {
等待 Promise.resolve()
期望(1).toEqual(1)
})
这些通
将超时增加到 30000。这会导致一些测试使用数据库调用 return null
。
我能够解决这个问题,但我认为存在两个问题:
- API 实际上没有连接到数据库。我能够通过创建一个新的 docker 网络并附加数据库和 VSTS 构建代理来解决这个问题,as described in this other answer
- 测试在数据库完全启动之前开始。我在测试前的 bash 脚本中添加了
sleep
命令,这似乎解决了这个问题。
我正在尝试 运行 使用 Visual Studio 团队服务构建进行开玩笑测试。这些测试 运行 正常并在本地通过,但是当我在 VSTS 中 运行 它们时超时。对于连接到数据库的每个异步测试,我得到
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
这是我的设置:
- graphql API 使用 Apollo 服务器
- ArangoDB 数据库内幕一个docker容器
一个典型的测试是这样的:
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
数据库对象并获取数据库信息。
我尝试过的其他事情:
承诺不命中数据库的测试,例如
it('foo', async () => { 等待 Promise.resolve() 期望(1).toEqual(1) }) 这些通
将超时增加到 30000。这会导致一些测试使用数据库调用 return
null
。
我能够解决这个问题,但我认为存在两个问题:
- API 实际上没有连接到数据库。我能够通过创建一个新的 docker 网络并附加数据库和 VSTS 构建代理来解决这个问题,as described in this other answer
- 测试在数据库完全启动之前开始。我在测试前的 bash 脚本中添加了
sleep
命令,这似乎解决了这个问题。