nixpkgs/nixos/tests/centrifugo.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

86 lines
2.4 KiB
Nix

let
redisPort = 6379;
centrifugoPort = 8080;
nodes = [
"centrifugo1"
"centrifugo2"
"centrifugo3"
];
in
{ lib, ... }:
{
name = "centrifugo";
meta.maintainers = [ lib.maintainers.tie ];
nodes = lib.listToAttrs (
lib.imap0 (index: name: {
inherit name;
value =
{ config, ... }:
{
services.centrifugo = {
enable = true;
settings = {
inherit name;
port = centrifugoPort;
# See https://centrifugal.dev/docs/server/engines#redis-sharding
engine = "redis";
# Connect to local Redis shard via Unix socket.
redis_address =
let
toRedisAddresses = map (name: "${name}:${toString redisPort}");
in
toRedisAddresses (lib.take index nodes)
++ [
"unix://${config.services.redis.servers.centrifugo.unixSocket}"
]
++ toRedisAddresses (lib.drop (index + 1) nodes);
usage_stats_disable = true;
api_insecure = true;
};
extraGroups = [
config.services.redis.servers.centrifugo.user
];
};
services.redis.servers.centrifugo = {
enable = true;
bind = null; # all interfaces
port = redisPort;
openFirewall = true;
settings.protected-mode = false;
};
};
}) nodes
);
testScript = ''
import json
redisPort = ${toString redisPort}
centrifugoPort = ${toString centrifugoPort}
start_all()
for machine in machines:
machine.wait_for_unit("redis-centrifugo.service")
machine.wait_for_open_port(redisPort)
for machine in machines:
machine.wait_for_unit("centrifugo.service")
machine.wait_for_open_port(centrifugoPort)
# See https://centrifugal.dev/docs/server/server_api#info
def list_nodes(machine):
curl = "curl --fail-with-body --silent"
body = "{}"
resp = json.loads(machine.succeed(f"{curl} -d '{body}' http://localhost:{centrifugoPort}/api/info"))
return resp["result"]["nodes"]
machineNames = {m.name for m in machines}
for machine in machines:
nodes = list_nodes(machine)
assert len(nodes) == len(machines)
nodeNames = {n['name'] for n in nodes}
assert machineNames == nodeNames
'';
}