From 69d0e9ee5482f3dbe84f01c0e205477387f2c99d Mon Sep 17 00:00:00 2001 From: Sawjan Gurung Date: Wed, 7 Sep 2022 14:07:16 +0545 Subject: [PATCH] open only one socket connection per test scenario (#9948) --- test/gui/shared/scripts/bdd_hooks.py | 6 ++++++ test/gui/shared/steps/steps.py | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/test/gui/shared/scripts/bdd_hooks.py b/test/gui/shared/scripts/bdd_hooks.py index 63c1e8e84d5..1466bd659b7 100644 --- a/test/gui/shared/scripts/bdd_hooks.py +++ b/test/gui/shared/scripts/bdd_hooks.py @@ -151,6 +151,12 @@ def scenarioFailed(): @OnScenarioEnd def hook(context): + # close socket connection + global socketConnect + if socketConnect: + socketConnect.connected = False + socketConnect._sock.close() + # Currently, this workaround is needed because we cannot find out a way to determine the pass/fail status of currently running test scenario. # And, resultCount("errors") and resultCount("fails") return the total number of error/failed test scenarios of a test suite. global previousFailResultCount diff --git a/test/gui/shared/steps/steps.py b/test/gui/shared/steps/steps.py index b65b8546313..b8e0c000751 100644 --- a/test/gui/shared/steps/steps.py +++ b/test/gui/shared/steps/steps.py @@ -27,7 +27,7 @@ # to switch from the built-in interpreter see https://kb.froglogic.com/squish/howto/using-external-python-interpreter-squish-6-6/ # if the IDE fails to reference the script, add the folder in Edit->Preferences->PyDev->Interpreters->Libraries sys.path.append(os.path.realpath('../../../shell_integration/nautilus/')) -import syncstate +from syncstate import SocketConnect import functools @@ -138,11 +138,18 @@ def step(context): newAccount.addAccountCredential(context) +def getSocketConnection(): + global socketConnect + if not socketConnect or not socketConnect.connected: + socketConnect = SocketConnect() + return socketConnect + + # Using socket API to check file sync status def hasSyncStatus(type, itemName, status): if type != 'FILE' and type != 'FOLDER': raise Exception("type must be 'FILE' or 'FOLDER'") - socketConnect = syncstate.SocketConnect() + socketConnect = getSocketConnection() socketConnect.sendCommand("RETRIEVE_" + type + "_STATUS:" + itemName + "\n") if not socketConnect.read_socket_data_with_timeout(0.1): @@ -278,7 +285,7 @@ def sanitizePath(path): def shareResource(resource): - socketConnect = syncstate.SocketConnect() + socketConnect = getSocketConnection() socketConnect.sendCommand("SHARE:" + resource + "\n") if not socketConnect.read_socket_data_with_timeout(0.1): return False @@ -372,7 +379,7 @@ def collaboratorShouldBeListed( context, receiver, resource, permissions, receiverCount=0 ): resource = getResourcePath(context, resource) - socketConnect = syncstate.SocketConnect() + socketConnect = getSocketConnection() socketConnect.sendCommand("SHARE:" + resource + "\n") permissionsList = permissions.split(',')