1.1 NixOS integration tests: whole networks of VMs on your laptop
Lesson 1 of 3 · 22:06
Video chapters
-
0:00 Introduction to NixOS test driver
-
1:35 Manuals, repository, and available features
-
3:56 Ping test: VMs, containers, and interactive mode
-
10:11 Graphical browser test with screenshots
-
16:48 BitTorrent network test and large test suite
Transcript
Introduction to NixOS test driver
0:00 So this video is a little whirlwind tour about the capabilities of NixOS integration test driver, which is, in my opinion, one of the core features or killer features of NixOS. Because it makes it really easy to say, okay, let's spin up, I don't know, five VMs with different features, like, let's say your product in the customer network with whatever other services where it kind of is embedded and works with them and what you can do is run that inside the sandbox, like spin up a sandbox, spin up five NixOS VMs that kind of stimulate each other and after a minute or an hour, tear them down again and say, okay, my product worked or it didn't and have that run on your developer's desktop like every day multiple times.
0:48 There's no faster, no better feedback loop for your end to end tests, I would argue. And let's have a look at what it does. So the first thing that I want you to know is that on nixos.org/manual/nixos, there's the manual about NixOS tests. This reads relatively boring, it's complete, but with this video and the other manual, I want to show you how to hold it, like what can you expect from it, how do you even start and stuff like that.
1:18 So the NixOS test driver manual, which is on applicative.systems/nixos test driver manual, I'm linking to it in the video description. That shows you everything that you need to know on top of the normal manual. So we link to it a lot anyway. So the official NixOS manual is the source for everything, it's always fresh.
Sign in for the full transcript.
About this lesson
A NixOS integration test starts several virtual machines, puts them on networks, runs a script across all of them, and destroys them again. It happens inside a build sandbox, on the same laptop you write code on, and it happens identically on your CI because it is the same derivation. This demo is a tour of the NixOS test driver: what it can do, and what it feels like to work with.
In this video
- Two machines and one small file: the shortest NixOS integration test there is, and what the grey and green lines in the log are telling you
- Booting both VMs, waiting for the network and pinging: how many seconds that costs, and the one word you swap to make it several times faster
- Interactive mode: the machines pop up on your desktop and you get a Python prompt to drive them by hand while you are still figuring out what to test
- A graphical test that starts Firefox, waits for a page to appear and checks what is on it, without ever touching the browser from inside
- A BitTorrent test with two clients, a tracker and a router doing NAT: a whole home network in roughly 50 lines, and a firewall that opens a port for itself while the test runs
After this lesson
You can tell whether your own end to end tests belong in this and roughly what moving them would cost. You also know where the thousand or so existing tests live, which is the best place to steal from before writing your first one.
Links:
- https://applicative.systems/nixos-test-driver-manual
- Examples repository used in this video: https://github.com/applicative-systems/nixos-test-driver-manual
- Official NixOS tests manual: https://nixos.org/manual/nixos/stable/#sec-nixos-tests