test_soak.mojo (2908B)
1 from std.collections import List 2 from safe_tempdir import SafeTempDir 3 from std.testing import TestSuite, assert_equal, assert_true 4 5 from fixture_assertions import load_scenario_request_json 6 from hyf_runtime.startup import ( 7 RuntimeStartupContext, 8 RuntimeStartupInput, 9 resolve_startup_context, 10 ) 11 from hyf_stdio.server import run_stdio_session 12 13 14 def _context(temp_dir: String) raises -> RuntimeStartupContext: 15 return resolve_startup_context( 16 RuntimeStartupInput( 17 env_paths_profile="repo_local", 18 env_repo_local_base_root=temp_dir, 19 user_home="/home/unused", 20 argv=List[String](), 21 ) 22 ) 23 24 25 def test_bounded_process_soak_200_frames() raises: 26 with SafeTempDir() as temp_dir: 27 var context = _context(temp_dir) 28 var frames = List[String]() 29 for _ in range(200): 30 frames.append( 31 load_scenario_request_json("scenarios/status_ok.json") 32 ) 33 var responses = run_stdio_session(frames, context) 34 assert_equal(len(responses), 200) 35 for response in responses: 36 assert_true(response.find('"ok":true') >= 0) 37 38 39 def main() raises: 40 TestSuite.discover_tests[__functions_in_module()]().run() 41 42 43 from hyf_application.resource_envelope import ( 44 default_resource_envelope, 45 within_envelope, 46 ) 47 48 49 def test_candidate_and_plan_resource_envelope() raises: 50 var envelope = default_resource_envelope() 51 assert_true(within_envelope(envelope, 10, 2, 100, 5, 1)) 52 assert_true(not within_envelope(envelope, 1000, 2, 100, 5, 1)) 53 assert_true(not within_envelope(envelope, 10, 100, 100, 5, 1)) 54 assert_true(not within_envelope(envelope, 10, 2, 100000, 5, 1)) 55 56 57 from hyf_runtime.config import default_loaded_runtime_config, operation_enabled 58 from hyf_runtime.jev_composition import compose_jev 59 from hyf_application.authority_sim import ( 60 apply_expected_version, 61 new_authority_simulation, 62 ) 63 64 65 def test_provider_disablement_and_rollback_preserve_state() raises: 66 var config = default_loaded_runtime_config() 67 config.effective.runtime.enable_farm_update_interpret = True 68 config.effective.runtime.enable_buyer_request_interpret = True 69 config.effective.runtime.enable_buyer_request_match = True 70 assert_true(operation_enabled(config, "farm_update.interpret")) 71 config.effective.runtime.disable_provider = True 72 assert_true(not operation_enabled(config, "farm_update.interpret")) 73 assert_true(not operation_enabled(config, "buyer_request.match")) 74 var composition = compose_jev(config) 75 assert_equal(composition.reason, "provider_disabled") 76 77 # Model/provider rollback must not erase accepted business state. 78 var simulation = new_authority_simulation() 79 apply_expected_version(simulation, "s1", "r1", "r1") 80 assert_equal(simulation.accepted_changes, 1) 81 assert_true(simulation.requires_confirmation)