diff options
author | Anish Athalye <me@anishathalye.com> | 2018-03-27 20:56:55 -0400 |
---|---|---|
committer | Anish Athalye <me@anishathalye.com> | 2018-03-27 20:56:55 -0400 |
commit | b7022f4abb7ff9a6b816ecb16038ff5b2f6559fb (patch) | |
tree | 89f2f4857a25f04260db18d315074f3f103ce24f /test | |
parent | 9ff1db16726afaee890092c20b0a23d7c5d35d1d (diff) |
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.
Diffstat (limited to 'test')
-rw-r--r-- | test/README.md | 28 | ||||
-rw-r--r-- | test/driver-lib.bash | 25 |
2 files changed, 18 insertions, 35 deletions
diff --git a/test/README.md b/test/README.md index e553936..993a753 100644 --- a/test/README.md +++ b/test/README.md @@ -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/ diff --git a/test/driver-lib.bash b/test/driver-lib.bash index 56a0740..02a71a5 100644 --- a/test/driver-lib.bash +++ b/test/driver-lib.bash @@ -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 |