1
0
Fork 0
mirror of synced 2024-11-22 16:25:34 -05:00

Speed up Vagrant tests

This patch removes the snapshot/rollback system for the tests and
replaces it with a simple cleanup script that removes the appropriate
files from the VM's $HOME before every test. A side benefit is that
there is no more dependency on the Sahara plugin.

The cleanup script may not provide as good isolation between independent
tests as the previous setup, but it is orders of magnitude faster to run
without a VM rollback for every single test, and it does not break any
of the current tests.
This commit is contained in:
Anish Athalye 2018-03-27 20:56:55 -04:00
parent 9ff1db1672
commit b7022f4abb
2 changed files with 18 additions and 35 deletions

View file

@ -1,12 +1,8 @@
Testing
=======
Dotbot testing code uses [Vagrant][vagrant] to run all tests inside a virtual
machine to have tests be completely isolated from the host machine. The test
driver relies on the [Sahara][sahara] plugin to snapshot and roll back virtual
machine state. The tests are deterministic, and each test is run in a virtual
machine with fresh state, ensuring that tests that modify system state are
easily repeatable.
Dotbot testing code uses [Vagrant] to run all tests inside a virtual machine to
have tests be completely isolated from the host machine.
Installing the Test environnement
---------------------------------
@ -19,12 +15,6 @@ Installing the Test environnement
sudo apt install vagrant virtualbox
```
- Install the [Sahara][sahara] Vagrant plugin
```bash
vagrant plugin install sahara
```
- Install Dotbot dependencies
```bash
@ -34,14 +24,8 @@ git submodule update --init --recursive
### macOS
- Install the test requirements
- [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
- [Vagrant](https://www.vagrantup.com/downloads.html)
- Install the [Sahara][sahara] Vagrant plugin
```bash
vagrant plugin install sahara
```
- [VirtualBox]
- [Vagrant]
- Install Dotbot dependencies
@ -64,5 +48,5 @@ Tests can be run with a specific Python version by running `./test --version
When finished with testing, it is good to shut down the virtual machine by
running `vagrant halt`.
[vagrant]: https://www.vagrantup.com/
[sahara]: https://github.com/jedi4ever/sahara
[VirtualBox]: https://www.virtualbox.org/wiki/Downloads
[Vagrant]: https://www.vagrantup.com/

View file

@ -31,10 +31,6 @@ check_prereqs() {
>&2 echo "vagrant vm must be running."
return 1
fi
if ! (vagrant plugin list | grep '^sahara\s\+') >/dev/null 2>&1; then
>&2 echo "vagrant plugin 'sahara' is not installed."
return 1
fi
}
until_success() {
@ -56,23 +52,26 @@ wait_for_vagrant() {
until_success vagrant ssh -c 'exit'
}
rollback() {
vagrant sandbox rollback >/dev/null 2>&1 &&
wait_for_vagrant &&
vagrant rsync >/dev/null 2>&1
cleanup() {
vagrant ssh -c "
find . -not \\( \
-path './.pyenv' -o \
-path './.pyenv/*' -o \
-path './.bashrc' -o \
-path './.profile' -o \
-path './.ssh' -o \
-path './.ssh/*' \
\\) -delete" >/dev/null 2>&1
}
initialize() {
echo "initializing."
vagrant sandbox on >/dev/null 2>&1
if ! vagrant ssh -c "pyenv local ${2}" >/dev/null 2>&1; then
wait_for_vagrant && vagrant sandbox rollback >/dev/null 2>&1
wait_for_vagrant
if ! vagrant ssh -c "pyenv install -s ${2} && pyenv local ${2}" >/dev/null 2>&1; then
die "could not install python ${2}"
fi
vagrant sandbox commit >/dev/null 2>&1
fi
vagrant rsync >/dev/null 2>&1
tests_run=0
tests_passed=0
tests_failed=0
@ -96,7 +95,7 @@ fail() {
run_test() {
tests_run=$((tests_run + 1))
printf '[%d/%d] (%s)\n' "${tests_run}" "${tests_total}" "${1}"
rollback || die "unable to rollback vm." # start with a clean slate
cleanup
vagrant ssh -c "pyenv local ${2}" >/dev/null 2>&1
if vagrant ssh -c "cd /dotbot/test/tests && bash ${1}" 2>/dev/null; then
pass