diff options
author | Sawjan Gurung <saw.jan.grg3e@gmail.com> | 2022-10-24 13:33:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-24 13:33:29 +0300 |
commit | db885317895f219421ee1a9ea2d35bb391b886f4 (patch) | |
tree | a80efe84b4d1fd46e6346071d1266a2e54a82af3 /test | |
parent | 214ea7216df9c2225123b583ac49d563fe44cdb5 (diff) |
[gui-tests] Remove unnecessary waits (#10208)
Diffstat (limited to 'test')
-rw-r--r-- | test/gui/shared/scripts/bdd_hooks.py | 43 | ||||
-rw-r--r-- | test/gui/shared/scripts/helpers/SetupClientHelper.py | 2 | ||||
-rw-r--r-- | test/gui/shared/steps/steps.py | 112 |
3 files changed, 68 insertions, 89 deletions
diff --git a/test/gui/shared/scripts/bdd_hooks.py b/test/gui/shared/scripts/bdd_hooks.py index 3762ae18e..5acdf4318 100644 --- a/test/gui/shared/scripts/bdd_hooks.py +++ b/test/gui/shared/scripts/bdd_hooks.py @@ -30,6 +30,10 @@ previousErrorResultCount = 0 # socket messages socket_messages = [] +# Whether wait has been made or not after account is set up +# This is useful for waiting only for the first time +waitedAfterSync = False + @OnScenarioStart def hook(context): @@ -143,6 +147,8 @@ def hook(context): # determines if the test scenario failed or not +# 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. def scenarioFailed(): global previousFailResultCount global previousErrorResultCount @@ -152,20 +158,40 @@ def scenarioFailed(): ) +def isAppKilled(pid): + if os.path.isdir('/proc/{}'.format(pid)): + # process is still running + # wait 100ms before checking again + snooze(0.1) + return False + return True + + +def waitUntilAppIsKilled(context, pid=0): + timeout = context.userData['minSyncTimeout'] * 1000 + killed = waitFor( + lambda: isAppKilled(pid), + timeout, + ) + if not killed: + test.log( + "Application was not terminated within {} milliseconds".format(timeout) + ) + + @OnScenarioEnd def hook(context): + global socketConnect, socket_messages, waitedAfterSync, previousFailResultCount, previousErrorResultCount, waitedAfterSync + + # reset waited after sync flag + waitedAfterSync = False + # close socket connection and clear messages - global socketConnect, socket_messages socket_messages.clear() 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 - global previousErrorResultCount - # capture a screenshot if there is error or test failure in the current scenario execution if scenarioFailed() and os.getenv('CI'): @@ -191,9 +217,10 @@ def hook(context): # Detach (i.e. potentially terminate) all AUTs at the end of a scenario for ctx in applicationContextList(): + # get pid before detaching + pid = ctx.pid ctx.detach() - # ToDo wait smarter till the app died - snooze(context.userData['minSyncTimeout']) + waitUntilAppIsKilled(context, pid) # delete local files/folders for filename in os.listdir(context.userData['clientRootSyncPath']): diff --git a/test/gui/shared/scripts/helpers/SetupClientHelper.py b/test/gui/shared/scripts/helpers/SetupClientHelper.py index 0ae6ca502..0cc1bd7b2 100644 --- a/test/gui/shared/scripts/helpers/SetupClientHelper.py +++ b/test/gui/shared/scripts/helpers/SetupClientHelper.py @@ -72,8 +72,6 @@ def startClient(context): + context.userData['clientConfigDir'] ) - squish.snooze(1) - def getPollingInterval(): pollingInterval = '''[ownCloud] diff --git a/test/gui/shared/steps/steps.py b/test/gui/shared/steps/steps.py index ca274773a..1a8021147 100644 --- a/test/gui/shared/steps/steps.py +++ b/test/gui/shared/steps/steps.py @@ -538,35 +538,13 @@ def step(context, type, resource): waitForFileOrFolderToSync(context, resource, type) -@Given( - 'user "|any|" has created a file "|any|" with the following content inside the sync folder' -) -def step(context, username, filename): - createFile(context, filename, username) - - @When( 'user "|any|" creates a file "|any|" with the following content inside the sync folder' ) def step(context, username, filename): - createFile(context, filename, username) - - -def createFile(context, filename, username=None): fileContent = "\n".join(context.multiLineText) - syncPath = None - if username: - syncPath = getUserSyncPath(context, username) - else: - syncPath = context.userData['currentUserSyncPath'] - - # A file is scheduled to be synced but is marked as ignored for 5 seconds. And if we try to sync it, it will fail. So we need to wait for 5 seconds. - # https://github.com/owncloud/client/issues/9325 - snooze(context.userData['minSyncTimeout']) - - f = open(join(syncPath, filename), "w") - f.write(fileContent) - f.close() + syncPath = getUserSyncPath(context, username) + waitAndWriteFile(context, join(syncPath, filename), fileContent) @When('user "|any|" creates a folder "|any|" inside the sync folder') @@ -714,9 +692,9 @@ def step(context): @Given('the user has changed the content of local file "|any|" to:') def step(context, filename): fileContent = "\n".join(context.multiLineText) - f = open(context.userData['currentUserSyncPath'] + filename, "w") - f.write(fileContent) - f.close() + waitAndWriteFile( + join(context.userData['currentUserSyncPath'], filename), fileContent + ) @When('the user resumes the file sync on the client') @@ -1051,12 +1029,12 @@ def step(context, username): enterUserPassword = EnterPassword() enterUserPassword.enterPassword(password) + # wait for files to sync + waitForInitialSyncToComplete(context) + @Then('user "|any|" should be connect to the client-UI') def step(context, username): - # TODO: find some way to dynamically to check if files are synced - # It might take some time for all files to sync and connect to ther server - snooze(context.userData['minSyncTimeout']) isUserSignedIn(context, username) @@ -1145,15 +1123,31 @@ def step(context, resource, group): sharingDialog.selectCollaborator(group, True) -def overwriteFile(resource, content): +# performing actions immediately after completing the sync from the server does not work +# The test should wait for a while before performing the action +# issue: https://github.com/owncloud/client/issues/8832 +def waitForClientToBeReady(context): + global waitedAfterSync + if not waitedAfterSync: + snooze(context.userData['minSyncTimeout']) + waitedAfterSync = True + + +def writeFile(resource, content): f = open(resource, "w") f.write(content) f.close() -def tryToOverwriteFile(context, resource, content): +def waitAndWriteFile(context, path, content): + waitForClientToBeReady(context) + writeFile(path, content) + + +def waitAndTryToWriteFile(context, resource, content): + waitForClientToBeReady(context) try: - overwriteFile(resource, content) + writeFile(resource, content) except: pass @@ -1162,38 +1156,20 @@ def tryToOverwriteFile(context, resource, content): def step(context, resource, content): print("starting file overwrite") resource = join(context.userData['currentUserSyncPath'], resource) - - # overwriting the file immediately after it has been synced from the server seems to have some problem. - # The client does not see the change although the changes have already been made thus we are having a race condition - # So for now we add 5sec static wait - # an issue https://github.com/owncloud/client/issues/8832 has been created for it - snooze(context.userData['minSyncTimeout']) - - overwriteFile(resource, content) - + waitAndWriteFile(context, resource, content) print("file has been overwritten") @When('the user tries to overwrite the file "|any|" with content "|any|"') def step(context, resource, content): resource = context.userData['currentUserSyncPath'] + resource - # overwriting the file immediately after it has been synced from the server seems to have some problem. - # The client does not see the change although the changes have already been made thus we are having a race condition - # So for now we add 5sec static wait - # an issue https://github.com/owncloud/client/issues/8832 has been created for it - snooze(context.userData['minSyncTimeout']) - tryToOverwriteFile(context, resource, content) + waitAndTryToWriteFile(context, resource, content) @When('user "|any|" tries to overwrite the file "|any|" with content "|any|"') def step(context, user, resource, content): resource = getResourcePath(context, resource, user) - # overwriting the file immediately after it has been synced from the server seems to have some problem. - # The client does not see the change although the changes have already been made thus we are having a race condition - # So for now we add 5sec static wait - # an issue https://github.com/owncloud/client/issues/8832 has been created for it - snooze(context.userData['minSyncTimeout']) - tryToOverwriteFile(context, resource, content) + waitAndTryToWriteFile(context, resource, content) def enableVFSSupport(vfsBtnText): @@ -1278,9 +1254,7 @@ def step(context, errorMsg): @When(r'the user deletes the (file|folder) "([^"]*)"', regexp=True) def step(context, itemType, resource): - # deleting the file immediately after it has been synced from the server seems to have some problem. - # issue: https://github.com/owncloud/client/issues/8832 - snooze(context.userData['minSyncTimeout']) + waitForClientToBeReady(context) resourcePath = sanitizePath(context.userData['currentUserSyncPath'] + resource) if itemType == 'file': @@ -1530,35 +1504,15 @@ def step(context): test.xvp("VP_VFS_enabled") -@Given('user "|any|" has created the following files inside the sync folder:') -def step(context, username): - ''' - Create files without any content - ''' - syncPath = getUserSyncPath(context, username) - - # A file is scheduled to be synced but is marked as ignored for 5 seconds. And if we try to sync it, it will fail. So we need to wait for 5 seconds. - # https://github.com/owncloud/client/issues/9325 - snooze(context.userData['minSyncTimeout']) - - for row in context.table[1:]: - filename = syncPath + row[0] - f = open(join(syncPath, filename), "w") - f.close() - - @When('user "|any|" creates the following files inside the sync folder:') def step(context, username): syncPath = getUserSyncPath(context, username) - # A file is scheduled to be synced but is marked as ignored for 5 seconds. And if we try to sync it, it will fail. So we need to wait for 5 seconds. - # https://github.com/owncloud/client/issues/9325 - snooze(context.userData['minSyncTimeout']) + waitForClientToBeReady(context) for row in context.table[1:]: filename = syncPath + row[0] - f = open(join(syncPath, filename), "w") - f.close() + writeFile(join(syncPath, filename), '') @Given( |