diff --git a/src/core/tests/Test_StatusHandlerTruncation.py b/src/core/tests/Test_StatusHandlerTruncation.py index 73b44f90..ba2ff8e8 100644 --- a/src/core/tests/Test_StatusHandlerTruncation.py +++ b/src/core/tests/Test_StatusHandlerTruncation.py @@ -937,9 +937,9 @@ def __set_up_patches_func(self, val, random_char=None): test_patches_list.append('python-samba' + str(i)) if random_char is not None: - test_patches_version_list.append('2:4.4.5+dfsg-2ubuntu€' + random_char) + test_patches_version_list.append('2:4.4.5+dfsg-2ubuntu\u20ac' + random_char) else: - test_patches_version_list.append('2:4.4.5+dfsg-2ubuntu€') + test_patches_version_list.append('2:4.4.5+dfsg-2ubuntu\u20ac') return test_patches_list, test_patches_version_list diff --git a/src/core/tests/Test_TelemetryWriter.py b/src/core/tests/Test_TelemetryWriter.py index eb716f21..96b60aee 100644 --- a/src/core/tests/Test_TelemetryWriter.py +++ b/src/core/tests/Test_TelemetryWriter.py @@ -102,9 +102,11 @@ def test_write_event_msg_size_limit(self): f.close() def test_write_event_msg_size_limit_char_more_than_1_bytes(self): - """ Perform 1 byte truncation on char that is more than 1 byte, use decode('utf-8', errors='replace') to replace bad unicode with a good 1 byte char (�) """ + """ Perform 1 byte truncation on char that is more than 1 byte, use decode('utf-8', errors='replace') to replace bad unicode with a good 1 byte char (\uFFFD) """ - message = "a€bc"*3074 # €(\xe2\x82\xac) is 3 bytes char can be written in windows console w/o encoding + message = "a\u20acbc" * 3074 # (\xe2\x82\xac) is 3 bytes char can be written in windows console w/o encoding + min_msg_limit_in_bytes = Constants.TELEMETRY_MSG_SIZE_LIMIT_IN_CHARS - Constants.TELEMETRY_BUFFER_FOR_DROPPED_COUNT_MSG_IN_CHARS - Constants.TELEMETRY_EVENT_COUNTER_MSG_SIZE_LIMIT_IN_CHARS + max_msg_limit_in_bytes = Constants.TELEMETRY_MSG_SIZE_LIMIT_IN_CHARS self.runtime.telemetry_writer.write_event(message, Constants.TelemetryEventLevel.Error, "Test Task") latest_event_file = [pos_json for pos_json in os.listdir(self.runtime.telemetry_writer.events_folder_path) if re.search('^[0-9]+.json$', pos_json)][-1] with open(os.path.join(self.runtime.telemetry_writer.events_folder_path, latest_event_file), 'r+') as f: @@ -112,9 +114,10 @@ def test_write_event_msg_size_limit_char_more_than_1_bytes(self): self.assertTrue(events is not None) self.assertEqual(events[-1]["TaskName"], "Test Task") self.assertTrue(len(events[-1]["Message"]) < len(message.encode('utf-8'))) - chars_dropped = len(message.encode('utf-8')) - Constants.TELEMETRY_MSG_SIZE_LIMIT_IN_CHARS + Constants.TELEMETRY_BUFFER_FOR_DROPPED_COUNT_MSG_IN_CHARS + Constants.TELEMETRY_EVENT_COUNTER_MSG_SIZE_LIMIT_IN_CHARS - self.assertTrue("a€bc" in events[-1]["Message"]) - self.assertTrue("a€bc" * (len(message) + 1 - chars_dropped) + ". [{0} chars dropped]".format(chars_dropped) in events[-1]["Message"]) # len(message) + 1 due to bad unicode will be replaced by � + self.assertTrue("a\u20acbc" in events[-1]["Message"]) + self.assertTrue(len(events[-1]["Message"].encode('utf-8')) > min_msg_limit_in_bytes) + self.assertTrue(len(events[-1]["Message"].encode('utf-8')) < max_msg_limit_in_bytes) + f.close() # TODO: The following 3 tests cause widespread test suite failures (on master), so leaving it out. And tracking in: Task 10912099: [Bug] Bug in telemetry writer - overwriting prior events in fast execution