From 19ff402b4ba8d0dd329f3421c1d3603e6accc95f Mon Sep 17 00:00:00 2001 From: yevh-berdnyk Date: Fri, 1 Jun 2018 14:46:54 +0200 Subject: [PATCH] Updated message reliability test report Signed-off-by: yevh-berdnyk --- test/appium/Jenkinsfile.message_reliability | 42 +++++++++++++++++++ ...chart.py => message_reliability_report.py} | 17 +++++++- test/appium/tests/base_test_case.py | 7 ++-- 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 test/appium/Jenkinsfile.message_reliability rename test/appium/support/{message_reliability_chart.py => message_reliability_report.py} (80%) diff --git a/test/appium/Jenkinsfile.message_reliability b/test/appium/Jenkinsfile.message_reliability new file mode 100644 index 0000000000..78bb50f0ca --- /dev/null +++ b/test/appium/Jenkinsfile.message_reliability @@ -0,0 +1,42 @@ +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; +node ('linux1'){sauce('1be1b688-e0e7-4314-92a0-db11f52d3c00'){ + def testPassed = true + try { + + stage('Tests & Report'){ + try { + withCredentials([string(credentialsId: 'GIT_HUB_TOKEN', variable: 'GIT_HUB_TOKEN'), + string(credentialsId: 'SOB_SAUCE_ACCESS_KEY', variable: 'SOB_SAUCE_ACCESS_KEY'), + string(credentialsId: 'SOB_SAUCE_USERNAME', variable: 'SOB_SAUCE_USERNAME')]){ + sh 'cd test/appium/tests && python3 -m pytest test_message_reliability.py::TestMessageReliability::$test_to_run --messages_number=$messages_number --message_wait_time=$message_wait_time $apk' } + } + finally { + saucePublisher() + junit testDataPublishers: [[$class: 'SauceOnDemandReportPublisher', jobVisibility: 'public']], + testResults: 'test/appium/tests/*.xml' + archiveArtifacts 'test/appium/tests/*.png' + } + } + } catch(e) { + testPassed = false + } + + stage('Slack notification'){ + def c = (testPassed ? 'good' : 'warning') + def resultText = (testPassed ? '' : 'FAILED') + def fileData = readFile('test/appium/tests/messages.txt') + def map = evaluate(fileData) + def text = 'Sent messages: ' + map.sent + '\nReceived messages: ' + map.received + '\n<' + env.BUILD_URL + '/artifact/test/appium/tests/chart.png' + '|Test run chart>' + JSONArray attachments = new JSONArray(); + JSONObject attachment = new JSONObject(); + + attachment.put('title','Message reliability job run, ' + test_to_run + ' ' + resultText); + attachment.put('title_link', env.BUILD_URL); + attachment.put('text', text); + + attachments.add(attachment); + slackSend(color: c, channel: '#test-notifications', attachments: attachments.toString()) + } +} +} \ No newline at end of file diff --git a/test/appium/support/message_reliability_chart.py b/test/appium/support/message_reliability_report.py similarity index 80% rename from test/appium/support/message_reliability_chart.py rename to test/appium/support/message_reliability_report.py index 450ccd2e4b..ce7e300947 100644 --- a/test/appium/support/message_reliability_chart.py +++ b/test/appium/support/message_reliability_report.py @@ -1,4 +1,9 @@ -def create_chart_one_to_one_chat(one_to_one_chat_data: dict): +def write_data_to_file(sent: int, received: int): + with open('messages.txt', 'a') as f: + f.write("['sent': %s, 'received': %s]" % (sent, received)) + + +def create_one_to_one_chat_report(one_to_one_chat_data: dict): import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt @@ -13,7 +18,10 @@ def create_chart_one_to_one_chat(one_to_one_chat_data: dict): time_2 = sorted(user_b['message_time']) ax.plot([i / 60 for i in time_2], [user_b['message_time'][i] for i in time_2], 'o-', color='#f61e06', label='user_b') + sent_messages = user_a['sent_messages'] + user_b['sent_messages'] + received_messages = len(user_a['message_time']) + len(user_b['message_time']) + title = "User A: sent messages: {}, received messages: {}" \ "\nUser B: sent messages: {}, received messages: {}".format(user_a['sent_messages'], len(user_a['message_time']), @@ -22,14 +30,17 @@ def create_chart_one_to_one_chat(one_to_one_chat_data: dict): if sent_messages: title += "\nReceived messages: {}%".format( round((len(user_a['message_time']) + len(user_b['message_time'])) / sent_messages * 100, ndigits=2)) + plt.title(title) plt.xlabel('chat session duration, minutes') plt.ylabel('time to receive a message, seconds') plt.legend() fig.savefig('chart.png') + write_data_to_file(sent=sent_messages, received=received_messages) -def create_chart_public_chat(public_chat_data: dict): + +def create_public_chat_report(public_chat_data: dict): import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt @@ -46,3 +57,5 @@ def create_chart_public_chat(public_chat_data: dict): plt.ylabel('time to receive a message, seconds') plt.legend() fig.savefig('chart.png') + + write_data_to_file(sent=sent_messages, received=len(message_time)) diff --git a/test/appium/tests/base_test_case.py b/test/appium/tests/base_test_case.py index 91b80bab77..2d6c928691 100644 --- a/test/appium/tests/base_test_case.py +++ b/test/appium/tests/base_test_case.py @@ -4,7 +4,7 @@ import re import subprocess import asyncio -from support.message_reliability_chart import create_chart_one_to_one_chat, create_chart_public_chat +from support.message_reliability_report import create_one_to_one_chat_report, create_public_chat_report from support.network_api import NetworkApi from os import environ from appium import webdriver @@ -227,6 +227,7 @@ class MessageReliabilityTestCase(MultipleDeviceTestCase): def teardown_method(self, method): if self.one_to_one_chat_data: - create_chart_one_to_one_chat(self.one_to_one_chat_data) + create_one_to_one_chat_report(self.one_to_one_chat_data) if self.public_chat_data: - create_chart_public_chat(self.public_chat_data) + create_public_chat_report(self.public_chat_data) + super(MultipleDeviceTestCase, self).teardown_method(method)