Skip to content
Snippets Groups Projects
Commit d0cc38e2 authored by Georges Racinet's avatar Georges Racinet
Browse files

Preparations: timed test users management

These preparations (signed-in webdriver, personal access token)
are only done once per session, but if the session is comprised of
only a few tests, they can represent a good chunk of the run time.

For example, launching the only current test in test_wikis.py,
they represent 45% of the total time (on a warmed up GDK Heptapod
based on GitLab 12.10).
parent 1443aca0
No related branches found
No related tags found
No related merge requests found
......@@ -174,6 +174,7 @@
self.wait_startup(
wait_after_first_response=self.wait_after_first_response)
logger.info("Preparing root user.")
start = time.time()
root = self.users['root'] = {}
driver = self.new_webdriver()
# guaranteeing driver to be available for teardown as soon as created
......@@ -200,7 +201,8 @@
'ssh-keygen',
'-R', '[{host}]:{port}'.format(
host=self.host, port=self.ssh_port)))
logger.info("All preparations done, proceeding with tests.")
logger.info("All preparations done in %.2f seconds. "
"Proceeding with tests.", time.time() - start)
def restart_rails(self):
logger.info("Restarting the Rails application.")
......
import logging
from selenium.webdriver.common.keys import Keys
......@@ -1,6 +2,7 @@
from selenium.webdriver.common.keys import Keys
import time
from .selenium import webdriver_wait_get
from .user import default_password, User
......@@ -2,8 +4,11 @@
from .selenium import webdriver_wait_get
from .user import default_password, User
logger = logging.getLogger(__name__)
def initialize_root(driver, heptapod, password):
# Create initial password
elem = driver.find_element_by_name('user[password]')
......@@ -19,6 +24,7 @@
def generate_private_token(driver, heptapod, user):
"""Generate a private token for already logged in user.
"""
start = time.time()
driver.get(heptapod.url + '/profile/personal_access_tokens')
name_elt = driver.find_element_by_xpath(
'//input[@name="personal_access_token[name]"]')
......@@ -30,6 +36,8 @@
submit.click()
account_page_retrieve_private_token(driver, heptapod, user)
logger.info("Access token for %r generated in %.2f seconds",
user, time.time() - start)
def account_page_retrieve_private_token(driver, heptapod, user):
......@@ -58,6 +66,7 @@
def login_as_root(driver, heptapod, password):
start = time.time()
webdriver_wait_get(heptapod, driver, relative_uri='/users/sign_in')
assert 'GitLab' in driver.title
html = driver.find_element_by_tag_name('html').get_attribute('innerHTML')
......@@ -66,6 +75,8 @@
return initialize_root(driver, heptapod, password)
sign_in_page_login(driver, heptapod, 'root', password)
logger.info("Made signed-in webdriver for user %r in %.2f seconds",
'root', time.time() - start)
generate_private_token(driver, heptapod, 'root')
......@@ -81,6 +92,7 @@
user = User.create(heptapod, name,
password=password, fullname=fullname)
start = time.time()
driver = heptapod.new_webdriver()
webdriver_wait_get(heptapod, driver, relative_uri='/users/sign_in')
sign_in_page_login(driver, heptapod, name, password=password)
......@@ -84,6 +96,8 @@
driver = heptapod.new_webdriver()
webdriver_wait_get(heptapod, driver, relative_uri='/users/sign_in')
sign_in_page_login(driver, heptapod, name, password=password)
logger.info("Made signed-in webdriver for user %s in %.2f seconds",
name, time.time() - start)
generate_private_token(driver, heptapod, name)
return user, driver
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment