0
我已经休息控制器的Grails 2.5.6项目中,我创建n个异步任务,他们每个人的调用的方法在服务这样的:Grails的异步集成测试
// MyController
...
def statuses = ['where', 'ownership', 'store']
def tasks = statuses.collect { st ->
task {
return myService.invokeMethod(st, [aDomain, data])
}
}
def props = waitAll(tasks)
...
// MyService
...
store(aDomain, data) {
...
def store = Store.get(data.store)
...
}
如果我执行应用程序中,在数据库中正确找到Store。
我也创建了一个集成测试。为了避免与数据库中现有的数据冲突我在测试过程中创建一个新的Store
:
// Integration test (simplified)
....
def store = new Store(....)
store.save(flush: true)
...
def json = [store: store.id] as JSON
...
controller.request.content = params.toString()
controller.request.method = "POST"
controller.update()
...
如果我执行测试,创建新的存储在服务中未找到并导致测试失败。 我已经验证了应用程序某些点的情况,发现: - 如果我在控制器中搜索商店(执行任务之前或之后),发现它为 - 如果我列出了所有商店新店的服务方法不存在。
我想这种行为是由于测试期间如何处理hibernate会话,但我不知道如何解决它。 欢迎任何建议。
谢谢
谢谢,它的工作原理 – GUL