Dynamic scenario freezes when called using afterFeature hook

For now, I have done the following workaround where I have added a test clean-up scenario at the end of the feature that has tests. Have stopped parallel execution for these tests and to be honest I do not mind these tests not running in parallel as they are fast to run anyways.

Ids to delete:

* def idsToDelete =
    """
      [
        101,
        102,
        103
      ]
   """

Test clean up scenario:

# Test data clean-up scenario
  Scenario: Delete test data
    # Js method to call delete data feature.
    * def deleteTestDataFun =
    """
      function(x) {
        var temp = [x];
        // Call to feature. Pass argument as json object.
        karate.call('delete-test-data.feature', { id: temp });
      }
    """
    * karate.forEach(idsToDelete, deleteTestDataFun)

Calls the delete test data scenario and passes it a list of ids that needs to be deleted.

Delete test data feature:

Feature: To delete test data

  Background:
    * def idVal = id

  Scenario: Delete 
    Given path 'tests', 'delete', idVal
    Then method delete

Yeah I personally recommend a strategy to pre-clean-up always, because you cannot guarantee that an "after" hook gets called, e.g. if the machine is switched off.

Sometimes the simplest option is to do this as plain old Java code in your JUnit test-suite. So maybe a one-line after using Runner is sufficient.

It gets tricky if you need to keep track of dynamic data that your tests have created. What I would do is write a Java singleton, use it in your tests to "collect" the ID-s that need to be deleted, and then use this in your JUnit class. You can use things like @AfterClass.

Please try and replicate using the instructions here: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue - because this can indeed be a bug with Scenario Outline.

Finally, you can evaluate ExecutionHook which has an afterSuite() callback: https://github.com/intuit/karate/issues/970#issuecomment-557443551

EDIT: in 1.0 - it has become RuntimeHook: https://github.com/intuit/karate/wiki/1.0-upgrade-guide#hooks