Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cups vm tests: fix race condition, add more tests #338193

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,10 @@ in {
predictable-interface-names = handleTest ./predictable-interface-names.nix {};
pretalx = runTest ./web-apps/pretalx.nix;
pretix = runTest ./web-apps/pretix.nix;
printing-socket = handleTest ./printing.nix { socket = true; };
printing-service = handleTest ./printing.nix { socket = false; };
printing-socket = handleTest ./printing.nix { socket = true; listenTcp = true; };
printing-service = handleTest ./printing.nix { socket = false; listenTcp = true; };
printing-socket-notcp = handleTest ./printing.nix { socket = true; listenTcp = false; };
printing-service-notcp = handleTest ./printing.nix { socket = false; listenTcp = false; };
private-gpt = handleTest ./private-gpt.nix {};
privatebin = runTest ./privatebin.nix;
privoxy = handleTest ./privoxy.nix {};
Expand Down
16 changes: 11 additions & 5 deletions nixos/tests/printing.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
import ./make-test-python.nix (
{ pkgs
, socket ? true # whether to use socket activation
, listenTcp ? true # whether to open port 631 on client
, ...
}:

let
inherit (pkgs) lib;
in

{
name = "printing";
meta = with pkgs.lib.maintainers; {
meta = with lib.maintainers; {
maintainers = [ domenkozar matthewbauer ];
};

Expand All @@ -35,9 +40,10 @@ import ./make-test-python.nix (
}];
};

nodes.client = { ... }: {
nodes.client = { lib, ... }: {
services.printing.enable = true;
services.printing.startWhenNeeded = socket;
services.printing.listenAddresses = lib.mkIf (!listenTcp) [];
# Add printer to the client as well, via IPP.
hardware.printers.ensurePrinters = [{
name = "DeskjetRemote";
Expand All @@ -54,16 +60,16 @@ import ./make-test-python.nix (
start_all()

with subtest("Make sure that cups is up on both sides and printers are set up"):
server.wait_for_unit("cups.${if socket then "socket" else "service"}")
client.wait_for_unit("cups.${if socket then "socket" else "service"}")
server.wait_for_unit("ensure-printers.service")
client.wait_for_unit("ensure-printers.service")

assert "scheduler is running" in client.succeed("lpstat -r")

with subtest("UNIX socket is used for connections"):
assert "/var/run/cups/cups.sock" in client.succeed("lpstat -H")

with subtest("HTTP server is available too"):
client.succeed("curl --fail http://localhost:631/")
${lib.optionalString listenTcp ''client.succeed("curl --fail http://localhost:631/")''}
client.succeed(f"curl --fail http://{server.name}:631/")
server.fail(f"curl --fail --connect-timeout 2 http://{client.name}:631/")

Expand Down
3 changes: 3 additions & 0 deletions pkgs/misc/cups/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ stdenv.mkDerivation rec {

passthru.tests = {
inherit (nixosTests)
cups-pdf
printing-service
printing-socket
printing-service-notcp
printing-socket-notcp
;
};

Expand Down