Skip to content

Commit 244af08

Browse files
committed
database: Add basic-raft nixos-test
1 parent ce195c3 commit 244af08

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ venv.bak/
3737
# They can be nice to have for reference
3838
result*
3939
result*/
40+
# Also probably don't need the nixos-test repl history
41+
.nixos-test-history
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{ testers
2+
, lib
3+
# Adjust for more nodes
4+
, nPeers ? 3
5+
}:
6+
# see also:
7+
# https://nix.dev/tutorials/nixos/integration-testing-using-virtual-machines.html
8+
let
9+
peers = lib.genList (n: "peer${toString n}") nPeers;
10+
11+
raft-port = 3000;
12+
in
13+
testers.runNixOSTest {
14+
name = "null-db-basic-raft";
15+
16+
nodes = lib.genAttrs peers (_self: { });
17+
18+
defaults = { pkgs, ... }: {
19+
imports = [ ../../module.nix ];
20+
21+
config = {
22+
# Test-specific vm configuration
23+
virtualisation = {
24+
# Default is 1 - might need more for our workers
25+
cores = 2;
26+
memorySize = 512;
27+
# If you want to see ttys run the same stuff as stdout/stderr,
28+
# enable this
29+
graphics = false;
30+
};
31+
32+
# Interactive debugging
33+
environment.defaultPackages = [ pkgs.curl pkgs.bind.host ];
34+
35+
programs.null-db.enable = true;
36+
37+
services.null-db = {
38+
enable = true;
39+
openFirewall = true;
40+
args.encoding = "json";
41+
args.roster = lib.map (n: "${n}:${toString raft-port}") peers;
42+
inherit raft-port;
43+
};
44+
45+
# If you want verbose logging, you might break a bit of an
46+
# abstraction boundary:
47+
# systemd.services.null-db.serviceConfig.Environment =
48+
# "RUST_LOG=info";
49+
};
50+
};
51+
52+
testScript = { nodes }: ''
53+
start_all()
54+
55+
for peer in machines:
56+
peer.wait_for_unit("null-db.service")
57+
58+
peer0.wait_for_console_text("null-db.*Starting raft main loop", timeout=60)
59+
'';
60+
}

nix/overlay.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
final: prev: {
2-
null-db = final.callPackage ../database { };
2+
null-db = (final.callPackage ../database { }).overrideAttrs (o: {
3+
# passthru is a nixpkgs field that is reserved to only exist in
4+
# nix runtime but not end up in a derivation. passthru.tests is
5+
# one very common attribute.
6+
passthru.tests.basic-raft = final.callPackage ./nixos-tests/basic-raft { };
7+
});
38
}

0 commit comments

Comments
 (0)