I have seen this operation on our local systems, using 2015 TFS Update 2 on Premise. I can reproduce the issue with a couple different scenarios, which are consistent, but give different outcomes. Hopefully this will clear things up for others that have this issue.
Our test servers are VMs so I will refer to them as such below.
Reproduce VMs NOT Restarting before running tests
- After tests are already run, with out touching the VMs (IE not restarting, not starting a remote connection, ect) run another set of tests and you will see the VMs will not restart.
Reproduce VMs restarting
- New Setup where tests have not been run before
- After a remote connection to the VM then logging out of that remote session.
- After restarting the VM itself. (Yes after a restart, when the tests run they restart it again).
- After logging off VM using tscon 1 /dest:console
There are a few scenarios I have not tested like connecting using MTM Test Lab.
Setup Considerations
- All VMs are manually setup to disable lock screen in gpedit.msc
- All VMs setup to automatically login using regedit settings and adding DefaultPassword.
- Manually installed test agents on each VM
- Update Test Agent is Not checked in Test Agent Deployment task.
- We are Running tests as part of a Release and not a Build (should not make a difference for the most part).
Conclusion
My best guess would be there are certain states the system checks on the VM to make sure it is in the exact state needed to run the tests, if every criteria is not met it restarts the server and sets it to those states. This could include specific login states and services running.