TestApi.teardown and batch created entities


Calling TestApi.teardown on a context tracking entities created with createBatchEntity is very slow.
I created hundreds of Measurements (all attached to the same timeseries).
Is there a way to improve the performances of TestApi.teardown and make it call a removeAll instead of remove?


teardown already uses removeAll! I think what’s slowing down the teardown is the waiting for queues to drain especially if they have too many entries.


Running teardown shows hundreds of remove with individual id.
Not sure what am I missing, why it is not using removeAll


I think the only case where Type.remove is used is when someone explicitly uses the TestAPi.removeEntities function, in the other cases it’s either removeAll or removeBatch that’s used.

Can you check that you’re not calling removeEntities?


Here is the code that is making the call to individual remove:

  var ctx = TestApi.createContext("FOO");

    function addMeasurementsTo(id) {
      var start = new DateTime("2016-01-01");
      var end = new DateTime("2016-02-01");
      var measurements = Measurement.array();
      for (var date = start; date < end; date = date.plusDays(1)) {
              start: date,
              end: date.plusDays(1),
              quantity: {
                  value: 0,
                  unit: {"id": "dimensionless"}
              parent: {
                "id": id

      TestApi.createBatchEntity(ctx, "Measurement", measurements);


It seems that the behaviour is not the same when the header is also tracked by the TestApi ( here the header is not created by the TestApi )