3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #72835 from tfc/nixos-integration-test-ports

Nixos integration test ports
This commit is contained in:
worldofpeace 2019-11-07 01:05:36 +00:00 committed by GitHub
commit 3780b9e69c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 23 deletions

View file

@ -4,7 +4,9 @@ from contextlib import contextmanager
from xml.sax.saxutils import XMLGenerator
import _thread
import atexit
import json
import os
import ptpython.repl
import pty
import queue
import re
@ -15,7 +17,6 @@ import sys
import tempfile
import time
import unicodedata
import ptpython.repl
CHAR_TO_KEY = {
"A": "shift-a",
@ -344,6 +345,18 @@ class Machine:
)
return self.execute("systemctl {}".format(q))
def require_unit_state(self, unit, require_state="active"):
with self.nested(
"checking if unit {} has reached state '{}'".format(unit, require_state)
):
info = self.get_unit_info(unit)
state = info["ActiveState"]
if state != require_state:
raise Exception(
"Expected unit {} to to be in state ".format(unit)
+ "'active' but it is in state {}".format(state)
)
def execute(self, command):
self.connect()
@ -642,6 +655,27 @@ class Machine:
if status == 0:
return
def get_window_names(self):
return self.succeed(
r"xwininfo -root -tree | sed 's/.*0x[0-9a-f]* \"\([^\"]*\)\".*/\1/; t; d'"
).splitlines()
def wait_for_window(self, regexp):
pattern = re.compile(regexp)
def window_is_visible(last_try):
names = self.get_window_names()
if last_try:
self.log(
"Last chance to match {} on the window list,".format(regexp)
+ " which currently contains: "
+ ", ".join(names)
)
return any(pattern.search(name) for name in names)
with self.nested("Waiting for a window to appear"):
retry(window_is_visible)
def sleep(self, secs):
time.sleep(secs)

View file

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: {
import ./make-test-python.nix ({ pkgs, ... }: {
name = "firefox";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ eelco shlevy ];
@ -11,19 +11,27 @@ import ./make-test.nix ({ pkgs, ... }: {
environment.systemPackages = [ pkgs.firefox pkgs.xdotool ];
};
testScript =
''
$machine->waitForX;
$machine->execute("xterm -e 'firefox file://${pkgs.valgrind.doc}/share/doc/valgrind/html/index.html' &");
$machine->waitForWindow(qr/Valgrind/);
$machine->sleep(40); # wait until Firefox has finished loading the page
$machine->execute("xdotool key space"); # do I want to make Firefox the
# default browser? I just want to close the dialog
$machine->sleep(2); # wait until Firefox hides the default browser window
$machine->execute("xdotool key F12");
$machine->sleep(10); # wait until Firefox draws the developer tool panel
$machine->succeed("xwininfo -root -tree | grep Valgrind");
$machine->screenshot("screen");
testScript = ''
machine.wait_for_x()
with subtest("wait until Firefox has finished loading the Valgrind docs page"):
machine.execute(
"xterm -e 'firefox file://${pkgs.valgrind.doc}/share/doc/valgrind/html/index.html' &"
)
machine.wait_for_window("Valgrind")
machine.sleep(40)
with subtest("Close default browser prompt"):
machine.execute("xdotool key space")
with subtest("Hide default browser window"):
machine.sleep(2)
machine.execute("xdotool key F12")
with subtest("wait until Firefox draws the developer tool panel"):
machine.sleep(10)
machine.succeed("xwininfo -root -tree | grep Valgrind")
machine.screenshot("screen")
'';
})

View file

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... } : let
import ./make-test-python.nix ({ pkgs, ... } : let
runWithOpenSSL = file: cmd: pkgs.runCommand file {
@ -55,13 +55,17 @@ in {
};
testScript = ''
startAll;
$serverpostgres->waitForUnit("matrix-synapse.service");
$serverpostgres->waitUntilSucceeds("curl -L --cacert ${ca_pem} https://localhost:8448/");
$serverpostgres->requireActiveUnit("postgresql.service");
$serversqlite->waitForUnit("matrix-synapse.service");
$serversqlite->waitUntilSucceeds("curl -L --cacert ${ca_pem} https://localhost:8448/");
$serversqlite->mustSucceed("[ -e /var/lib/matrix-synapse/homeserver.db ]");
start_all()
serverpostgres.wait_for_unit("matrix-synapse.service")
serverpostgres.wait_until_succeeds(
"curl -L --cacert ${ca_pem} https://localhost:8448/"
)
serverpostgres.require_unit_state("postgresql.service")
serversqlite.wait_for_unit("matrix-synapse.service")
serversqlite.wait_until_succeeds(
"curl -L --cacert ${ca_pem} https://localhost:8448/"
)
serversqlite.succeed("[ -e /var/lib/matrix-synapse/homeserver.db ]")
'';
})