From 01a940539126f70424052892a7dfe3db44d86a63 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Tue, 28 Nov 2017 08:38:04 -0500 Subject: [PATCH] Make ophaned editor test less flaky. Instead of having the editor sleep a short time, explicitly send it a signal to exit. --- tests/end2end/features/editor.feature | 5 ++-- tests/end2end/features/test_editor_bdd.py | 28 +++++++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/tests/end2end/features/editor.feature b/tests/end2end/features/editor.feature index 92de6ccdd..13e3deddc 100644 --- a/tests/end2end/features/editor.feature +++ b/tests/end2end/features/editor.feature @@ -116,14 +116,15 @@ Feature: Opening external editors Then the javascript message "text: foobar" should be logged Scenario: Spawning an editor and closing the tab - When I set up a fake editor returning "foo" after 1s + When I set up a fake editor that waits And I open data/editor.html And I run :click-element id qute-textarea And I wait for "Entering mode KeyMode.insert (reason: clicking input)" in the log And I run :open-editor And I set tabs.last_close to blank And I run :tab-close - Then the warning "Edited element was closed" should be shown + And I kill the waiting editor + Then the warning "Edited element vanished" should be shown @qtwebengine_todo: Caret mode is not implemented yet Scenario: Spawning an editor in caret mode diff --git a/tests/end2end/features/test_editor_bdd.py b/tests/end2end/features/test_editor_bdd.py index 0cd85a351..3421be88c 100644 --- a/tests/end2end/features/test_editor_bdd.py +++ b/tests/end2end/features/test_editor_bdd.py @@ -20,6 +20,8 @@ import sys import json import textwrap +import os +import signal import pytest_bdd as bdd bdd.scenarios('editor.feature') @@ -66,19 +68,31 @@ def set_up_editor_empty(quteproc, server, tmpdir): set_up_editor(quteproc, server, tmpdir, "") -@bdd.when(bdd.parsers.parse( - 'I set up a fake editor returning "{text}" after {t}s')) -def set_up_editor_delay(quteproc, server, tmpdir, text, t): +@bdd.when(bdd.parsers.parse('I set up a fake editor that waits')) +def set_up_editor_wait(quteproc, server, tmpdir): """Set up editor.command to a small python script inserting a text.""" + pidfile = tmpdir / 'editor_pid' script = tmpdir / 'script.py' script.write(textwrap.dedent(""" + import os import sys import time + import signal - time.sleep({t}) + with open('{pidfile}', 'w') as f: + f.write(str(os.getpid())) - with open(sys.argv[1], 'w', encoding='utf-8') as f: - f.write({text!r}) - """.format(text=text, t=t))) + signal.signal(signal.SIGUSR1, lambda s, f: sys.exit(0)) + + time.sleep(100) + """.format(pidfile=pidfile))) editor = json.dumps([sys.executable, str(script), '{}']) quteproc.set_setting('editor.command', editor) + + +@bdd.when(bdd.parsers.parse('I kill the waiting editor')) +def kill_editor_wait(quteproc, server, tmpdir): + """Kill the waiting editor.""" + pidfile = tmpdir / 'editor_pid' + pid = int(pidfile.read()) + os.kill(pid, signal.SIGUSR1)