Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Controlling the batch size
samholder
#1 Posted : Tuesday, October 31, 2023 3:59:52 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/11/2012(UTC)
Posts: 94

Thanks: 28 times
Was thanked: 12 time(s) in 12 post(s)
I asked this question a while back:

https://forum.ncrunch.ne...led-multiple-times.aspx

and whilst I understand the answer and the reason for the current behaviour, I'm having a similar issue again but when using playwright and hosting all the app in process. This means that the static variable trick doesn't seem to work, I can't reuse the app/browser across test batches.

This means I have a more significant overhead for setting up the tests vs running the batch of tests.

Is it possible to get a option (or maybe there is one) to have some more control over the batches of tests that are run so that the BeforeTestRun/AfterTestRun issues are ,minimised. If we could opt in to different batch sizes (currently it seems that there are about 8 tests in a batch) then using bigger batch sizes would mean that I would run more tests using a single browser instance and so offset the browser creation overhead. Maybe options for approximate batch size that we could set to some value and NCrunch would attempt to run that many tests in a single batch? Then I could have say 50 tests in a batch rather than 8.

Ideally we would have an option to minimise the number of batches, so create n batches up front, where n is the number of processing threads, and each batch would contain (number of tests)/n tests. I appreciate that this would negate some of the benefits of the pipeline and scheduling to try an optimise the test run, but I think in some cases the set up is such an overhead that it negates any of these benefits anyway.

some rough testing I have done:

we have ~1000 integration tests. Running them all in VSTest and reusing the same browser for each test takes about 15mins
running in ncrunch with 8 threads takes about 30 mins, mainly because the test start up is quite significant, and we only get a few tests run for each startup (the processing queue indicates that most batches only have a small number of tests, often 1/2).

Having some mechanism to influence this in a positive way when we know we have this situation would be useful.
Remco
#2 Posted : Tuesday, October 31, 2023 11:28:28 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,987

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
From the features we have available, the closest thing I can think of would be to use atomic attribute on a large fixture that contains many test cases, each one of which is an integration test that is set up to share the same playwright instance. Clearly, this would be rather painful as you would need to design your test suite around NCrunch's constraints and probably it would involve porting over 1000 integration tests to a new structure. However, this would give you a way to force the engine to conform to your chosen batch sizes.

I don't have personal experience with playwright, but it feels to me that this is a cleanup issue. What are the consequences if a test process that uses playwright is suddenly terminated without warning? Are there browser instances or resources that leak? I ask this as I'm wondering if there's an opportunity to simply re-use the playwright session across all tests that share the same process, then either forego a proper cleanup or design a new mechanism to handle cleanup separately. NCrunch does re-use test processes across batches, so this could give an opportunity to avoid repeated and expensive initialisation.
1 user thanked Remco for this useful post.
samholder on 11/1/2023(UTC)
samholder
#3 Posted : Wednesday, November 1, 2023 8:36:02 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/11/2012(UTC)
Posts: 94

Thanks: 28 times
Was thanked: 12 time(s) in 12 post(s)
Cheers Remco.

I'll look at the atomic attribute as an option in the short term, as this wouldn't have too much impact on the tests and would allow some large features to run a good chunk of the tests together (some features have >100 tests).

I'll do a bit more digging into sharing the playwright instance, and the application, across the process and see if we can get anything running there.

Thanks for the input. No chance of some control over the batching size even if its only a hint like 'prefer large', 'prefer very large', 'prefer extra large' option in the config? or maybe a 'by feature' option that just applies the atomic attribute to the feature automatically, so the tests don't need to change? (we are using specflow so adding NCrunch attributes is not super straight forward. I have a plugin that does it, but think it currently only works at the test level, not the feature level).
Remco
#4 Posted : Wednesday, November 1, 2023 11:47:37 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,987

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
samholder;16909 wrote:

Thanks for the input. No chance of some control over the batching size even if its only a hint like 'prefer large', 'prefer very large', 'prefer extra large' option in the config? or maybe a 'by feature' option that just applies the atomic attribute to the feature automatically, so the tests don't need to change? (we are using specflow so adding NCrunch attributes is not super straight forward. I have a plugin that does it, but think it currently only works at the test level, not the feature level).


I think it's reasonable to expect we will eventually add an attribute that can control test batching in a more direct way than we do with the other attributes, but right now we're snowed under with preparation for the V5 release. Something I'd suggest is to put it through a feature request on uservoice so it doesn't get lost and we have a way to prioritise this with everyone else's feedback. If you can take a moment to do this, please make sure to add detail on how you would like such a feature to work (as would be ideal for your environment).
1 user thanked Remco for this useful post.
samholder on 11/1/2023(UTC)
samholder
#5 Posted : Wednesday, November 1, 2023 8:28:50 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/11/2012(UTC)
Posts: 94

Thanks: 28 times
Was thanked: 12 time(s) in 12 post(s)
ok, so I got the atomic attribute working and it allows the tests to be run in batches and thats great, however I misunderstood how it worked, and it effectively means you can't run a single test on its own any more as it has to run all those tests. I think this could be ok, but isn't really an appropriate solution I don't think
samholder
#7 Posted : Wednesday, November 1, 2023 9:13:46 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/11/2012(UTC)
Posts: 94

Thanks: 28 times
Was thanked: 12 time(s) in 12 post(s)
1 user thanked samholder for this useful post.
Remco on 11/1/2023(UTC)
Remco
#6 Posted : Wednesday, November 1, 2023 10:50:44 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,987

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
samholder;16912 wrote:
ok, so I got the atomic attribute working and it allows the tests to be run in batches and thats great, however I misunderstood how it worked, and it effectively means you can't run a single test on its own any more as it has to run all those tests. I think this could be ok, but isn't really an appropriate solution I don't think


Sorry, I probably should have mentioned this. AtomicAttribute locks the tests together so they can never run independently.

I still think the better approach would be to try and attach the lifespan of the playwright session to the lifespan of the NCrunch test process. If you can make it work this way, everything will fit together well and work very efficiently.
samholder
#8 Posted : Tuesday, November 7, 2023 9:20:29 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/11/2012(UTC)
Posts: 94

Thanks: 28 times
Was thanked: 12 time(s) in 12 post(s)
ok, I got the browser instance to be shared across the test batches (and got the test run time down to <5 mins for all 1000+ tests), but this raises a question for me.

Given these are integration tests genrally we are not running them in continuous test mode. Usually its in 'run all tests manually' and then triggering when we need.

if we did run in a continuous mode (like 'run all pinned tests' with say a handful of tests pinned) what determines if NCrunch reuses the same process, and so if my static flag is set to skip initialisation?

Currently we are skipping some setup if the test look like they have been run before in this process and this works because the batches are using the same version of the code, but if we were continuous and making changes to the code am I creating another problem, in that the latest code is not actually going to be used as the tests won't redo the setup if there are changes to the code and those changes are running in a process that has already run an old version of the code.

Or can a i guarantee that when there are changes these are always going to be run in a new process?
Remco
#9 Posted : Tuesday, November 7, 2023 11:53:22 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,987

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
It is guaranteed that when the code changes, all test processes must be recycled by NCrunch before they can run the new code.

This is because of a technical limitation. Once an assembly has been loaded into a .NET application domain, it cannot be unloaded without the entire domain being taken down. So if you change your code, you'll get a new process. Every time.
1 user thanked Remco for this useful post.
samholder on 11/7/2023(UTC)
samholder
#10 Posted : Tuesday, November 7, 2023 11:59:40 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/11/2012(UTC)
Posts: 94

Thanks: 28 times
Was thanked: 12 time(s) in 12 post(s)
awesome, that's a relief :).

Cheers for the quick and helpful responses. Getting bthe run time down from 30+mins to 5 is a massive boost for us.
1 user thanked samholder for this useful post.
Remco on 11/7/2023(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.074 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download