BDD testing with too many background jobs?

99 Views Asked by At

I'm using BDD (Behat) for functional testing in my project. Now I have a problem when testing a feature with too many background jobs. Example:

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"

"Then I have to wait until it is finished" contains:

  • Server 1 received uploaded file, insert some metadata to database and mark status to "importing", then upload zip file to s3
  • Server 2 download file from s3 and process the assets stuff like PDF, images, then zip everything after processed and upload to s3 again.
  • Server 3 download the result zip package (done by server 2) from s3, and start to import issue (import pdf, images, articles...)

"And I can see list of articles are imported" is I call an API to server to get list of articles of that issue.

So as you can see, because during import, we have too many background job (using Resque), so I have to wait until it is finished by checking status of issue:

while ($status != 1) {
    $status = getStatusOfIssue(123);
    if (1 === $status) {
        break;
    }
}

The problem is I don't know how long I have to wait, because it depends on the size of issue package, the bigger size the longer time for waiting. So in this situation, what should I do?

1

There are 1 best solutions below

0
On

As a general practice, you need to use a conditional wait to check something you know(wait seconds until).

The condition might be:
- status of a request
- an element is displayed in a page
- a page/element is not displayed

Tip: you should avoid using just while loop and use a do-while loop instead with 2 conditions one that you need, in you case check status, and one that will break out of loop if the first one is never fulfilled like a count.