Conversation
Use guid for store name
|
@JoasE the Cosmos emulator in general has had stability issues (and/or rate limiting problems) when we tried to run the tests in parallel. Is it working for you locally? |
|
@roji Thanks for the heads-up! Was just poking around a little bit. Did notice some instability locally, but it was mostly with a high level of parallelism. It appears to be worse on the pipeline. (which was to be expected). Not sure if this will really turn into something, but just needed the PR to test the changes, hope that's ok! |
|
@JoasE To speed up local runs you can change |
|
@AndriySvyryd Thanks for the tip! I will look into that. I was looking into recreating the containers also because of this statement in the docs But will try and see what performs better if I have the time |
|
Oh yeah, perhaps I had tried this already and the results were disappointing. |
|
Since we're looking at Cosmos test running time, here are the running times of the 20 most slowest tests. Note that the top-most ones are in new session token-related ones - 20 seconds each (seems odd)... |
| // Since the databases are deleted, they can't be shared across test runs, so we generate a new name for each run. | ||
| // https://learn.microsoft.com/en-us/azure/cosmos-db/emulator#differences-between-the-emulator-and-cloud-service | ||
| return Guid.NewGuid().ToString(); | ||
| return "EF-" + Guid.NewGuid().ToString(); |
There was a problem hiding this comment.
@AndriySvyryd do you think we can get rid of the GUID-named containers? I'm not sure what emulator limitations make this necessary and why we need to delete etc.
There was a problem hiding this comment.
Its documented that the emulator will show performance degradation with >10 containers in this statement in the docs
Which I think is why its deleting the containers after every test.
Because different test classes might use the same test store, using a guid was a quick fix to allow parallel execution (as we otherwise will start deleting something while it's still being used.) There might be a better way to do this, or the performance of >10 containers isn't that bad (or is more about >10 active containers). I'm still looking into that.
There was a problem hiding this comment.
Ah thanks, I missed that note. I'm guessing that's also a good reason to not parallelize (or at least to keep the degree of parallelization down)...
But I'm still not sure why it's useful to include a random GUID inside the container name. That feels more like a practice for when a shared cloud database is used potentially in parallel, to ensure you don't have conflicts - not relevant for the emulator.
There was a problem hiding this comment.
@roji
The GUID guarantees that parallel execution becomes safe by ensuring every test gets its own isolated container.
Since different test classes might use the same fixture and therefore the same test store name, conflicts will occur with parallel test execution. The tests sharing fixtures are (usually, or as far as I saw until now) read only tests, but since we are deleting the containers one test might finish and delete the container while another is still using it. Using a GUID here is a quick fix, where another option would be to group these tests and create a collection fixture, tying the container lifetime to the collection fixture, but that might require significant changes in the setup with the specifications test or throughout the entire cosmos tests project. Which I am not sure is worth the effort at this moment as I am still trying to determine whether running tests in parallel is actually feasible with the emulator.
It currently seems to be stable locally with no limit on the parallelism (which would mean processor count, which is 16 for my laptop), and no significant performance increment compared to a limit of 3 threads. With by stable I mean running the complete test suite 15 times with no errors.
If I don't delete the shared containers the emulator will stop responding to create collection requests at some point, around 20 databases with each 1-3 containers.
I haven't tested this against a real cosmos db tho, and enabling multi threading is not conditional, so I still have to do that. Maybe I could handle the parallelism myself with semaphores in the test store completely, but it might be kinda funky, also affecting test run times for tests that don't use a fixture but call InitializeAsync in the test.
I just want to mention that this is still an experiment, and I’m not sure yet whether it will succeed or if I’ll even complete it. Please don’t feel like you need to limit your questions though, I really appreciate the input and enjoy discussing it. I just don’t want you to feel like you have to spend time on it, unless you are ok with that!
Allow cosmos tests to run in parallel
Use guid for store name