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:
parent
9ff1db1672
commit
b7022f4abb
2 changed files with 18 additions and 35 deletions
|
@ -1,12 +1,8 @@
|
||||||
Testing
|
Testing
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Dotbot testing code uses [Vagrant][vagrant] to run all tests inside a virtual
|
Dotbot testing code uses [Vagrant] to run all tests inside a virtual machine to
|
||||||
machine to have tests be completely isolated from the host machine. The test
|
have tests be completely isolated from the host machine.
|
||||||
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.
|
|
||||||
|
|
||||||
Installing the Test environnement
|
Installing the Test environnement
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
@ -19,12 +15,6 @@ Installing the Test environnement
|
||||||
sudo apt install vagrant virtualbox
|
sudo apt install vagrant virtualbox
|
||||||
```
|
```
|
||||||
|
|
||||||
- Install the [Sahara][sahara] Vagrant plugin
|
|
||||||
|
|
||||||
```bash
|
|
||||||
vagrant plugin install sahara
|
|
||||||
```
|
|
||||||
|
|
||||||
- Install Dotbot dependencies
|
- Install Dotbot dependencies
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -34,14 +24,8 @@ git submodule update --init --recursive
|
||||||
### macOS
|
### macOS
|
||||||
|
|
||||||
- Install the test requirements
|
- Install the test requirements
|
||||||
- [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
|
- [VirtualBox]
|
||||||
- [Vagrant](https://www.vagrantup.com/downloads.html)
|
- [Vagrant]
|
||||||
|
|
||||||
- Install the [Sahara][sahara] Vagrant plugin
|
|
||||||
|
|
||||||
```bash
|
|
||||||
vagrant plugin install sahara
|
|
||||||
```
|
|
||||||
|
|
||||||
- Install Dotbot dependencies
|
- 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
|
When finished with testing, it is good to shut down the virtual machine by
|
||||||
running `vagrant halt`.
|
running `vagrant halt`.
|
||||||
|
|
||||||
[vagrant]: https://www.vagrantup.com/
|
[VirtualBox]: https://www.virtualbox.org/wiki/Downloads
|
||||||
[sahara]: https://github.com/jedi4ever/sahara
|
[Vagrant]: https://www.vagrantup.com/
|
||||||
|
|
|
@ -31,10 +31,6 @@ check_prereqs() {
|
||||||
>&2 echo "vagrant vm must be running."
|
>&2 echo "vagrant vm must be running."
|
||||||
return 1
|
return 1
|
||||||
fi
|
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() {
|
until_success() {
|
||||||
|
@ -56,23 +52,26 @@ wait_for_vagrant() {
|
||||||
until_success vagrant ssh -c 'exit'
|
until_success vagrant ssh -c 'exit'
|
||||||
}
|
}
|
||||||
|
|
||||||
rollback() {
|
cleanup() {
|
||||||
vagrant sandbox rollback >/dev/null 2>&1 &&
|
vagrant ssh -c "
|
||||||
wait_for_vagrant &&
|
find . -not \\( \
|
||||||
vagrant rsync >/dev/null 2>&1
|
-path './.pyenv' -o \
|
||||||
|
-path './.pyenv/*' -o \
|
||||||
|
-path './.bashrc' -o \
|
||||||
|
-path './.profile' -o \
|
||||||
|
-path './.ssh' -o \
|
||||||
|
-path './.ssh/*' \
|
||||||
|
\\) -delete" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
echo "initializing."
|
echo "initializing."
|
||||||
vagrant sandbox on >/dev/null 2>&1
|
|
||||||
if ! vagrant ssh -c "pyenv local ${2}" >/dev/null 2>&1; then
|
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
|
if ! vagrant ssh -c "pyenv install -s ${2} && pyenv local ${2}" >/dev/null 2>&1; then
|
||||||
die "could not install python ${2}"
|
die "could not install python ${2}"
|
||||||
fi
|
fi
|
||||||
vagrant sandbox commit >/dev/null 2>&1
|
|
||||||
fi
|
fi
|
||||||
|
vagrant rsync >/dev/null 2>&1
|
||||||
tests_run=0
|
tests_run=0
|
||||||
tests_passed=0
|
tests_passed=0
|
||||||
tests_failed=0
|
tests_failed=0
|
||||||
|
@ -96,7 +95,7 @@ fail() {
|
||||||
run_test() {
|
run_test() {
|
||||||
tests_run=$((tests_run + 1))
|
tests_run=$((tests_run + 1))
|
||||||
printf '[%d/%d] (%s)\n' "${tests_run}" "${tests_total}" "${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
|
vagrant ssh -c "pyenv local ${2}" >/dev/null 2>&1
|
||||||
if vagrant ssh -c "cd /dotbot/test/tests && bash ${1}" 2>/dev/null; then
|
if vagrant ssh -c "cd /dotbot/test/tests && bash ${1}" 2>/dev/null; then
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue