Skip to content

Commit

Permalink
properly wait for AUT context to get removed
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Nov 7, 2023
1 parent 04d1091 commit 4478fd2
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 62 deletions.
25 changes: 2 additions & 23 deletions test/gui/shared/scripts/bdd_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from helpers.StacktraceHelper import getCoredumps, generateStacktrace
from helpers.SyncHelper import closeSocketConnection, clearWaitedAfterSync
from helpers.SpaceHelper import delete_project_spaces
from helpers.SetupClientHelper import wait_until_app_killed
from helpers.ConfigHelper import (
init_config,
get_config,
Expand Down Expand Up @@ -116,27 +117,6 @@ 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(pid=0):
timeout = get_config('minSyncTimeout') * 1000
killed = waitFor(
lambda: isAppKilled(pid),
timeout,
)
if not killed:
test.log(
"Application was not terminated within {} milliseconds".format(timeout)
)


# runs after every scenario
# Order: 1
# cleanup spaces
Expand All @@ -157,7 +137,6 @@ def hook(context):

# capture a screenshot if there is error or test failure in the current scenario execution
if scenarioFailed() and os.getenv('CI'):

import gi

gi.require_version('Gtk', '3.0')
Expand All @@ -183,7 +162,7 @@ def hook(context):
# get pid before detaching
pid = ctx.pid
ctx.detach()
waitUntilAppIsKilled(pid)
wait_until_app_killed(pid)

# delete local files/folders
for filename in os.listdir(get_config('clientRootSyncPath')):
Expand Down
25 changes: 23 additions & 2 deletions test/gui/shared/scripts/helpers/SetupClientHelper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from urllib.parse import urlparse
import squish
from os import makedirs
import squish, test
from os import makedirs, path
from os.path import exists, join
from helpers.SpaceHelper import get_space_id
from helpers.ConfigHelper import get_config, set_config
Expand Down Expand Up @@ -152,3 +152,24 @@ def setUpClient(username, displayName, space="Personal"):

startClient()
listenSyncStatusForItem(syncPath)


def is_app_killed(pid):
if path.isdir('/proc/{}'.format(pid)):
# process is still running
# wait 100ms before checking again
squish.snooze(0.1)
return False
return True


def wait_until_app_killed(pid=0):
timeout = 5 * 1000
killed = squish.waitFor(
lambda: is_app_killed(pid),
timeout,
)
if not killed:
test.log(
"Application was not terminated within {} milliseconds".format(timeout)
)
1 change: 0 additions & 1 deletion test/gui/shared/scripts/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@
o_folderList_Personal_QModelIndex = {"column": 0, "container": stack_folderList_QTreeView, "text": "Personal", "type": "QModelIndex"}
add_Folder_Sync_Connection_tableView_QTableView = {"name": "tableView","type": "QTableView","visible": 1,"window": add_Folder_Sync_Connection_OCC_FolderWizard}
stack_scrollArea_QScrollArea = {"container": settings_stack_QStackedWidget, "name": "scrollArea", "type": "QScrollArea", "visible": 1}
quit_ownCloud_QMessageBox = {"type": "QMessageBox", "unnamed": 1, "visible": 1, "windowTitle": "Quit ownCloud"}
25 changes: 24 additions & 1 deletion test/gui/shared/scripts/pageObjects/AccountSetting.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ class AccountSetting:
"type": "OCC::LoginRequiredDialog",
"visible": 1,
}
ACCOUNT_LOADING = {
"window": names.settings_OCC_SettingsDialog,
"name": "loadingPage",
"type": "QWidget",
"visible": 0,
}

@staticmethod
def accountAction(action):
Expand Down Expand Up @@ -136,13 +142,30 @@ def waitUntilAccountIsConnected(displayname, server, timeout=5000):
)

if not result:
raise Exception(
raise TimeoutError(
"Timeout waiting for the account to be connected for "
+ str(timeout)
+ " milliseconds"
)
return result

@staticmethod
def wait_until_sync_folder_is_configured(timeout=5000):
result = squish.waitFor(
lambda: not squish.waitForObjectExists(
AccountSetting.ACCOUNT_LOADING
).visible,
timeout,
)

if not result:
raise TimeoutError(
"Timeout waiting for sync folder to be connected for "
+ str(timeout)
+ " milliseconds"
)
return result

@staticmethod
def confirmRemoveAllFiles():
squish.clickButton(squish.waitForObject(AccountSetting.REMOVE_ALL_FILES))
Expand Down
18 changes: 14 additions & 4 deletions test/gui/shared/scripts/pageObjects/Toolbar.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import squish
import names
from helpers.SetupClientHelper import wait_until_app_killed


class Toolbar:
QUIT_OWNCLOUD_YES_QPUSHBUTTON = {
QUIT_CONFIRMATION_DIALOG = {
"type": "QMessageBox",
"unnamed": 1,
"visible": 1,
"windowTitle": "Quit ownCloud",
}
CONFIRM_QUIT_BUTTON = {
"text": "Yes",
"type": "QPushButton",
"unnamed": 1,
"visible": 1,
"window": names.quit_ownCloud_QMessageBox,
"window": QUIT_CONFIRMATION_DIALOG,
}

@staticmethod
Expand Down Expand Up @@ -50,4 +56,8 @@ def quitOwncloud():
squish.clickButton(
squish.waitForObject(Toolbar.getItemSelector("Quit ownCloud"))
)
squish.clickButton(squish.waitForObject(Toolbar.QUIT_OWNCLOUD_YES_QPUSHBUTTON))
squish.clickButton(squish.waitForObject(Toolbar.CONFIRM_QUIT_BUTTON))
for ctx in squish.applicationContextList():
pid = ctx.pid
ctx.detach()
wait_until_app_killed(pid)
26 changes: 8 additions & 18 deletions test/gui/shared/steps/account_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def step(context):
startClient()


@When('the user starts the client')
def step(context):
startClient()


@When('the user opens the add-account dialog')
def step(context):
Toolbar.openNewAccountSetup()
Expand All @@ -76,12 +81,6 @@ def step(context):
AccountConnectionWizard.addAccount(account_details)


@When('the user starts the client')
def step(context):
squish.snooze(2)
startClient()


@When(r'^the user adds (the first|another) account with$', regexp=True)
def step(context, accountType):
if accountType == 'another':
Expand Down Expand Up @@ -148,11 +147,8 @@ def step(context, username, password):
def step(context, username):
displayname = getDisplaynameForUser(username)
server = get_config('localBackendUrl')
test.compare(
AccountSetting.waitUntilAccountIsConnected(displayname, server),
True,
"User '%s' is connected" % username,
)
AccountSetting.waitUntilAccountIsConnected(displayname, server)
AccountSetting.wait_until_sync_folder_is_configured()


@When('the user removes the connection for user "|any|" and host |any|')
Expand Down Expand Up @@ -247,12 +243,6 @@ def step(context):
test.compare(True, AccountSetting.isLogDialogVisible(), "Log dialog is opened")


@Given('the user has added the following account with oauth2 enabled:')
def step(context):
AccountConnectionWizard.addAccountWithOauth2(context)
# squish.snooze(1)


@When('the user adds the following account with oauth2 enabled:')
def step(context):
AccountConnectionWizard.addAccountWithOauth2(context)
Expand Down Expand Up @@ -284,6 +274,6 @@ def step(context, username):
raise Exception("oidc re-login failed")


@Given("the user has quitted the client")
@When("the user quits the client")
def step(context):
Toolbar.quitOwncloud()
19 changes: 6 additions & 13 deletions test/gui/tst_loginLogout/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,15 @@ Feature: Logout users
Scenario: login after loggin out with oauth2 enabled
Given app "oauth2" has been "enabled" in the server
And the user has started the client
And the user has added the following account with oauth2 enabled:
When the user adds the following account with oauth2 enabled:
| server | %local_server% |
| user | Alice |
| password | 1234 |
And the user "Alice" has logged out of the client-UI
Then user "Alice" should be connect to the client-UI
When the user "Alice" logs out of the client-UI
Then user "Alice" should be signed out
When user "Alice" logs in with oauth2 to the client-UI
Then user "Alice" should be connect to the client-UI

@skipOnOCIS
Scenario: the client re-auths after restarting
Given app "oauth2" has been "enabled" in the server
And the user has started the client
And the user has added the following account with oauth2 enabled:
| server | %local_server% |
| user | Alice |
| password | 1234 |
And the user has quitted the client
When the user starts the client
When the user quits the client
And the user starts the client
Then user "Alice" should be connect to the client-UI

0 comments on commit 4478fd2

Please sign in to comment.