File: log_test.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (54 lines) | stat: -rw-r--r-- 1,925 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
import time
import asyncio

from devtools_testutils.perfstress_tests import PerfStressTest


# Used for logging every step and property of the perf test
class LogTest(PerfStressTest):
    _logged_global_completed_operations = 0

    start_time = time.time()

    def __init__(self, arguments):
        super().__init__(arguments)
        self._seconds_per_operation = 1.0 / (self._parallel_index + 1)
        self._logged_completed_operations = 0
        self.log("__init__()")

    async def global_setup(self):
        await super().global_setup()
        self.log("global_setup()")

    async def setup(self):
        await super().setup()
        self.log("setup()")

    def run_sync(self):
        time.sleep(self._seconds_per_operation)
        self._logged_completed_operations += 1
        type(self)._logged_global_completed_operations += 1

    async def run_async(self):
        await asyncio.sleep(self._seconds_per_operation)
        self._logged_completed_operations += 1
        type(self)._logged_global_completed_operations += 1

    async def cleanup(self):
        await super().cleanup()
        self.log(f"cleanup() - Completed Operations: {self._logged_completed_operations}")

    async def global_cleanup(self):
        await super().global_cleanup()
        self.log(f"global_cleanup() - Global Completed Operations: {self._logged_global_completed_operations}")

    def log(self, message):
        print(
            f"[{(time.time() - type(self).start_time):.3f}] [PID: {os.getpid()}] [Parallel: {self._parallel_index}] {message}"
        )