有太多后台工作的BDD测试?

时间:2016-11-16 07:52:13

标签: php bdd behat php-resque

我在项目中使用BDD(Behat)进行功能测试。 现在,在测试具有太多后台作业的功能时,我遇到了问题。例如:

let custom_fields = {
  "21": {
    "edit": true,
    "required": true,
    "show": true
  },
  "22": {
    "edit": true,
    "required": true,
    "show": true
  },
  "data": [{
    "display_name": "Text",
    "id": 21,
    "name": "Text",
    "value": ["TextHere"]
  }, {
    "display_name": "Text",
    "id": 22,
    "name": "Text",
    "value": ["TextHere"]
  }]
};

custom_fields.data.forEach(function(item) {
  let obj = custom_fields[item.id];
  for (let attr in item)
    obj[attr] = item[attr];
});
//Remove the data property
delete custom_fields.data;
console.log(custom_fields);

然后我必须等到它完成 ”包含:

  • 服务器1接收上传文件,将一些元数据插入数据库并将状态标记为“导入”,然后将zip文件上传至s3
  • 服务器2从s3下载文件并处理资产,如PDF,图像,然后在处理后压缩所有内容并再次上传到s3。
  • 服务器3从s3下载结果zip包(由服务器2完成),然后开始导入问题(导入pdf,图像,文章......)

我可以看到文章列表已导入 ”我是否将API调用到服务器以获取该问题的文章列表。

正如您所看到的,因为在导入期间,我们有太多后台作业(使用Resque),所以我必须等到完成后才检查问题状态:

Scenario: Import issue at the first time
    Given I have a issue package "1602.zip"
    When I upload issue "1602.zip"
    Then I have to wait until it is finished
    And I can see list of articles are imported
    And status of issue is "1"

问题是我不知道我要等多久,因为它取决于问题包的大小,更大的等待时间越长。所以在这种情况下,我该怎么办?

1 个答案:

答案 0 :(得分:1)

作为一般做法,您需要使用条件等待来检查您知道的事情(等待几秒钟)。

条件可能是:
  - 请求的状态
  - 元素显示在页面中   - 不显示页面/元素

  

提示:您应该避免仅使用while循环并使用do-while循环而不是您需要的2个条件,在您的情况下检查状态,以及如果第一个永远不会像计数一样实现。