about summary refs log tree commit diff
path: root/nixos/tests/beanstalkd.nix
blob: 518f018408ad89d6f3cb53203bf4f8ff19824fcb (plain) (blame)
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
import ./make-test-python.nix ({ pkgs, lib, ... }:

let
  pythonEnv = pkgs.python3.withPackages (p: [p.beanstalkc]);

  produce = pkgs.writeScript "produce.py" ''
    #!${pythonEnv.interpreter}
    import beanstalkc

    queue = beanstalkc.Connection(host='localhost', port=11300, parse_yaml=False);
    queue.put(b'this is a job')
    queue.put(b'this is another job')
  '';

  consume = pkgs.writeScript "consume.py" ''
    #!${pythonEnv.interpreter}
    import beanstalkc

    queue = beanstalkc.Connection(host='localhost', port=11300, parse_yaml=False);

    job = queue.reserve(timeout=0)
    print(job.body.decode('utf-8'))
    job.delete()
  '';

in
{
  name = "beanstalkd";
  meta.maintainers = [ lib.maintainers.aanderse ];

  nodes.machine =
    { ... }:
    { services.beanstalkd.enable = true;
    };

  testScript = ''
    start_all()

    machine.wait_for_unit("beanstalkd.service")

    machine.succeed("${produce}")
    assert "this is a job\n" == machine.succeed(
        "${consume}"
    )
    assert "this is another job\n" == machine.succeed(
        "${consume}"
    )
  '';
})