Recently we’ve began working with running tests in GitLab CI through GameCI’s Docker images and configuration files. We are also using Zenject for our services, and are writing tests that load the scene through its testing framework (along with our service container) and test the application’s behavior this way. For now these are simple, such as loading the scene, clicking a button on a window and checking if it is visible afterwards, and clearing the scene again (to get a clean slate for the next test).
This works fine locally, and tests are reasonably fast, about one second per behavior test. For some reason, though, in GitLab CI, these are unacceptably slow - each test takes anywhere between 50 to 120 seconds.
Analyzing the Unity logs in CI, it turns out deserialization of the scene is the root cause. Here is an excerpt from a single test:
Loaded scene 'Assets/Scenes/Main.unity'
Deserialize: 106748.398 ms
Integration: 1540.717 ms
Integration of assets: 507.097 ms
Thread Wait Time: -432.781 ms
Total Operation Time: 108363.430 ms
The first test is usually a little slower, so all consecutive tests are similar to the following:
Loaded scene 'Assets/Scenes/Main.unity'
Deserialize: 61155.941 ms
Integration: 744.542 ms
Integration of assets: 292.142 ms
Thread Wait Time: -224.852 ms
Total Operation Time: 61967.773 ms
Which amounts to about 60 seconds per test. I realize GitLab CI is less powerful than a development machine, but this seems extremely slow. GitLab CI has little problems with these kind of tests in npm, PHP, or other languages, which are also computationally expensive (and usually not native or use JIT, so one would expect Unity to be even faster).
We have code coverage enabled, but are limiting it to our application’s scripts, but it is possible that it is impacting it anyway (?). If that turns out to be the case, we could try disabling it, but in the end this would also be unfortunate since we would lose coverage entirely.
Also, we use the YAML scene format to get better results when merging in Git, which may also be related to (de)serialization performance.
Does anyone have any pointers towards improving the situation?