【发布时间】:2021-10-12 11:27:29
【问题描述】:
我有一个场景,每 5 秒有条件地等待最多 1 分钟。我已经通过使用 java.lang.Thread.sleep() 进行轮询来实现它,这会阻塞线程并在我的多线程项目中失败。如何在我的普通空手道特征函数中使用类似 karate.pause() 的东西?注意:在我的情况下,我不能使用“重试直到”。
这是我使用 Thread.sleep() 进行轮询的方法,
* def checkForEventCompletion =
"""
function(arg) {
var poolTime = 5;
var counter = 1;
// should pool for every 5 seconds until it exceeds your input wait time
while (true) {
if( (counter*poolTime) > arg.maxWaitTime){
karate.log('Status Not yet Updated');
return EventStatus;
}
//Code to Fetch EventStatus
karate.log('Current Status->',EventStatus);
if (EventStatus == 'COMPLETED') {
karate.log('Status Verified, --Exiting--');
return true;
}
// pool every 5 seconds
java.lang.Thread.sleep(poolTime*1000);
counter++;
}
}
当我尝试使用 karate.pause() 时,它失败并显示“com.intuit.karate.core.ScenarioBridge@4acb7ecc 上的 invokeMember (pause) 失败,原因是:未知标识符:暂停”。
【问题讨论】:
标签: multithreading sleep karate pause