tests: Make Tests.Cumulocity.Software Management.Software suite faster#4237
tests: Make Tests.Cumulocity.Software Management.Software suite faster#4237Bravo555 wants to merge 2 commits into
Tests.Cumulocity.Software Management.Software suite faster#4237Conversation
Signed-off-by: Marcel Guzik <marcel.guzik@cumulocity.com>
- rewrite some tests that spawn new containers to not spawn + restore previous state - removed some Sleep keywords that were useless because keywords after retry anyway Signed-off-by: Marcel Guzik <marcel.guzik@cumulocity.com>
Tests.Cumulocity.Software Management.Software suite faster
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
Robot Results
|
rina23q
left a comment
There was a problem hiding this comment.
Nice experiment.
I think one problem of this test file is mixed of 3 level things:
- testing against c8y with legacy software management
- testing against c8y with advanced software management
- testing locally, without using c8y
I agree that the previous setup, creating a test container per each test is time consuming and too much costs.
However, I sometimes think we put too many tests in one robot file. For this case, if we split the file into three (or at least two, covering point 1&2-c8y and point 3-local) files, maybe the tests would look short and easy to read.
| *** Test Cases *** | ||
| Supported software types should not be declared during startup when disabled | ||
| # This Setup could be removed and test could run on a suite device, making it faster | ||
| # if we either actively sent an empty software type fragment on startup (currently we just don't send anything) |
There was a problem hiding this comment.
Having the c8y_SupportedSoftwareTypes fragment in ManagedObject triggers filtering out "Installed Software" list in the "Software" tab. To avoid an unexpected surprise, c8y.software_management.with_types is set to false by default.
I tested how to reset the fragment in c8y. We can send either JSON over MQTT or SmartREST.
tedge mqtt pub c8y/inventory/managedObjects/update/${DEVICE_SN} '{"c8y_SupportedSoftwareTypes":null}'tedge mqtt pub c8y/s/us 143
After the MQTT request is sent, if we ensure the fragment does not exist in MO, this is the clean enough state for this test.
In short, yes, we can remove this Setup by replacing it as I wrote above.
| Set Managed Object | ||
| [Arguments] ${device_sn} | ||
| Cumulocity.Set Managed Object ${device_sn} | ||
| ThinEdgeIO.Set Device Context ${device_sn} |
There was a problem hiding this comment.
(trivial) I think we can promote this to library level 🤔
|
|
||
| *** Keywords *** | ||
| Custom Suite Setup | ||
| ${device_sn}= Custom Setup With Software Types Enabled |
There was a problem hiding this comment.
(note) This change makes most of tests run with c8y.software_management.with_types = true, which is against default. Previously, they were tested with the default (false) value. Eventually, this value doesn't affect tests unless it uses advanced software management.
|
|
||
| Sleep 5s reason=Given mapper a chance to react, if it does not react with 5 seconds it never will | ||
| ${retained_message}= Execute Command | ||
| ... tedge mqtt sub --no-topic '${topic}' --duration 1 | ||
| ... ignore_exit_code=${True} | ||
| ... strip=${True} | ||
| ... timeout=5 |
There was a problem hiding this comment.
I think this change is problematic as you might get the message before it has been cleared by the mapper, so the static sleep was in-place to ensure the mapper is not clearing the message. Removing the timeout means that the tedge mqtt sub might see the previously manually posted message before the tedge-mapper reacts to it.
Proposed changes
Tests.Cumulocity.Software Management.Softwaresuite is our slowest test suite, running at over 10 minutes on the test runner, I thought to try to speed it up a bit to get some sense what kind of changes would be necessary in other suites to speed up the entire test suite. Currently it runs in about 30 minutes, I think it would be neat if it ran closer to 5-10 minutes.This PR speeds up software test suite by:
Sleepkeywords that were useless because keywords after retry anywayOn my pc
on test runner
We're running the suites in parallel, so it will have very limited impact on total runtime, but after doing it I have a better idea of what type of changes would be required to speed up other tests. Apart from repeating these changes for other suites, one other speedup would be to try to replace retry mechanisms that always wait
2swith blocking mechanisms that return as soon as assertion succeeds. In some tests there are multiple of these kinds of checks, for example in test caseOperation gets updated regardless of the order of the creation timewe hit a2sretry 4 times, so8sin a test that takes14s(on my machine), little over 50%, is spent waiting, so I expect it to also inflate runtime of other suites a bit.Though speeding it up does take a lot of time, so next time I'll try to task other suites to an AI model.
Types of changes
Paste Link to the issue
Checklist
just prepare-devonce)just formatas mentioned in CODING_GUIDELINESjust checkas mentioned in CODING_GUIDELINESFurther comments