-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrrr-demo.test.nix
114 lines (108 loc) · 3.68 KB
/
brrr-demo.test.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Copyright © 2024 Brrr Authors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Inspired by
# https://blakesmith.me/2024/03/02/running-nixos-tests-with-flakes.html
{ self, pkgs }:
# Distributed test across multiple VMs, so there’s still some room for bugs to
# creep into the actual demo. Both are nice to have so we should probably add a
# test that replicates the actual demo as closely as possible to catch any
# errors there.
pkgs.testers.runNixOSTest {
name = "brrr-test";
nodes.datastores = { config, pkgs, ... }: {
imports = [
# Not going to export and dogfood this--it’s just local only
./dynamodb.module.nix
];
services.redis.servers.main = {
enable = true;
port = 6379;
openFirewall = true;
bind = null;
logLevel = "debug";
settings.protected-mode = "no";
};
services.dynamodb = {
enable = true;
openFirewall = true;
};
};
nodes.server = { config, pkgs, ... }: {
imports = [
self.nixosModules.brrr-demo
];
networking.firewall.allowedTCPPorts = [ 8080 ];
services.brrr-demo = {
enable = true;
package = self.packages.${pkgs.system}.brrr-demo;
args = [ "server" ];
environment = {
BRRR_DEMO_LISTEN_HOST = "0.0.0.0";
BRRR_DEMO_REDIS_URL = "redis://datastores:6379";
AWS_DEFAULT_REGION = "foo";
AWS_ENDPOINT_URL = "http://datastores:8000";
AWS_ACCESS_KEY_ID = "foo";
AWS_SECRET_ACCESS_KEY = "bar";
};
};
};
nodes.worker = { config, pkgs, ... }: {
imports = [
self.nixosModules.brrr-demo
];
services.brrr-demo = {
enable = true;
package = self.packages.${pkgs.system}.brrr-demo;
args = [ "worker" ];
environment = {
BRRR_DEMO_REDIS_URL = "redis://datastores:6379";
AWS_DEFAULT_REGION = "foo";
AWS_ENDPOINT_URL = "http://datastores:8000";
AWS_ACCESS_KEY_ID = "foo";
AWS_SECRET_ACCESS_KEY = "bar";
};
};
};
# Separate node entirely just for the actual testing
nodes.tester = { config, pkgs, ... }: let
test-script = pkgs.writeShellApplication {
name = "test-brrr-demo";
# 😂
text = ''
eval "$(curl --fail -sSL "http://server:8080/hello?greetee=Jim" | jq '. == {status: "ok", result: "Hello, Jim!"}')"
eval "$(curl --fail -sSL "http://server:8080/fib_and_print?n=6&salt=abcd" | jq '. == {status: "ok", result: 8}')"
'';
};
in {
environment.systemPackages = [
test-script
] ++ (with pkgs; [
curl
jq
]);
};
globalTimeout = 2 * 60;
testScript = ''
# Start first because it's a dependency
datastores.wait_for_unit("default.target")
# Server initializes the stores
server.wait_for_unit("default.target")
worker.wait_for_unit("default.target")
tester.wait_for_unit("default.target")
server.wait_for_open_port(8080)
tester.wait_until_succeeds("curl --fail -sSL -X POST 'http://server:8080/hello?greetee=Jim'")
tester.wait_until_succeeds("curl --fail -sSL -X POST 'http://server:8080/fib_and_print?n=6&salt=abcd'")
tester.wait_until_succeeds("test-brrr-demo")
'';
}