Spaces:
Configuration error

File size: 4,154 Bytes
2d63f96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""Stress tests for the DockerRuntime, which connects to the ActionExecutor running in the sandbox."""

from conftest import _close_test_runtime, _load_runtime

from openhands.core.logger import openhands_logger as logger
from openhands.events.action import CmdRunAction


def test_stress_docker_runtime(temp_dir, runtime_cls, repeat=1):
    runtime, config = _load_runtime(
        temp_dir,
        runtime_cls,
        docker_runtime_kwargs={
            'cpu_period': 100000,  # 100ms
            'cpu_quota': 100000,  # Can use 100ms out of each 100ms period (1 CPU)
            'mem_limit': '4G',  # 4 GB of memory
        },
    )

    action = CmdRunAction(
        command='sudo apt-get update && sudo apt-get install -y stress-ng'
    )
    logger.info(action, extra={'msg_type': 'ACTION'})
    obs = runtime.run_action(action)
    logger.info(obs, extra={'msg_type': 'OBSERVATION'})
    assert obs.exit_code == 0

    for _ in range(repeat):
        # run stress-ng stress tests for 1 minute
        action = CmdRunAction(command='stress-ng --all 1 -t 30s')
        action.set_hard_timeout(120)
        logger.info(action, extra={'msg_type': 'ACTION'})
        obs = runtime.run_action(action)
        logger.info(obs, extra={'msg_type': 'OBSERVATION'})

    _close_test_runtime(runtime)


# def test_stress_docker_runtime_hit_memory_limits(temp_dir, runtime_cls):
#     """Test runtime behavior under resource constraints."""
#     runtime, config = _load_runtime(
#         temp_dir,
#         runtime_cls,
#         docker_runtime_kwargs={
#             'cpu_period': 100000,  # 100ms
#             'cpu_quota': 100000,  # Can use 100ms out of each 100ms period (1 CPU)
#             'mem_limit': '4G',  # 4 GB of memory
#             'memswap_limit': '0',  # No swap
#             'mem_swappiness': 0,  # Disable swapping
#             'oom_kill_disable': False,  # Enable OOM killer
#         },
#         runtime_startup_env_vars={
#             'RUNTIME_MAX_MEMORY_GB': '3',
#         },
#     )

#     action = CmdRunAction(
#         command='sudo apt-get update && sudo apt-get install -y stress-ng'
#     )
#     logger.info(action, extra={'msg_type': 'ACTION'})
#     obs = runtime.run_action(action)
#     logger.info(obs, extra={'msg_type': 'OBSERVATION'})
#     assert obs.exit_code == 0

#     action = CmdRunAction(
#         command='stress-ng --vm 1 --vm-bytes 6G --timeout 30s --metrics'
#     )
#     action.set_hard_timeout(120)
#     logger.info(action, extra={'msg_type': 'ACTION'})
#     obs = runtime.run_action(action)
#     logger.info(obs, extra={'msg_type': 'OBSERVATION'})
#     assert 'aborted early, out of system resources' in obs.content
#     assert obs.exit_code == 3  # OOM killed!

#     _close_test_runtime(runtime)


# def test_stress_docker_runtime_within_memory_limits(temp_dir, runtime_cls):
#     """Test runtime behavior under resource constraints."""
#     runtime, config = _load_runtime(
#         temp_dir,
#         runtime_cls,
#         docker_runtime_kwargs={
#             'cpu_period': 100000,  # 100ms
#             'cpu_quota': 100000,  # Can use 100ms out of each 100ms period (1 CPU)
#             'mem_limit': '4G',  # 4 GB of memory
#             'memswap_limit': '0',  # No swap
#             'mem_swappiness': 0,  # Disable swapping
#             'oom_kill_disable': False,  # Enable OOM killer
#         },
#         runtime_startup_env_vars={
#             'RUNTIME_MAX_MEMORY_GB': '7',
#         },
#     )

#     action = CmdRunAction(
#         command='sudo apt-get update && sudo apt-get install -y stress-ng'
#     )
#     logger.info(action, extra={'msg_type': 'ACTION'})
#     obs = runtime.run_action(action)
#     logger.info(obs, extra={'msg_type': 'OBSERVATION'})
#     assert obs.exit_code == 0

#     action = CmdRunAction(
#         command='stress-ng --vm 1 --vm-bytes 6G --timeout 30s --metrics'
#     )
#     action.set_hard_timeout(120)
#     logger.info(action, extra={'msg_type': 'ACTION'})
#     obs = runtime.run_action(action)
#     logger.info(obs, extra={'msg_type': 'OBSERVATION'})
#     assert obs.exit_code == 0

#     _close_test_runtime(runtime)