-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make test failure messages/tracebacks unique to PSM Interop (#21)
This PR: - Make test failure messages/tracebacks unique to PSM Interop to allow for easier grepping/matchers (more details below. - Replaces `self.id()` calls in the framework logs with custom `self.test_name`. For example, `--- Starting subTest __main__.AppNetTest.test_ping_pong.0_create_health_check ---` becomes `--- Starting subTest AppNetTest.test_ping_pong.0_create_health_check ---`. - Changes the log level of `----- TestCase ... FAILED -----` message from `info` to `error`. - Adds `FakeTest` to make future work on the log messages easier The new error format: ``` E0118 09:59:38.289015 140704433060736 base_testcase.py:39] ----- PSM Test Case FAILED: ClassName.test_method ----- E0118 09:59:38.289084 140704433060736 base_testcase.py:87] ($failure_type) PSM Interop Test Failed: ClassName.test_method ^^^^^ [ClassName.test_method] PSM Failed Test Traceback BEGIN Traceback (most recent call last): ... AssertionError: description [ClassName.test_method] PSM Failed Test Traceback END ``` This format will allow us to drastically simplify buggrep matchers that search within the stack traces of _our_ framework, which also resulted in a test failure (e.g. didn't recover after retrying). Now we can do a plain-text grep for `PSM Failed Test Traceback BEGIN` instead of an extended regex grep for `E[0-9]{4}.*base_testcase.*ERROR Traceback in`. Text `PSM Failed Test Traceback BEGIN` is guaranteed to be only produced on test failure. Additionally, this allows to restrict matchers to a specific test in the same swoop, just do a plain-text search for `[TestClass.test_method] PSM Failed Test Traceback BEGIN`. Initial PR that added the traceback: grpc/grpc#34023.
- Loading branch information
Showing
4 changed files
with
149 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Copyright 2024 gRPC authors. | ||
# | ||
# 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. | ||
import logging | ||
|
||
from absl import flags | ||
from absl.testing import absltest | ||
from absl.testing import parameterized | ||
|
||
from framework import xds_k8s_testcase | ||
|
||
logger = logging.getLogger(__name__) | ||
flags.adopt_module_key_flags(xds_k8s_testcase) | ||
|
||
|
||
class FakeTest(xds_k8s_testcase.XdsKubernetesBaseTestCase): | ||
"""A fake test class with known failures to debug BaseTestCase logs. | ||
This test case won't do any infra provisioning, just parses the flags and | ||
reads k8s contexts file. | ||
""" | ||
|
||
def test_0_pass(self): | ||
self.assertTrue(True, "I'm a passing test in the beginning") | ||
|
||
def test_1_error(self): | ||
self.assertTrue(False, msg="Test 1 Assertion ERROR") | ||
|
||
def test_2_pass(self): | ||
self.assertTrue(True, "I'm a passing test in the middle") | ||
|
||
def test_3_failure(self): | ||
raise RuntimeError("Test 3 Uncaught Exception FAILURE") | ||
|
||
def test_4_pass(self): | ||
self.assertTrue(True, "I'm a passing test at the end") | ||
|
||
|
||
class FakeParametrizedTest( | ||
xds_k8s_testcase.XdsKubernetesBaseTestCase, | ||
parameterized.TestCase, | ||
): | ||
"""A fake class to debug BaseTestCase logs produced by parametrized tests. | ||
See FakeTest for notes on provisioning. | ||
""" | ||
|
||
@parameterized.parameters(True, False) | ||
def test_true(self, is_true): | ||
self.assertTrue(is_true) | ||
|
||
@parameterized.named_parameters( | ||
{"testcase_name": "pass", "is_true": True}, | ||
{"testcase_name": "fail", "is_true": False}, | ||
) | ||
def test_true_named(self, is_true): | ||
self.assertTrue(is_true) | ||
|
||
|
||
class FakeSubtestTest(xds_k8s_testcase.XdsKubernetesBaseTestCase): | ||
"""A fake class to debug BaseTestCase logs produced by tests with subtests. | ||
See FakeTest for notes on provisioning. | ||
""" | ||
|
||
def test_even(self): | ||
for num in range(0, 6): | ||
with self.subTest(i=num, msg=f"num_{num}"): | ||
if num & 1: | ||
self.fail(f"Integer {num} is odd") | ||
|
||
|
||
if __name__ == "__main__": | ||
absltest.main() |