Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions keywords/TestServerAndroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ def install_device(self):
apk_path = "{}/{}".format(BINARY_DIR, self.apk_name)

try:
# check if package is installed on device already
cmd = self.set_device_option(["adb", "shell", "dumpsys", "package",
"com.couchbase.TestServerApp",
" | grep versionName ", "| cut -d= -f2- "])
output = subprocess.check_output(cmd)
log_info("version in device {} ".format(output.decode()))
if output.strip().decode() == self.version_build:
log_info("package {} is installed already on device. Skip install it"\
.format(self.version_build))
self.stop() # stop CBL server if it is running
self.start_device()
return
log_info("remove the app on device before install, to ensure sandbox gets cleaned.")
self.remove()
except Exception as e:
Expand Down Expand Up @@ -216,7 +228,7 @@ def start(self, logfile_name):

# return "http://{}:{}".format(self.host, self.port)

def start_device(self, logfile_name):
def start_device(self, logfile_name=""):
"""
1. Starts a Test server app with adb logging to provided logfile file object.
The adb process will be stored in the self.process property
Expand All @@ -230,10 +242,12 @@ def start_device(self, logfile_name):
command = self.set_device_option(["adb", "logcat", "-c"])
subprocess.check_call(command)

# Start redirecting adb output to the logfile
self.logfile = open(logfile_name, "w+")
command = self.set_device_option(["adb", "logcat"])
self.process = subprocess.Popen(args=command, stdout=self.logfile)
if logfile_name:
# Start redirecting adb output to the logfile
self.logfile = open(logfile_name, "w+")
command = self.set_device_option(["adb", "logcat"])
self.process = subprocess.Popen(args=command, stdout=self.logfile)

command = self.set_device_option([
"adb", "shell", "am", "start", "-n", self.activity_name,
"--es", "username", "none",
Expand Down Expand Up @@ -273,10 +287,12 @@ def stop(self):
output = subprocess.check_output(command)
log_info(output)

self.logfile.flush()
self.logfile.close()
self.process.kill()
self.process.wait()
if self.logfile:
self.logfile.flush()
self.logfile.close()
if self.process:
self.process.kill()
self.process.wait()

def close_app(self):
if self.device_enabled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from keywords.constants import RBAC_FULL_ADMIN



@pytest.mark.channels
@pytest.mark.syncgateway
@pytest.mark.attachment_cleanup
Expand Down
4 changes: 4 additions & 0 deletions testsuites/CBLTester/CBL_Functional_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ def params_from_base_suite_setup(request):
# Start Test server which needed for suite level set up like query tests
if not use_local_testserver and create_db_per_suite:
log_info("Starting TestServer...")
testserver.stop()
test_name_cp = test_name.replace("/", "-")
if device_enabled:
testserver.start_device("{}/logs/{}-{}-{}.txt".format(RESULTS_DIR, type(testserver).__name__,
Expand All @@ -505,6 +506,7 @@ def params_from_base_suite_setup(request):
testserver.start("{}/logs/{}-{}-{}.txt".format(RESULTS_DIR, type(testserver).__name__,
test_name_cp,
datetime.datetime.now()))
time.sleep(2)

suite_source_db = None
suite_db = None
Expand Down Expand Up @@ -717,10 +719,12 @@ def params_from_base_test_setup(request, params_from_base_suite_setup):

if not use_local_testserver and create_db_per_test:
log_info("Starting TestServer...")
testserver.stop()
if device_enabled:
testserver.start_device(log_filename)
else:
testserver.start(log_filename)
time.sleep(2)

cluster_helper = ClusterKeywords(cluster_config)
cluster_hosts = cluster_helper.get_cluster_topology(cluster_config=cluster_config)
Expand Down