this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Migrate tests from stdlib I/O to Eio-based file operations

Replace blocking stdlib file operations with Eio's capability-based filesystem access and streaming I/O. Tests now use Eio_main.run, Eio.Path.with_open_in, and Eio.Buf_read.of_flow for more idiomatic Eio patterns that eliminate intermediate string buffers.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

+60 -85
+2 -2
test/dune
··· 1 1 (test 2 2 (name simple_test) 3 - (libraries fastcgi eio) 3 + (libraries fastcgi eio eio_main) 4 4 (deps (source_tree test_cases)) 5 5 ) 6 6 7 7 (test 8 8 (name validate_all_test_cases) 9 - (libraries fastcgi eio) 9 + (libraries fastcgi eio eio_main) 10 10 (deps (source_tree test_cases)) 11 11 )
+14 -17
test/simple_test.ml
··· 67 67 68 68 Printf.printf "✓ Long key-value encoding test passed\n%!" 69 69 70 - let test_with_binary_test_case filename expected_type expected_request_id = 70 + let test_with_binary_test_case ~fs filename expected_type expected_request_id = 71 71 Printf.printf "Testing with binary test case: %s...\n%!" filename; 72 72 73 - let content = 74 - let ic = open_in_bin ("test_cases/" ^ filename) in 75 - let len = in_channel_length ic in 76 - let content = really_input_string ic len in 77 - close_in ic; 78 - content 73 + let parsed = 74 + Eio.Path.with_open_in (fs, "test_cases/" ^ filename) @@ fun flow -> 75 + let buf_read = Eio.Buf_read.of_flow flow ~max_size:1000000 in 76 + Record.read buf_read 79 77 in 80 - 81 - let buf_read = Eio.Buf_read.of_string content in 82 - let parsed = Record.read buf_read in 83 78 84 79 assert (parsed.version = 1); 85 80 assert (parsed.record_type = expected_type); ··· 87 82 88 83 Printf.printf "✓ Binary test case %s passed\n%!" filename 89 84 90 - let run_tests () = 85 + let run_tests ~fs = 91 86 Printf.printf "Running FastCGI Record tests...\n\n%!"; 92 87 93 88 test_record_types (); ··· 95 90 test_long_key_value (); 96 91 97 92 (* Test with some of our binary test cases *) 98 - test_with_binary_test_case "begin_request_responder.bin" Begin_request 1; 99 - test_with_binary_test_case "params_empty.bin" Params 1; 100 - test_with_binary_test_case "end_request_success.bin" End_request 1; 101 - test_with_binary_test_case "get_values.bin" Get_values 0; 102 - test_with_binary_test_case "abort_request.bin" Abort_request 1; 93 + test_with_binary_test_case ~fs "begin_request_responder.bin" Begin_request 1; 94 + test_with_binary_test_case ~fs "params_empty.bin" Params 1; 95 + test_with_binary_test_case ~fs "end_request_success.bin" End_request 1; 96 + test_with_binary_test_case ~fs "get_values.bin" Get_values 0; 97 + test_with_binary_test_case ~fs "abort_request.bin" Abort_request 1; 103 98 104 99 Printf.printf "\n✅ All FastCGI Record tests passed!\n%!" 105 100 106 - let () = run_tests () 101 + let () = Eio_main.run @@ fun env -> 102 + let fs = Eio.Stdenv.cwd env in 103 + run_tests ~fs:(fst fs)
+44 -66
test/validate_all_test_cases.ml
··· 25 25 ("unknown_type.bin", Unknown_type, 0); 26 26 ] 27 27 28 - let test_binary_file filename expected_type expected_request_id = 28 + let test_binary_file ~fs filename expected_type expected_request_id = 29 29 Printf.printf "Testing %s... " filename; 30 30 31 - let content = 32 - let ic = open_in_bin ("test_cases/" ^ filename) in 33 - let len = in_channel_length ic in 34 - let content = really_input_string ic len in 35 - close_in ic; 36 - content 31 + let parsed = 32 + Eio.Path.with_open_in (fs, "test_cases/" ^ filename) @@ fun flow -> 33 + let buf_read = Eio.Buf_read.of_flow flow ~max_size:1000000 in 34 + Record.read buf_read 37 35 in 38 36 39 - let buf_read = Eio.Buf_read.of_string content in 40 - let parsed = Record.read buf_read in 41 - 42 37 assert (parsed.version = 1); 43 38 assert (parsed.record_type = expected_type); 44 39 assert (parsed.request_id = expected_request_id); 45 40 46 41 Printf.printf "✓\n%!" 47 42 48 - let test_params_decoding () = 43 + let test_params_decoding ~fs = 49 44 Printf.printf "Testing params record content decoding... "; 50 45 51 - let content = 52 - let ic = open_in_bin "test_cases/params_get.bin" in 53 - let len = in_channel_length ic in 54 - let content = really_input_string ic len in 55 - close_in ic; 56 - content 46 + let parsed = 47 + Eio.Path.with_open_in (fs, "test_cases/params_get.bin") @@ fun flow -> 48 + let buf_read = Eio.Buf_read.of_flow flow ~max_size:1000000 in 49 + Record.read buf_read 57 50 in 58 51 59 - let buf_read = Eio.Buf_read.of_string content in 60 - let parsed = Record.read buf_read in 61 - 62 52 (* Decode the params content *) 63 53 let params = Record.KV.decode parsed.content in 64 54 ··· 69 59 70 60 Printf.printf "✓\n%!" 71 61 72 - let test_large_record () = 62 + let test_large_record ~fs = 73 63 Printf.printf "Testing large record... "; 74 64 75 - let content = 76 - let ic = open_in_bin "test_cases/large_record.bin" in 77 - let len = in_channel_length ic in 78 - let content = really_input_string ic len in 79 - close_in ic; 80 - content 65 + let parsed = 66 + Eio.Path.with_open_in (fs, "test_cases/large_record.bin") @@ fun flow -> 67 + let buf_read = Eio.Buf_read.of_flow flow ~max_size:1000000 in 68 + Record.read buf_read 81 69 in 82 70 83 - let buf_read = Eio.Buf_read.of_string content in 84 - let parsed = Record.read buf_read in 85 - 86 71 assert (parsed.version = 1); 87 72 assert (parsed.record_type = Stdout); 88 73 assert (parsed.request_id = 1); ··· 90 75 91 76 Printf.printf "✓\n%!" 92 77 93 - let test_padded_record () = 78 + let test_padded_record ~fs = 94 79 Printf.printf "Testing padded record... "; 95 80 96 - let content = 97 - let ic = open_in_bin "test_cases/padded_record.bin" in 98 - let len = in_channel_length ic in 99 - let content = really_input_string ic len in 100 - close_in ic; 101 - content 81 + let parsed = 82 + Eio.Path.with_open_in (fs, "test_cases/padded_record.bin") @@ fun flow -> 83 + let buf_read = Eio.Buf_read.of_flow flow ~max_size:1000000 in 84 + Record.read buf_read 102 85 in 103 - 104 - let buf_read = Eio.Buf_read.of_string content in 105 - let parsed = Record.read buf_read in 106 86 107 87 assert (parsed.version = 1); 108 88 assert (parsed.record_type = Stdout); ··· 111 91 112 92 Printf.printf "✓\n%!" 113 93 114 - let test_multiplexed_records () = 94 + let test_multiplexed_records ~fs = 115 95 Printf.printf "Testing multiplexed records... "; 116 96 117 - let content = 118 - let ic = open_in_bin "test_cases/multiplexed_requests.bin" in 119 - let len = in_channel_length ic in 120 - let content = really_input_string ic len in 121 - close_in ic; 122 - content 97 + let records = 98 + Eio.Path.with_open_in (fs, "test_cases/multiplexed_requests.bin") @@ fun flow -> 99 + let buf_read = Eio.Buf_read.of_flow flow ~max_size:1000000 in 100 + let records = ref [] in 101 + 102 + (* Read all records from the multiplexed stream *) 103 + (try 104 + while true do 105 + let record = Record.read buf_read in 106 + records := record :: !records 107 + done 108 + with End_of_file -> ()); 109 + !records 123 110 in 124 111 125 - let buf_read = Eio.Buf_read.of_string content in 126 - let records = ref [] in 127 - 128 - (* Read all records from the multiplexed stream *) 129 - (try 130 - while true do 131 - let record = Record.read buf_read in 132 - records := record :: !records 133 - done 134 - with End_of_file -> ()); 135 - 136 - let records = List.rev !records in 112 + let records = List.rev records in 137 113 138 114 (* Should have multiple records with different request IDs *) 139 115 assert (List.length records > 5); ··· 145 121 146 122 Printf.printf "✓\n%!" 147 123 148 - let run_all_tests () = 124 + let run_all_tests ~fs = 149 125 Printf.printf "Validating all FastCGI test case files...\n\n%!"; 150 126 151 127 (* Test individual files *) 152 128 List.iter (fun (filename, expected_type, expected_request_id) -> 153 - test_binary_file filename expected_type expected_request_id 129 + test_binary_file ~fs filename expected_type expected_request_id 154 130 ) test_cases; 155 131 156 132 Printf.printf "\nTesting specific content decoding...\n%!"; 157 - test_params_decoding (); 158 - test_large_record (); 159 - test_padded_record (); 160 - test_multiplexed_records (); 133 + test_params_decoding ~fs; 134 + test_large_record ~fs; 135 + test_padded_record ~fs; 136 + test_multiplexed_records ~fs; 161 137 162 138 Printf.printf "\n✅ All %d test case files validated successfully!\n%!" (List.length test_cases); 163 139 Printf.printf "✅ FastCGI Record implementation is working correctly!\n%!" 164 140 165 - let () = run_all_tests () 141 + let () = Eio_main.run @@ fun env -> 142 + let fs = Eio.Stdenv.cwd env in 143 + run_all_tests ~fs:(fst fs)