microsoft / testfx

MSTest framework and adapter
MIT License
714 stars 253 forks source link

AssemblyInitialize, ClassInitialize Timeout #704

Closed fl3pp closed 8 months ago

fl3pp commented 4 years ago

We are trying to migrate from MSTestV1 to MSTestV2. While doing so we noticed the behavior change documented in DeltaWithMSTestV1 - Behavior change 12 which leads to some trouble.

Unfortunately, we did not find any way to limit the execution time of the ClassInitialize and AssemblyInitialize methods.

In a comment in issue #496 there was a talk about a timeout attribute on these methods. Is there such a feature available or is there another way to set the timeouts for these methods?

As far as we've seen in the code, there is no way to limit the execution time of these methods. Because this is a feature we need (and we consider it as essential) we would be willing to go ahead and implement it by ourselves.

To avoid doing work that will have no chance to get merged into MSTestV2, we would like to know if such a feature would fit into your concept/vision for MSTestV2.

We imagine providing the following additional settings in .runsettings files:

<RunSettings>
   <MSTest>
      <AssemblyInitializeTimeout>5000</AssemblyInitializeTimeout>
      <ClassInitializeTimeout>5000</ClassInitializeTimeout>
   </MSTest>
</RunSettings>

AB#1934903

HeroMaxPower commented 4 years ago

I quite like this feature from a CI/CD point of view, for those who are unlucky enough to load large amounts of test data before the testing begins this would help narrow down the cause of a Test Execution failure. Since i imagine that 90% of the use for Assembly/Class Initialize is based for loading in test data or establishing connections to test resources. It seems like a good idea to limit the time this if a dependency fails.

There has been some cases where a build or a deployment with tests simply ran forever and gives no information of the cause. However if i know a good estimate of the time test data should be loaded in then i could use this feature to make sure it doesn't exceed the time and free up resources for another build.

dennis-yemelyanov commented 3 years ago

Totally agree with all the points here. This is a must have feature in most real life scenarios. It's great that MsTestV2 has a way to globally set a timeout for all tests, and we rely on it a lot to avoid blocking our CI/CD pipelines. However, not covering ClassInitialize/AssemblyInitialize methods limits the usefulness of this timeout setting and makes it almost useless for those who make some network calls inside these initialization methods.

Is there anything that can be done to enable globally limiting the time of ClassInitialize/AssemblyInitialize methods?

nohwnd commented 3 years ago

@Haplois Does this look like something that could be addressed in 16.9?