Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds flaky e2e report and restart functionality #11263

Merged
merged 31 commits into from
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fae8a15
Reverted old changes
DubeySandeep Nov 25, 2020
c6c9a8a
Adds checks for reporting.
DubeySandeep Nov 25, 2020
9562edd
Added url
DubeySandeep Nov 25, 2020
43f2ffd
Merge branch 'develop' of github.com:oppia/oppia into flake-e2e
DubeySandeep Nov 27, 2020
6353ea8
Fixes exit error issues.
DubeySandeep Nov 28, 2020
ea3af12
Adds checker file.
DubeySandeep Nov 28, 2020
d2bfd87
Adds correct url.
DubeySandeep Nov 28, 2020
7e6bf00
Adds correct url format.
DubeySandeep Nov 28, 2020
917c92f
Fixes test issues
DubeySandeep Nov 28, 2020
1f0544a
Address review comments.
DubeySandeep Dec 1, 2020
d33937e
Merge branch 'develop' into flake-e2e
U8NWXD Dec 11, 2020
f10e084
Update with review comments and for new server
U8NWXD Dec 11, 2020
58753c1
lint fixes
U8NWXD Dec 11, 2020
4f68414
Catch non-unicode characters and ignore them
U8NWXD Dec 11, 2020
4e28982
Merge branch 'develop' into flake-e2e
U8NWXD Dec 14, 2020
f203b29
Report passes and rerun non flaky e2e tests
U8NWXD Dec 15, 2020
2b66886
Fix e2e backend tests
U8NWXD Dec 15, 2020
17c4179
Fix lint errors
U8NWXD Dec 15, 2020
f55fff8
Fix backend tests
U8NWXD Dec 16, 2020
6209a6a
Silence pylint
U8NWXD Dec 16, 2020
426aace
Reach 100% coverage of run_e2e_tests.py
U8NWXD Dec 16, 2020
02210e2
Add tests for flake_checker.py
U8NWXD Dec 17, 2020
1826229
Lint fixes
U8NWXD Dec 17, 2020
545b794
Merge branch 'develop' into flake-e2e
U8NWXD Dec 18, 2020
19f43c1
Include unicode character directly for testing
U8NWXD Dec 18, 2020
8203f85
Make cleanup code more robust
U8NWXD Dec 18, 2020
a84928c
Improve unicode handling
U8NWXD Dec 18, 2020
49d3f05
Fix backend code coverage
U8NWXD Dec 18, 2020
c87d667
Fix CI errors
U8NWXD Dec 19, 2020
8c219b0
More robustly shut down processes
U8NWXD Dec 19, 2020
a2f3b67
Make killing reluctant processes more robust
U8NWXD Dec 19, 2020
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
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@


# Miscellaneous.
/auth.json.enc @nithusha21
/__init__.py @nithusha21
/core/__init__.py @nithusha21
/core/controllers/__init__.py @nithusha21
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ yarn-error.log
.env
.pytest_cache/v/cache/*
.lighthouseci
auth.json

# Oppia uses cache slugs for various resources and we need separate resource
# directories for dev and prod. Resource directories for prod are generated
Expand Down
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
force_single_line=true
force_sort_within_sections=true
ignore_whitespace=true
known_third_party=browsermobproxy,cloudstorage,contextlib2,elasticsearch,google.appengine,google.api_core,google.cloud,google.oauth2,google.protobuf,jinja2,mapreduce,mutagen,pipeline,pylatexenc,pylint,requests,selenium,skulpt,webapp2,webapp2_extras,webtest,yaml
known_third_party=browsermobproxy,cloudstorage,contextlib2,elasticsearch,google.appengine,google.api_core,google.cloud,google.protobuf,jinja2,mapreduce,mutagen,pipeline,pylatexenc,pylint,requests,selenium,skulpt,webapp2,webapp2_extras,webtest,yaml
line_length=80
sections=FUTURE,STDLIB,FIRSTPARTY,THIRDPARTY,LOCALFOLDER
6 changes: 0 additions & 6 deletions app_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,6 @@ skip_files:
- third_party/static/bower-material-1.1.19/
- third_party/python_libs/google/appengine/
- third_party/python_libs/google/net/
- third_party/python_libs/google_auth_oauthlib/
- third_party/python_libs/googleapiclient/
- third_party/python_libs/httplib2/
- third_party/python_libs/oauthlib/
- third_party/python_libs/requests_oauthlib/
- third_party/python_libs/uritemplate/
- third_party/python_libs/google/pyglib/
- third_party/python_libs/grpc/
# CKEditor-4.12.1 plugins in the download from the CKEditor website include
Expand Down
Binary file removed auth.json.enc
Binary file not shown.
4 changes: 0 additions & 4 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ bleach==3.1.5
callbacks==0.3.0
contextlib2==0.6.0.post1
future==0.18.2
google-api-python-client==1.11.0
google-auth==1.21.1
google-auth-httplib2==0.0.4
google-auth-oauthlib==0.4.1
GoogleAppEngineCloudStorageClient==1.9.22.1
GoogleAppEngineMapReduce==1.9.22.0
GoogleAppEnginePipeline==1.9.22.1
Expand Down
15 changes: 4 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ enum34==1.1.10 # via google-cloud-tasks, grpcio
funcsigs==1.0.2 # via mock
future==0.18.2 # via -r requirements.in
futures==3.3.0 # via google-api-core, grpcio
google-api-core[grpc]==1.22.4 # via google-api-python-client, google-cloud-tasks
google-api-python-client==1.11.0 # via -r requirements.in
google-auth-httplib2==0.0.4 # via -r requirements.in, google-api-python-client
google-auth-oauthlib==0.4.1 # via -r requirements.in
google-auth==1.21.1 # via -r requirements.in, google-api-core, google-api-python-client, google-auth-httplib2, google-auth-oauthlib
google-api-core[grpc]==1.22.4 # via google-cloud-tasks
google-auth==1.22.1 # via google-api-core
google-cloud-tasks==1.5.0 # via -r requirements.in
googleapis-common-protos[grpc]==1.52.0 # via -r requirements.in, google-api-core, grpc-google-iam-v1
googleappenginecloudstorageclient==1.9.22.1 # via -r requirements.in, googleappenginemapreduce, googleappenginepipeline
Expand All @@ -35,12 +32,10 @@ graphy==1.0.0 # via -r requirements.in, googleappenginemapreduce
grpc-google-iam-v1==0.12.3 # via google-cloud-tasks
grpcio==1.32.0 # via google-api-core, googleapis-common-protos, grpc-google-iam-v1
html5lib==1.0.1 # via -r requirements.in
httplib2==0.18.1 # via google-api-python-client, google-auth-httplib2
idna==2.10 # via requests
mock==3.0.5 # via googleappenginemapreduce
mox==0.5.3 # via googleappenginemapreduce
mutagen==1.43.0 # via -r requirements.in
oauthlib==3.1.0 # via requests-oauthlib
packaging==20.4 # via -r requirements.in, bleach
protobuf==3.13.0 # via google-api-core, googleapis-common-protos
pyasn1-modules==0.2.8 # via google-auth
Expand All @@ -50,14 +45,12 @@ pyparsing==2.4.7 # via packaging
pytz==2020.1 # via google-api-core
redis==3.5.3 # via -r requirements.in
requests-mock==1.5.2 # via -r requirements.in
requests-oauthlib==1.3.0 # via google-auth-oauthlib
requests-toolbelt==0.9.1 # via -r requirements.in
requests==2.24.0 # via -r requirements.in, google-api-core, requests-mock, requests-oauthlib, requests-toolbelt
requests==2.24.0 # via -r requirements.in, google-api-core, requests-mock, requests-toolbelt
rsa==4.5 # via google-auth
simplejson==3.17.0 # via -r requirements.in, googleappenginemapreduce
six==1.15.0 # via -r requirements.in, bleach, google-api-core, google-api-python-client, google-auth, google-auth-httplib2, grpcio, html5lib, mock, packaging, protobuf, requests-mock, webapp2
six==1.15.0 # via -r requirements.in, bleach, google-api-core, google-auth, grpcio, html5lib, mock, packaging, protobuf, requests-mock, webapp2
soupsieve==1.9.5 # via -r requirements.in, beautifulsoup4
uritemplate==3.0.1 # via google-api-python-client
urllib3==1.25.11 # via elasticsearch, requests
webapp2==3.0.0b1 # via -r requirements.in
webencodings==0.5.1 # via -r requirements.in, bleach, html5lib
Expand Down
1 change: 0 additions & 1 deletion scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
PYGITHUB_VERSION = '1.45'
WEBTEST_VERSION = '2.0.35'
PIP_TOOLS_VERSION = '5.4.0'
SIMPLE_CRYPT_VERSION = '4.1.7'
GRPCIO_VERSION = '1.0.0'
ENUM_VERSION = '1.1.10'
PROTOBUF_VERSION = '3.13.0'
Expand Down
173 changes: 173 additions & 0 deletions scripts/flake_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# Copyright 2020 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS-IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Python execution for checking whether the tests output is flaky."""

from __future__ import absolute_import # pylint: disable=import-only-modules
from __future__ import unicode_literals # pylint: disable=import-only-modules

import datetime
import os

import python_utils

import requests

FLAKE_CHECK_AND_REPORT_URL = (
'https://oppia-e2e-test-results-logger.herokuapp.com'
'/check-flake-and-report')
PASS_REPORT_URL = (
'https://oppia-e2e-test-results-logger.herokuapp.com'
'/check-flake-and-report')
REPORT_API_KEY = '7Ccp062JVjv9LUYwnLMqcm5Eu5gYqqhpl3zQmcO3cDQ'

CI_INFO = {
'circleCI': {
'env': {
'identifier': 'CIRCLECI',
'user_info': 'CIRCLE_USERNAME',
'build_url': 'CIRCLE_BUILD_URL',
'build_id': None
}
},
'githubActions': {
'env': {
'identifier': 'GITHUB_ACTIONS',
'user_info': 'GITHUB_ACTOR',
'build_url': None,
'build_id': 'GITHUB_ACTION'
},
'build_url_template': 'https://github.com/oppia/oppia/runs/%s'
}
}

REQUEST_EXCEPTIONS = (
requests.RequestException, requests.ConnectionError,
requests.HTTPError, requests.TooManyRedirects, requests.Timeout)


def _print_color_message(message):
"""Prints the given message in red color.

Args:
message: str. The success message to print.
"""
# \033[91m is the ANSI escape sequences for green color.
python_utils.PRINT('\033[92m' + message + '\033[0m\n')


def check_if_on_ci():
"""Check if the script is running on a CI server.

Returns: bool. Whether we are running on a CI server.
"""
for info in CI_INFO.values():
ci_identifier = info['env']['identifier']
if os.getenv(ci_identifier):
return True
return False


def _get_build_info():
"""Returns the info related to the build container."""
build_info = {}

for info in CI_INFO.values():
ci_env = info['env']

if not os.getenv(ci_env['identifier']):
continue

if os.getenv(ci_env['build_url']) is not None:
build_url = os.getenv(ci_env['build_url'])
else:
build_url = info['build_url_template'] % os.getenv(
ci_env['build_id'])
timestamp = datetime.datetime.utcnow().isoformat() + '+00:00'

build_info['username'] = os.getenv(ci_env['user_info'])
build_info['build_url'] = build_url
build_info['timestamp'] = timestamp

return build_info

raise Exception('Unknown build environment.')


def report_pass(suite_name):
"""Report a passing test to the logging server."""
metadata = _get_build_info()
payload = {
'suite': suite_name,
'metadata': metadata,
}
try:
requests.post(
PASS_REPORT_URL, json=payload,
allow_redirects=False,
headers={'report_key': REPORT_API_KEY})
except REQUEST_EXCEPTIONS as e:
_print_color_message((
'Failed to contact E2E test logging server at %s.'
'Please report to E2E team in case server is down.'
'Exception: %s') % (FLAKE_CHECK_AND_REPORT_URL, e))


def is_test_output_flaky(output_lines, suite_name):
"""Returns whether the test output matches any flaky test log."""
build_info = _get_build_info()
payload = {
'suite': suite_name,
'output_lines': output_lines,
'metadata': build_info,
}
response = None
try:
response = requests.post(
FLAKE_CHECK_AND_REPORT_URL, json=payload,
allow_redirects=False,
headers={'report_key': REPORT_API_KEY})
except REQUEST_EXCEPTIONS as e:
_print_color_message((
'Failed to contact E2E test logging server at %s.'
'Please report to E2E team in case server is down.'
'Exception: %s') % (FLAKE_CHECK_AND_REPORT_URL, e))

return False

if not response.ok:
U8NWXD marked this conversation as resolved.
Show resolved Hide resolved
_print_color_message('Failed request with response code: %s (%s)' % (
response.status_code, response.reason))
return False

report = {}
try:
report = response.json()
except ValueError as e:
_print_color_message('Unable to convert json response: %s' % e)

if 'log' in report:
log_str = '\n'.join(report['log'])
_print_color_message(
'Logs from test result logging server:\n %s' % log_str)

flaky = report['result'] if 'result' in report else False
if flaky:
flake = report['flake']
_print_color_message('Flake Detected:')
_print_color_message(' Suite: %s' % flake['suite'])
_print_color_message(' Test: %s' % flake['test'])
_print_color_message(
' Error Message: %s' % flake['flake_id'])
return flaky
Loading