I have a specific framework that is actually updating tons of data using platform event. Now I need to do a stress test to determine what is the amount of data that the framework would actually break.

The scenario Goes like this. A parent has multiple Objects that have the same field as parent Let's say field A for example. Now the thing is once field A gets updated in the parent that specific field should be updated across multiple objects with multiple records. It is actually a lot more complex than that but that is the main concept of it (I can't use a formula for this requirement).

Now I am making a test class that updates Field A on the parent object and I should do an assertion if all the child objects have been updated. But since it is actually on a platform event, the time the assertion is hit, the field isn't updated yet. (it might take some time before the field gets updated). I have tried delaying the assertion in a specific time by using this code.

 Integer delayInMilliseconds = 10000; // 10-second delay
    while (System.now().getTime() - startingTime < delayInMilliseconds)  {
        //Assertion Here

But no luck. Any alternatives I can actually do? Maybe I am missing some important points here.

1 Answer 1


Your unit test should be using Test.startTest() and Test.stopTest() around the code that is generating the platform events, or you should call Test.getEventBus().deliver() immediately after the statement in the unit test that causes the platform event to be published. If you do that your unit test will find that the platform event has been delivered and processed before Test.stopTest() or Test.getEventBus().deliver() has completed.

See the documentation for more detail.

If your test requires more than 2000 platform events to be processed in one go, I suspect you are out of luck and cannot do testing in this way.

NB: Stress testing is not really something you should do with a unit test since it could have quite an impact on how long it takes to run your unit tests (plus the types of org you do your development against may not have enough database storage to actually support a true stress test). Instead you should create an end-to-end test that you are more selective about when and where you execute it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .