aws-crt 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (322) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/VERSION +1 -1
  4. data/aws-crt-ffi/CMakeLists.txt +49 -41
  5. data/aws-crt-ffi/crt/aws-c-auth/CMakeLists.txt +0 -10
  6. data/aws-crt-ffi/crt/aws-c-auth/include/aws/auth/credentials.h +3 -2
  7. data/aws-crt-ffi/crt/aws-c-auth/include/aws/auth/private/credentials_utils.h +4 -4
  8. data/aws-crt-ffi/crt/aws-c-auth/source/auth.c +1 -14
  9. data/aws-crt-ffi/crt/aws-c-auth/source/aws_imds_client.c +206 -68
  10. data/aws-crt-ffi/crt/aws-c-auth/source/aws_signing.c +5 -0
  11. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_cached.c +6 -6
  12. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_default_chain.c +16 -1
  13. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_ecs.c +0 -1
  14. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_process.c +0 -1
  15. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_sts_web_identity.c +0 -1
  16. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_x509.c +10 -7
  17. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_utils.c +35 -26
  18. data/aws-crt-ffi/crt/aws-c-auth/source/signable_chunk.c +3 -2
  19. data/aws-crt-ffi/crt/aws-c-auth/tests/CMakeLists.txt +3 -2
  20. data/aws-crt-ffi/crt/aws-c-auth/tests/aws_imds_client_test.c +1 -0
  21. data/aws-crt-ffi/crt/aws-c-auth/tests/credentials_provider_ecs_tests.c +3 -0
  22. data/aws-crt-ffi/crt/aws-c-auth/tests/credentials_provider_process_tests.c +65 -16
  23. data/aws-crt-ffi/crt/aws-c-auth/tests/credentials_tests.c +125 -0
  24. data/aws-crt-ffi/crt/aws-c-auth/tests/sigv4_signing_tests.c +68 -46
  25. data/aws-crt-ffi/crt/aws-c-cal/CMakeLists.txt +8 -3
  26. data/aws-crt-ffi/crt/aws-c-cal/bin/run_x_platform_fuzz_corpus/main.c +9 -0
  27. data/aws-crt-ffi/crt/aws-c-cal/builder.json +11 -3
  28. data/aws-crt-ffi/crt/aws-c-cal/cmake/aws-c-cal-config.cmake +14 -5
  29. data/aws-crt-ffi/crt/aws-c-cal/source/darwin/securityframework_ecc.c +6 -6
  30. data/aws-crt-ffi/crt/aws-c-cal/source/windows/bcrypt_ecc.c +12 -12
  31. data/aws-crt-ffi/crt/aws-c-cal/tests/test_case_helper.h +14 -14
  32. data/aws-crt-ffi/crt/aws-c-common/CMakeLists.txt +21 -1
  33. data/aws-crt-ffi/crt/aws-c-common/README.md +8 -0
  34. data/aws-crt-ffi/crt/aws-c-common/cmake/AwsCFlags.cmake +20 -5
  35. data/aws-crt-ffi/crt/aws-c-common/cmake/AwsFeatureTests.cmake +7 -1
  36. data/aws-crt-ffi/crt/aws-c-common/format-check.sh +1 -1
  37. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/byte_buf.h +14 -0
  38. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/config.h.in +1 -0
  39. data/aws-crt-ffi/crt/{aws-c-auth/include/aws/auth → aws-c-common/include/aws/common}/external/cJSON.h +82 -74
  40. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/json.h +335 -0
  41. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/logging.h +1 -0
  42. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/math.inl +2 -2
  43. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/private/json_impl.h +22 -0
  44. data/aws-crt-ffi/crt/aws-c-common/include/aws/testing/aws_test_harness.h +2 -0
  45. data/aws-crt-ffi/crt/aws-c-common/source/byte_buf.c +36 -0
  46. data/aws-crt-ffi/crt/aws-c-common/source/common.c +5 -2
  47. data/aws-crt-ffi/crt/aws-c-common/source/external/cJSON.c +3113 -0
  48. data/aws-crt-ffi/crt/aws-c-common/source/file.c +9 -0
  49. data/aws-crt-ffi/crt/aws-c-common/source/json.c +348 -0
  50. data/aws-crt-ffi/crt/aws-c-common/source/logging.c +7 -2
  51. data/aws-crt-ffi/crt/aws-c-common/source/posix/system_info.c +8 -0
  52. data/aws-crt-ffi/crt/aws-c-common/source/ref_count.c +3 -1
  53. data/aws-crt-ffi/crt/aws-c-common/source/windows/file.c +47 -0
  54. data/aws-crt-ffi/crt/aws-c-common/source/windows/system_info.c +2 -1
  55. data/aws-crt-ffi/crt/aws-c-common/tests/CMakeLists.txt +5 -0
  56. data/aws-crt-ffi/crt/aws-c-common/tests/byte_buf_test.c +69 -0
  57. data/aws-crt-ffi/crt/aws-c-common/tests/json_test.c +134 -0
  58. data/aws-crt-ffi/crt/aws-c-common/tests/memtrace_test.c +6 -2
  59. data/aws-crt-ffi/crt/aws-c-event-stream/README.md +18 -35
  60. data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/event_stream.h +21 -2
  61. data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/event_stream_rpc_client.h +14 -2
  62. data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/event_stream_rpc_server.h +13 -0
  63. data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/private/event_stream_rpc_priv.h +7 -7
  64. data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream.c +257 -141
  65. data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream_channel_handler.c +1 -1
  66. data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream_rpc_client.c +31 -8
  67. data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream_rpc_server.c +63 -10
  68. data/aws-crt-ffi/crt/aws-c-event-stream/tests/CMakeLists.txt +2 -0
  69. data/aws-crt-ffi/crt/aws-c-event-stream/tests/event_stream_rpc_client_connection_test.c +157 -106
  70. data/aws-crt-ffi/crt/aws-c-event-stream/tests/event_stream_rpc_server_connection_test.c +168 -1
  71. data/aws-crt-ffi/crt/aws-c-event-stream/tests/message_deserializer_test.c +4 -2
  72. data/aws-crt-ffi/crt/aws-c-http/CMakeLists.txt +1 -0
  73. data/aws-crt-ffi/crt/aws-c-http/README.md +8 -0
  74. data/aws-crt-ffi/crt/aws-c-http/bin/elasticurl/main.c +1 -1
  75. data/aws-crt-ffi/crt/aws-c-http/builder.json +4 -3
  76. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/connection.h +8 -1
  77. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/connection_manager.h +45 -1
  78. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/http2_stream_manager.h +63 -12
  79. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/connection_impl.h +2 -1
  80. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/h2_connection.h +20 -2
  81. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/h2_frames.h +1 -0
  82. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/h2_stream.h +42 -13
  83. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/http2_stream_manager_impl.h +17 -0
  84. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/http_impl.h +3 -0
  85. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/random_access_set.h +10 -3
  86. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/request_response_impl.h +3 -17
  87. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/request_response.h +108 -4
  88. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/statistics.h +22 -0
  89. data/aws-crt-ffi/crt/aws-c-http/source/connection.c +8 -3
  90. data/aws-crt-ffi/crt/aws-c-http/source/connection_manager.c +22 -3
  91. data/aws-crt-ffi/crt/aws-c-http/source/connection_monitor.c +32 -14
  92. data/aws-crt-ffi/crt/aws-c-http/source/h1_connection.c +14 -0
  93. data/aws-crt-ffi/crt/aws-c-http/source/h1_encoder.c +7 -4
  94. data/aws-crt-ffi/crt/aws-c-http/source/h2_connection.c +161 -45
  95. data/aws-crt-ffi/crt/aws-c-http/source/h2_decoder.c +37 -8
  96. data/aws-crt-ffi/crt/aws-c-http/source/h2_frames.c +13 -1
  97. data/aws-crt-ffi/crt/aws-c-http/source/h2_stream.c +345 -87
  98. data/aws-crt-ffi/crt/aws-c-http/source/hpack.c +3 -0
  99. data/aws-crt-ffi/crt/aws-c-http/source/http.c +3 -0
  100. data/aws-crt-ffi/crt/aws-c-http/source/http2_stream_manager.c +266 -39
  101. data/aws-crt-ffi/crt/aws-c-http/source/random_access_set.c +9 -3
  102. data/aws-crt-ffi/crt/aws-c-http/source/request_response.c +80 -20
  103. data/aws-crt-ffi/crt/aws-c-http/source/statistics.c +11 -0
  104. data/aws-crt-ffi/crt/aws-c-http/tests/CMakeLists.txt +28 -1
  105. data/aws-crt-ffi/crt/aws-c-http/tests/fuzz/fuzz_h2_decoder_correct.c +5 -3
  106. data/aws-crt-ffi/crt/aws-c-http/tests/h2_test_helper.c +133 -29
  107. data/aws-crt-ffi/crt/aws-c-http/tests/h2_test_helper.h +6 -0
  108. data/aws-crt-ffi/crt/aws-c-http/tests/py_localhost/README.md +40 -0
  109. data/aws-crt-ffi/crt/aws-c-http/tests/py_localhost/non_tls_server.py +56 -0
  110. data/aws-crt-ffi/crt/aws-c-http/tests/py_localhost/server.py +329 -0
  111. data/aws-crt-ffi/crt/aws-c-http/tests/test_connection_manager.c +1 -1
  112. data/aws-crt-ffi/crt/aws-c-http/tests/test_connection_monitor.c +2 -2
  113. data/aws-crt-ffi/crt/aws-c-http/tests/test_h1_client.c +47 -34
  114. data/aws-crt-ffi/crt/aws-c-http/tests/test_h1_encoder.c +4 -4
  115. data/aws-crt-ffi/crt/aws-c-http/tests/test_h1_server.c +15 -12
  116. data/aws-crt-ffi/crt/aws-c-http/tests/test_h2_client.c +582 -25
  117. data/aws-crt-ffi/crt/aws-c-http/tests/test_h2_encoder.c +3 -3
  118. data/aws-crt-ffi/crt/aws-c-http/tests/test_localhost_integ.c +530 -0
  119. data/aws-crt-ffi/crt/aws-c-http/tests/test_stream_manager.c +459 -67
  120. data/aws-crt-ffi/crt/aws-c-io/CMakeLists.txt +4 -0
  121. data/aws-crt-ffi/crt/aws-c-io/builder.json +3 -2
  122. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/channel.h +21 -0
  123. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/io.h +3 -0
  124. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/socket.h +6 -0
  125. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/stream.h +35 -5
  126. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/tls_channel_handler.h +211 -15
  127. data/aws-crt-ffi/crt/aws-c-io/source/channel.c +56 -30
  128. data/aws-crt-ffi/crt/aws-c-io/source/darwin/secure_transport_tls_channel_handler.c +0 -24
  129. data/aws-crt-ffi/crt/aws-c-io/source/io.c +9 -0
  130. data/aws-crt-ffi/crt/aws-c-io/source/{pkcs11.c → pkcs11_lib.c} +162 -22
  131. data/aws-crt-ffi/crt/aws-c-io/source/pkcs11_private.h +18 -20
  132. data/aws-crt-ffi/crt/aws-c-io/source/pkcs11_tls_op_handler.c +221 -0
  133. data/aws-crt-ffi/crt/aws-c-io/source/posix/socket.c +135 -81
  134. data/aws-crt-ffi/crt/aws-c-io/source/retry_strategy.c +12 -8
  135. data/aws-crt-ffi/crt/aws-c-io/source/s2n/s2n_tls_channel_handler.c +252 -215
  136. data/aws-crt-ffi/crt/aws-c-io/source/stream.c +65 -82
  137. data/aws-crt-ffi/crt/aws-c-io/source/tls_channel_handler.c +188 -57
  138. data/aws-crt-ffi/crt/aws-c-io/source/windows/iocp/socket.c +271 -256
  139. data/aws-crt-ffi/crt/aws-c-io/tests/CMakeLists.txt +21 -12
  140. data/aws-crt-ffi/crt/aws-c-io/tests/channel_test.c +32 -4
  141. data/aws-crt-ffi/crt/aws-c-io/tests/io_lib_test.c +37 -0
  142. data/aws-crt-ffi/crt/aws-c-io/tests/pkcs11_test.c +412 -93
  143. data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.crt +15 -0
  144. data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.key +5 -0
  145. data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.p12 +0 -0
  146. data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.p8 +5 -0
  147. data/aws-crt-ffi/crt/aws-c-io/tests/resources/generateCerts.sh +24 -15
  148. data/aws-crt-ffi/crt/aws-c-io/tests/socket_test.c +72 -1
  149. data/aws-crt-ffi/crt/s2n/CMakeLists.txt +6 -1
  150. data/aws-crt-ffi/crt/s2n/bindings/rust/Cargo.toml +1 -0
  151. data/aws-crt-ffi/crt/s2n/bindings/rust/generate/src/main.rs +105 -82
  152. data/aws-crt-ffi/crt/s2n/bindings/rust/generate.sh +1 -0
  153. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls/Cargo.toml +2 -2
  154. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls/src/raw/config.rs +1 -1
  155. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/Cargo.toml +1 -1
  156. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/build.rs +84 -30
  157. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/src/lib.rs +4 -0
  158. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/Cargo.toml +21 -0
  159. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/certs/cert.pem +14 -0
  160. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/certs/key.pem +8 -0
  161. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/client.rs +45 -0
  162. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/server.rs +60 -0
  163. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/src/lib.rs +150 -0
  164. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/tests/handshake.rs +51 -0
  165. data/aws-crt-ffi/crt/s2n/crypto/s2n_drbg.c +98 -77
  166. data/aws-crt-ffi/crt/s2n/crypto/s2n_drbg.h +10 -7
  167. data/aws-crt-ffi/crt/s2n/crypto/s2n_openssl.h +2 -0
  168. data/aws-crt-ffi/crt/s2n/error/s2n_errno.c +1 -1
  169. data/aws-crt-ffi/crt/s2n/error/s2n_errno.h +1 -0
  170. data/aws-crt-ffi/crt/s2n/s2n.mk +7 -0
  171. data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/repository.py +233 -0
  172. data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/setup-proof.py +8 -7
  173. data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/setup.py +17 -18
  174. data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/util.py +41 -23
  175. data/aws-crt-ffi/crt/s2n/tests/fuzz/LD_PRELOAD/global_overrides.c +3 -3
  176. data/aws-crt-ffi/crt/s2n/tests/integration/s2n_client_endpoint_handshake_test.py +2 -2
  177. data/aws-crt-ffi/crt/s2n/tests/integrationv2/Makefile +13 -42
  178. data/aws-crt-ffi/crt/s2n/tests/integrationv2/README.md +6 -1
  179. data/aws-crt-ffi/crt/s2n/tests/integrationv2/common.py +118 -53
  180. data/aws-crt-ffi/crt/s2n/tests/integrationv2/configuration.py +108 -88
  181. data/aws-crt-ffi/crt/s2n/tests/integrationv2/conftest.py +6 -3
  182. data/aws-crt-ffi/crt/s2n/tests/integrationv2/constants.py +6 -4
  183. data/aws-crt-ffi/crt/s2n/tests/integrationv2/fixtures.py +21 -12
  184. data/aws-crt-ffi/crt/s2n/tests/integrationv2/global_flags.py +1 -0
  185. data/aws-crt-ffi/crt/s2n/tests/integrationv2/processes.py +62 -19
  186. data/aws-crt-ffi/crt/s2n/tests/integrationv2/providers.py +304 -48
  187. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_client_authentication.py +20 -11
  188. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_cross_compatibility.py +41 -17
  189. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_dynamic_record_sizes.py +6 -3
  190. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_early_data.py +105 -48
  191. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_external_psk.py +160 -76
  192. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_fragmentation.py +59 -26
  193. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_happy_path.py +42 -28
  194. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_hello_retry_requests.py +33 -13
  195. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_key_update.py +29 -11
  196. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_ocsp.py +138 -0
  197. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_pq_handshake.py +103 -36
  198. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_session_resumption.py +52 -25
  199. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_signature_algorithms.py +47 -21
  200. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_sni_match.py +13 -9
  201. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_sslyze.py +88 -17
  202. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_version_negotiation.py +71 -22
  203. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_well_known_endpoints.py +4 -3
  204. data/aws-crt-ffi/crt/s2n/tests/integrationv2/tox.ini +1 -0
  205. data/aws-crt-ffi/crt/s2n/tests/integrationv2/utils.py +50 -15
  206. data/aws-crt-ffi/crt/s2n/tests/litani/CHANGELOG +131 -0
  207. data/aws-crt-ffi/crt/s2n/tests/litani/CONTRIBUTING.md +16 -0
  208. data/aws-crt-ffi/crt/s2n/tests/litani/README.md +36 -14
  209. data/aws-crt-ffi/crt/s2n/tests/litani/THIRD-PARTY +205 -41
  210. data/aws-crt-ffi/crt/s2n/tests/litani/doc/bin/build-html-doc +7 -7
  211. data/aws-crt-ffi/crt/s2n/tests/litani/doc/configure +27 -23
  212. data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani-add-job.scdoc +7 -0
  213. data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani-dump-run.scdoc +7 -5
  214. data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani-transform-jobs.scdoc +248 -0
  215. data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani.scdoc +2 -2
  216. data/aws-crt-ffi/crt/s2n/tests/litani/doc/templates/index.jinja.html +4 -0
  217. data/aws-crt-ffi/crt/s2n/tests/litani/examples/add-root-node/README +12 -0
  218. data/aws-crt-ffi/crt/s2n/tests/litani/examples/add-root-node/original-run.sh +52 -0
  219. data/aws-crt-ffi/crt/s2n/tests/litani/examples/add-root-node/run-all.py +71 -0
  220. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/README +13 -0
  221. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-1.sh +34 -0
  222. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-2.sh +35 -0
  223. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-3.sh +34 -0
  224. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-all.py +60 -0
  225. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/README.md +10 -0
  226. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/assumptions.html +42 -0
  227. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/file.dat +7 -0
  228. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/histogram.dat +7 -0
  229. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-1.sh +41 -0
  230. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-2.sh +47 -0
  231. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-3.sh +41 -0
  232. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-all.py +34 -0
  233. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/fib-table.py +40 -0
  234. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/fib.plt +5 -0
  235. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/fib.py +32 -0
  236. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/sin-output.py +40 -0
  237. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/sin.plt +5 -0
  238. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/sin.py +30 -0
  239. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/templates/fib-table.jinja.html +45 -0
  240. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/templates/sin-output.jinja.html +30 -0
  241. data/aws-crt-ffi/crt/s2n/tests/litani/lib/add_job.py +55 -0
  242. data/aws-crt-ffi/crt/s2n/tests/litani/lib/graph.py +2 -2
  243. data/aws-crt-ffi/crt/s2n/tests/litani/lib/litani.py +6 -1
  244. data/aws-crt-ffi/crt/s2n/tests/litani/lib/litani_report.py +18 -21
  245. data/aws-crt-ffi/crt/s2n/tests/litani/lib/ninja.py +2 -0
  246. data/aws-crt-ffi/crt/s2n/tests/litani/lib/run_printer.py +26 -7
  247. data/aws-crt-ffi/crt/s2n/tests/litani/lib/transform_jobs.py +84 -0
  248. data/aws-crt-ffi/crt/s2n/tests/litani/litani +28 -33
  249. data/aws-crt-ffi/crt/s2n/tests/litani/script/release +220 -0
  250. data/aws-crt-ffi/crt/s2n/tests/litani/templates/dashboard.jinja.html +78 -15
  251. data/aws-crt-ffi/crt/s2n/tests/litani/templates/pipeline.jinja.html +21 -5
  252. data/aws-crt-ffi/crt/s2n/tests/litani/test/README +15 -0
  253. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/run +56 -33
  254. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/custom_stages.py +1 -0
  255. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/cwd.py +1 -0
  256. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/dump_run.py +1 -0
  257. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/graph_line_break.py +1 -0
  258. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/html_node.py +1 -0
  259. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/job_id_env.py +1 -0
  260. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/multiproc_dump_run.py +1 -0
  261. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_pool_serialize.py +1 -0
  262. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_pool_serialize_graph.py +1 -0
  263. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_timed_out.py +1 -0
  264. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_timed_out_timeout_ignored.py +1 -0
  265. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_timed_out_timeout_ok.py +1 -0
  266. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/pipeline_order.py +53 -0
  267. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/pool_serialize.py +1 -0
  268. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/pool_serialize_graph.py +1 -0
  269. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/single_pool.py +1 -0
  270. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out.py +1 -0
  271. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_subprocess.py +1 -0
  272. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_subprocess_multi_shell.py +1 -0
  273. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_subprocess_shell.py +1 -0
  274. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_timeout_ignored.py +1 -0
  275. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_timeout_ok.py +1 -0
  276. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/transform_delete_job.py +54 -0
  277. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/transform_modify_job.py +46 -0
  278. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/transform_no_change_job.py +44 -0
  279. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/zero_pool.py +1 -0
  280. data/aws-crt-ffi/crt/s2n/tests/litani/test/run +82 -12
  281. data/aws-crt-ffi/crt/s2n/tests/s2n_test.h +58 -33
  282. data/aws-crt-ffi/crt/s2n/tests/testlib/s2n_key_schedule_testlib.c +18 -6
  283. data/aws-crt-ffi/crt/s2n/tests/testlib/s2n_pq_kat_test_utils.c +4 -4
  284. data/aws-crt-ffi/crt/s2n/tests/testlib/s2n_testlib.h +2 -0
  285. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_client_hello_retry_test.c +66 -2
  286. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_connection_test.c +1 -1
  287. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_drbg_test.c +34 -14
  288. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_fork_generation_number_test.c +28 -5
  289. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_mem_usage_test.c +6 -0
  290. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_override_openssl_random_test.c +1 -1
  291. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_random_test.c +60 -41
  292. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_self_talk_broken_pipe_test.c +2 -2
  293. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_handshake_early_data_test.c +3 -1
  294. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_hybrid_shared_secret_test.c +9 -1
  295. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_key_schedule_rfc8448_test.c +31 -130
  296. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_key_schedule_test.c +2 -4
  297. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_pq_handshake_test.c +11 -6
  298. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_secrets_rfc8448_test.c +19 -21
  299. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_secrets_test.c +109 -60
  300. data/aws-crt-ffi/crt/s2n/tls/s2n_config.c +1 -0
  301. data/aws-crt-ffi/crt/s2n/tls/s2n_config.h +1 -1
  302. data/aws-crt-ffi/crt/s2n/tls/s2n_connection.c +29 -24
  303. data/aws-crt-ffi/crt/s2n/tls/s2n_connection.h +5 -5
  304. data/aws-crt-ffi/crt/s2n/tls/s2n_handshake_hashes.h +1 -7
  305. data/aws-crt-ffi/crt/s2n/tls/s2n_handshake_io.c +2 -0
  306. data/aws-crt-ffi/crt/s2n/tls/s2n_handshake_transcript.c +0 -44
  307. data/aws-crt-ffi/crt/s2n/tls/s2n_internal.h +0 -1
  308. data/aws-crt-ffi/crt/s2n/tls/s2n_quic_support.h +1 -1
  309. data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_key_schedule.c +1 -2
  310. data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_secrets.c +84 -44
  311. data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_secrets.h +3 -9
  312. data/aws-crt-ffi/crt/s2n/utils/s2n_blob.h +15 -8
  313. data/aws-crt-ffi/crt/s2n/utils/s2n_fork_detection.c +2 -6
  314. data/aws-crt-ffi/crt/s2n/utils/s2n_random.c +9 -9
  315. data/aws-crt-ffi/src/input_stream.c +32 -15
  316. data/ext/compile.rb +13 -5
  317. data/lib/aws-crt/platforms.rb +14 -5
  318. data/lib/aws-crt/string_blob.rb +3 -3
  319. metadata +61 -7
  320. data/aws-crt-ffi/crt/aws-c-auth/source/external/cJSON.c +0 -2987
  321. data/aws-crt-ffi/crt/aws-c-auth/tests/external/cJSON.c +0 -2986
  322. data/aws-crt-ffi/crt/aws-c-io/tests/error_test.c +0 -20
@@ -17,7 +17,9 @@
17
17
  #include <aws/http/private/http2_stream_manager_impl.h>
18
18
  #include <aws/http/private/proxy_impl.h>
19
19
  #include <aws/http/proxy.h>
20
+ #include <aws/http/statistics.h>
20
21
 
22
+ #include <aws/io/stream.h>
21
23
  #include <aws/io/uri.h>
22
24
 
23
25
  #include <aws/common/byte_buf.h>
@@ -41,8 +43,18 @@ struct sm_tester_options {
41
43
  size_t max_connections;
42
44
  size_t ideal_concurrent_streams_per_connection;
43
45
  size_t max_concurrent_streams_per_connection;
46
+
47
+ const struct aws_http_connection_monitoring_options *monitor_opt;
48
+
49
+ struct aws_byte_cursor *uri_cursor;
50
+ const enum aws_log_level *log_level;
51
+ bool prior_knowledge;
52
+ bool close_connection_on_server_error;
53
+ size_t connection_ping_period_ms;
54
+ size_t connection_ping_timeout_ms;
44
55
  };
45
56
 
57
+ static struct aws_logger s_logger;
46
58
  struct sm_tester {
47
59
  struct aws_allocator *allocator;
48
60
  struct aws_event_loop_group *event_loop_group;
@@ -53,7 +65,7 @@ struct sm_tester {
53
65
  struct aws_http2_stream_manager *stream_manager;
54
66
  struct aws_http_connection_manager *connection_manager;
55
67
 
56
- struct aws_string *host;
68
+ struct aws_uri endpoint;
57
69
  struct aws_tls_ctx *tls_ctx;
58
70
  struct aws_tls_ctx_options tls_ctx_options;
59
71
  struct aws_tls_connection_options tls_connection_options;
@@ -63,16 +75,19 @@ struct sm_tester {
63
75
  struct aws_condition_variable signal;
64
76
 
65
77
  struct aws_array_list streams;
78
+ size_t wait_for_stream_acquire_count;
66
79
  size_t acquiring_stream_errors;
67
- size_t stream_complete_errors;
68
80
  int error_code;
81
+
82
+ size_t wait_for_stream_completed_count;
83
+ size_t stream_completed_count;
84
+ size_t stream_complete_errors;
85
+ size_t stream_200_count;
86
+ size_t stream_status_not_200_count;
69
87
  int stream_completed_error_code;
70
88
 
71
- size_t wait_for_stream_count;
72
89
  bool is_shutdown_complete;
73
90
 
74
- bool real_connection;
75
-
76
91
  /* Fake HTTP/2 connection */
77
92
  size_t wait_for_fake_connection_count;
78
93
 
@@ -91,6 +106,8 @@ struct sm_tester {
91
106
 
92
107
  /* To invoke the real on_setup */
93
108
  aws_http_on_client_connection_setup_fn *on_setup;
109
+
110
+ size_t length_sent;
94
111
  };
95
112
 
96
113
  static struct sm_tester s_tester;
@@ -179,6 +196,14 @@ static int s_tester_init(struct sm_tester_options *options) {
179
196
 
180
197
  s_tester.allocator = alloc;
181
198
 
199
+ struct aws_logger_standard_options logger_options = {
200
+ .level = options->log_level ? *options->log_level : AWS_LOG_LEVEL_TRACE,
201
+ .file = stderr,
202
+ };
203
+
204
+ aws_logger_init_standard(&s_logger, alloc, &logger_options);
205
+ aws_logger_set(&s_logger);
206
+
182
207
  ASSERT_SUCCESS(aws_mutex_init(&s_tester.lock));
183
208
  ASSERT_SUCCESS(aws_condition_variable_init(&s_tester.signal));
184
209
 
@@ -207,30 +232,60 @@ static int s_tester_init(struct sm_tester_options *options) {
207
232
  .connect_timeout_ms = (uint32_t)aws_timestamp_convert(10, AWS_TIMESTAMP_SECS, AWS_TIMESTAMP_MILLIS, NULL),
208
233
  };
209
234
 
210
- aws_tls_ctx_options_init_default_client(&s_tester.tls_ctx_options, alloc);
211
- if (!options->no_http2) {
212
- ASSERT_SUCCESS(aws_tls_ctx_options_set_alpn_list(&s_tester.tls_ctx_options, "h2"));
235
+ if (options->uri_cursor) {
236
+ ASSERT_SUCCESS(aws_uri_init_parse(&s_tester.endpoint, alloc, options->uri_cursor));
237
+ } else {
238
+ struct aws_byte_cursor default_host = aws_byte_cursor_from_c_str("https://example.com");
239
+ ASSERT_SUCCESS(aws_uri_init_parse(&s_tester.endpoint, alloc, &default_host));
213
240
  }
214
- s_tester.tls_ctx = aws_tls_client_ctx_new(alloc, &s_tester.tls_ctx_options);
215
241
 
216
- ASSERT_NOT_NULL(s_tester.tls_ctx);
242
+ bool use_tls = true;
243
+ uint16_t port = 443;
244
+ if (!s_tester.endpoint.scheme.len && (s_tester.endpoint.port == 80 || s_tester.endpoint.port == 8080)) {
245
+ use_tls = false;
246
+ } else {
247
+ if (aws_byte_cursor_eq_c_str_ignore_case(&s_tester.endpoint.scheme, "http")) {
248
+ use_tls = false;
249
+ }
250
+ }
251
+ if (s_tester.endpoint.port) {
252
+ port = s_tester.endpoint.port;
253
+ } else if (aws_byte_cursor_eq_c_str_ignore_case(&s_tester.endpoint.scheme, "http")) {
254
+ port = 80;
255
+ }
217
256
 
218
- s_tester.host = aws_string_new_from_c_str(alloc, "www.google.com");
219
- struct aws_byte_cursor server_name = aws_byte_cursor_from_string(s_tester.host);
220
- aws_tls_connection_options_init_from_ctx(&s_tester.tls_connection_options, s_tester.tls_ctx);
221
- aws_tls_connection_options_set_server_name(&s_tester.tls_connection_options, alloc, &server_name);
257
+ if (use_tls) {
258
+ aws_tls_ctx_options_init_default_client(&s_tester.tls_ctx_options, alloc);
259
+ if (!options->no_http2) {
260
+ ASSERT_SUCCESS(aws_tls_ctx_options_set_alpn_list(&s_tester.tls_ctx_options, "h2"));
261
+ }
262
+ if (aws_byte_cursor_eq_c_str_ignore_case(&s_tester.endpoint.host_name, "localhost")) {
263
+ /* Turn off peer verification as a localhost cert used */
264
+ s_tester.tls_ctx_options.verify_peer = false;
265
+ }
266
+ s_tester.tls_ctx = aws_tls_client_ctx_new(alloc, &s_tester.tls_ctx_options);
222
267
 
268
+ ASSERT_NOT_NULL(s_tester.tls_ctx);
269
+ aws_tls_connection_options_init_from_ctx(&s_tester.tls_connection_options, s_tester.tls_ctx);
270
+ aws_tls_connection_options_set_server_name(
271
+ &s_tester.tls_connection_options, alloc, &s_tester.endpoint.host_name);
272
+ }
223
273
  struct aws_http2_stream_manager_options sm_options = {
224
274
  .bootstrap = s_tester.client_bootstrap,
225
275
  .socket_options = &socket_options,
226
- .tls_connection_options = &s_tester.tls_connection_options,
227
- .host = server_name,
228
- .port = 443,
276
+ .tls_connection_options = use_tls ? &s_tester.tls_connection_options : NULL,
277
+ .host = s_tester.endpoint.host_name,
278
+ .port = port,
229
279
  .ideal_concurrent_streams_per_connection = options->ideal_concurrent_streams_per_connection,
230
280
  .max_concurrent_streams_per_connection = options->max_concurrent_streams_per_connection,
231
281
  .max_connections = options->max_connections,
232
282
  .shutdown_complete_user_data = &s_tester,
233
283
  .shutdown_complete_callback = s_sm_tester_on_sm_shutdown_complete,
284
+ .monitoring_options = options->monitor_opt,
285
+ .close_connection_on_server_error = options->close_connection_on_server_error,
286
+ .connection_ping_period_ms = options->connection_ping_period_ms,
287
+ .connection_ping_timeout_ms = options->connection_ping_timeout_ms,
288
+ .http2_prior_knowledge = options->prior_knowledge,
234
289
  };
235
290
  s_tester.stream_manager = aws_http2_stream_manager_new(alloc, &sm_options);
236
291
 
@@ -370,7 +425,8 @@ static int s_tester_clean_up(void) {
370
425
  aws_mutex_clean_up(&s_tester.lock);
371
426
  aws_condition_variable_clean_up(&s_tester.signal);
372
427
  aws_array_list_clean_up(&s_tester.streams);
373
- aws_string_destroy(s_tester.host);
428
+ aws_uri_clean_up(&s_tester.endpoint);
429
+ aws_logger_clean_up(&s_logger);
374
430
 
375
431
  return AWS_OP_SUCCESS;
376
432
  }
@@ -382,6 +438,7 @@ static void s_sm_tester_on_stream_acquired(struct aws_http_stream *stream, int e
382
438
 
383
439
  if (error_code) {
384
440
  ++s_tester.acquiring_stream_errors;
441
+ ++s_tester.stream_completed_count; /* As the stream will never be completed through complete callback */
385
442
  s_tester.error_code = error_code;
386
443
  } else {
387
444
  aws_array_list_push_back(&s_tester.streams, &stream);
@@ -392,18 +449,34 @@ static void s_sm_tester_on_stream_acquired(struct aws_http_stream *stream, int e
392
449
  AWS_FATAL_ASSERT(aws_mutex_unlock(&s_tester.lock) == AWS_OP_SUCCESS);
393
450
  }
394
451
 
395
- static bool s_is_stream_reply_count_at_least(void *context) {
452
+ static bool s_is_stream_acquired_count_at_least(void *context) {
396
453
  (void)context;
397
- return s_tester.wait_for_stream_count <=
454
+ return s_tester.wait_for_stream_acquire_count <=
398
455
  aws_array_list_length(&s_tester.streams) + s_tester.acquiring_stream_errors;
399
456
  }
400
457
 
401
- static int s_wait_on_streams_reply_count(size_t count) {
458
+ static int s_wait_on_streams_acquired_count(size_t count) {
402
459
  ASSERT_SUCCESS(aws_mutex_lock(&s_tester.lock));
403
460
 
404
- s_tester.wait_for_stream_count = count;
461
+ s_tester.wait_for_stream_acquire_count = count;
405
462
  int signal_error =
406
- aws_condition_variable_wait_pred(&s_tester.signal, &s_tester.lock, s_is_stream_reply_count_at_least, NULL);
463
+ aws_condition_variable_wait_pred(&s_tester.signal, &s_tester.lock, s_is_stream_acquired_count_at_least, NULL);
464
+
465
+ ASSERT_SUCCESS(aws_mutex_unlock(&s_tester.lock));
466
+ return signal_error;
467
+ }
468
+
469
+ static bool s_is_stream_completed_count_at_least(void *context) {
470
+ (void)context;
471
+ return s_tester.wait_for_stream_completed_count <= s_tester.stream_completed_count;
472
+ }
473
+
474
+ static int s_wait_on_streams_completed_count(size_t count) {
475
+ ASSERT_SUCCESS(aws_mutex_lock(&s_tester.lock));
476
+
477
+ s_tester.wait_for_stream_completed_count = count;
478
+ int signal_error =
479
+ aws_condition_variable_wait_pred(&s_tester.signal, &s_tester.lock, s_is_stream_completed_count_at_least, NULL);
407
480
 
408
481
  ASSERT_SUCCESS(aws_mutex_unlock(&s_tester.lock));
409
482
  return signal_error;
@@ -416,19 +489,58 @@ static void s_sm_tester_on_stream_complete(struct aws_http_stream *stream, int e
416
489
  if (error_code) {
417
490
  ++s_tester.stream_complete_errors;
418
491
  s_tester.stream_completed_error_code = error_code;
492
+ } else {
493
+ int status = 0;
494
+ if (aws_http_stream_get_incoming_response_status(stream, &status)) {
495
+ ++s_tester.stream_complete_errors;
496
+ s_tester.stream_completed_error_code = aws_last_error();
497
+ } else {
498
+ if (status == 200) {
499
+ ++s_tester.stream_200_count;
500
+ } else {
501
+ ++s_tester.stream_status_not_200_count;
502
+ }
503
+ }
419
504
  }
505
+ ++s_tester.stream_completed_count;
506
+ aws_condition_variable_notify_one(&s_tester.signal);
420
507
  AWS_FATAL_ASSERT(aws_mutex_unlock(&s_tester.lock) == AWS_OP_SUCCESS);
421
508
  }
422
509
 
510
+ static int s_sm_stream_acquiring_customize_request(
511
+ int num_streams,
512
+ struct aws_http_make_request_options *request_options) {
513
+ struct aws_http2_stream_manager_acquire_stream_options acquire_stream_option = {
514
+ .options = request_options,
515
+ .callback = s_sm_tester_on_stream_acquired,
516
+ .user_data = &s_tester,
517
+ };
518
+ for (int i = 0; i < num_streams; ++i) {
519
+ /* TODO: Test the callback will always be fired asynced, as now the CM cannot ensure the callback happens
520
+ * asynchronously, we cannot ensure it as well. */
521
+ aws_http2_stream_manager_acquire_stream(s_tester.stream_manager, &acquire_stream_option);
522
+ }
523
+ return AWS_OP_SUCCESS;
524
+ }
525
+
423
526
  static int s_sm_stream_acquiring(int num_streams) {
424
527
  struct aws_http_message *request = aws_http2_message_new_request(s_tester.allocator);
425
528
  ASSERT_NOT_NULL(request);
426
529
 
427
530
  struct aws_http_header request_headers_src[] = {
428
531
  DEFINE_HEADER(":method", "GET"),
429
- DEFINE_HEADER(":scheme", "https"),
430
- DEFINE_HEADER(":path", "/"),
431
- DEFINE_HEADER(":authority", aws_string_c_str(s_tester.host)),
532
+ {
533
+ .name = aws_byte_cursor_from_c_str(":scheme"),
534
+ .value = *aws_uri_scheme(&s_tester.endpoint),
535
+ },
536
+ {
537
+ .name = aws_byte_cursor_from_c_str(":path"),
538
+ .value = *aws_uri_path(&s_tester.endpoint),
539
+ },
540
+ {
541
+ .name = aws_byte_cursor_from_c_str(":authority"),
542
+ .value = *aws_uri_host_name(&s_tester.endpoint),
543
+ },
432
544
  };
433
545
  aws_http_message_add_header_array(request, request_headers_src, AWS_ARRAY_SIZE(request_headers_src));
434
546
  struct aws_http_make_request_options request_options = {
@@ -437,18 +549,9 @@ static int s_sm_stream_acquiring(int num_streams) {
437
549
  .user_data = &s_tester,
438
550
  .on_complete = s_sm_tester_on_stream_complete,
439
551
  };
440
- struct aws_http2_stream_manager_acquire_stream_options acquire_stream_option = {
441
- .options = &request_options,
442
- .callback = s_sm_tester_on_stream_acquired,
443
- .user_data = &s_tester,
444
- };
445
- for (int i = 0; i < num_streams; ++i) {
446
- /* TODO: Test the callback will always be fired asynced, as now the CM cannot ensure the callback happens
447
- * asynchronously, we cannot ensure it as well. */
448
- aws_http2_stream_manager_acquire_stream(s_tester.stream_manager, &acquire_stream_option);
449
- }
552
+ int return_code = s_sm_stream_acquiring_customize_request(num_streams, &request_options);
450
553
  aws_http_message_release(request);
451
- return AWS_OP_SUCCESS;
554
+ return return_code;
452
555
  }
453
556
 
454
557
  /* Test the common setup/teardown used by all tests in this file */
@@ -595,7 +698,7 @@ TEST_CASE(h2_sm_mock_connection) {
595
698
  /* waiting for one fake connection made */
596
699
  ASSERT_SUCCESS(s_wait_on_fake_connection_count(1));
597
700
  s_drain_all_fake_connection_testing_channel();
598
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(num_to_acquire));
701
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(num_to_acquire));
599
702
  ASSERT_SUCCESS(s_complete_all_fake_connection_streams());
600
703
 
601
704
  return s_tester_clean_up();
@@ -620,7 +723,7 @@ TEST_CASE(h2_sm_mock_multiple_connections) {
620
723
  /* waiting for one fake connection made */
621
724
  ASSERT_SUCCESS(s_wait_on_fake_connection_count(num_expected_connection));
622
725
  s_drain_all_fake_connection_testing_channel();
623
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(num_streams_to_acquire));
726
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(num_streams_to_acquire));
624
727
  ASSERT_TRUE(aws_array_list_length(&s_tester.fake_connections) == (size_t)num_expected_connection);
625
728
  ASSERT_SUCCESS(s_complete_all_fake_connection_streams());
626
729
 
@@ -649,7 +752,7 @@ TEST_CASE(h2_sm_mock_bad_connection_acquired) {
649
752
  /* waiting for 3 fake connection made as the first two connection will fail */
650
753
  ASSERT_SUCCESS(s_wait_on_fake_connection_count(good_connections_num));
651
754
  s_drain_all_fake_connection_testing_channel();
652
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(streams_acquiring_num));
755
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(streams_acquiring_num));
653
756
  /* We fail the number of streams cannot fit into the health connections based on the ideal. */
654
757
  ASSERT_INT_EQUALS(
655
758
  streams_acquiring_num - options.ideal_concurrent_streams_per_connection * good_connections_num,
@@ -662,7 +765,7 @@ TEST_CASE(h2_sm_mock_bad_connection_acquired) {
662
765
  /* waiting for the new connection */
663
766
  ASSERT_SUCCESS(s_wait_on_fake_connection_count(options.max_connections + 2));
664
767
  s_drain_all_fake_connection_testing_channel();
665
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(streams_acquiring_num + 4));
768
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(streams_acquiring_num + 4));
666
769
  /* all the new streams succeed */
667
770
  ASSERT_TRUE(aws_array_list_length(&s_tester.streams) == 10);
668
771
  ASSERT_SUCCESS(s_complete_all_fake_connection_streams());
@@ -670,7 +773,7 @@ TEST_CASE(h2_sm_mock_bad_connection_acquired) {
670
773
  return s_tester_clean_up();
671
774
  }
672
775
 
673
- /* Test a connection offerred, and before the stream was made, the connection dies. The stream should fail */
776
+ /* Test a connection offered, and before the stream was made, the connection dies. The stream should fail */
674
777
  TEST_CASE(h2_sm_mock_connections_closed_before_request_made) {
675
778
  (void)ctx;
676
779
  struct sm_tester_options options = {
@@ -684,7 +787,7 @@ TEST_CASE(h2_sm_mock_connections_closed_before_request_made) {
684
787
  /* waiting for one fake connection made */
685
788
  ASSERT_SUCCESS(s_wait_on_fake_connection_count(1));
686
789
  s_drain_all_fake_connection_testing_channel();
687
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(2));
790
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(2));
688
791
  /* No error happens */
689
792
  ASSERT_INT_EQUALS(0, s_tester.acquiring_stream_errors);
690
793
  /* Now, we close the connection, the stream manager will fail the new stream, if the opening streams not completed.
@@ -693,7 +796,7 @@ TEST_CASE(h2_sm_mock_connections_closed_before_request_made) {
693
796
  aws_http_connection_close(fake_connection->connection);
694
797
  ASSERT_SUCCESS(s_sm_stream_acquiring(1));
695
798
  s_drain_all_fake_connection_testing_channel();
696
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(3));
799
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(3));
697
800
  /* ASSERT new one failed. */
698
801
  ASSERT_INT_EQUALS(1, s_tester.acquiring_stream_errors);
699
802
  ASSERT_INT_EQUALS(AWS_ERROR_HTTP_CONNECTION_CLOSED, s_tester.error_code);
@@ -734,7 +837,7 @@ TEST_CASE(h2_sm_mock_max_concurrent_streams_remote) {
734
837
  /* waiting for one fake connection made */
735
838
  ASSERT_SUCCESS(s_wait_on_fake_connection_count(1));
736
839
  s_drain_all_fake_connection_testing_channel();
737
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(1));
840
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(1));
738
841
  ASSERT_INT_EQUALS(0, s_tester.acquiring_stream_errors);
739
842
  ASSERT_INT_EQUALS(0, s_tester.stream_complete_errors);
740
843
 
@@ -744,7 +847,7 @@ TEST_CASE(h2_sm_mock_max_concurrent_streams_remote) {
744
847
  /* We created a new connection */
745
848
  ASSERT_SUCCESS(s_wait_on_fake_connection_count(2));
746
849
  s_drain_all_fake_connection_testing_channel();
747
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(1 + 2));
850
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(1 + 2));
748
851
  ASSERT_INT_EQUALS(0, s_tester.acquiring_stream_errors);
749
852
 
750
853
  ASSERT_INT_EQUALS(2, aws_array_list_length(&s_tester.fake_connections));
@@ -753,6 +856,56 @@ TEST_CASE(h2_sm_mock_max_concurrent_streams_remote) {
753
856
  return s_tester_clean_up();
754
857
  }
755
858
 
859
+ /* Test that the remote max concurrent streams setting hit */
860
+ TEST_CASE(h2_sm_mock_fetch_metric) {
861
+ (void)ctx;
862
+ struct sm_tester_options options = {
863
+ .max_connections = 5,
864
+ .alloc = allocator,
865
+ };
866
+ ASSERT_SUCCESS(s_tester_init(&options));
867
+ s_override_cm_connect_function(s_aws_http_connection_manager_create_connection_sync_mock);
868
+ /* Set the remote max to be 2 */
869
+ s_tester.max_con_stream_remote = 2;
870
+ /* Acquire a stream to trigger */
871
+ ASSERT_SUCCESS(s_sm_stream_acquiring(1));
872
+ /* waiting for one fake connection made */
873
+ ASSERT_SUCCESS(s_wait_on_fake_connection_count(1));
874
+ s_drain_all_fake_connection_testing_channel();
875
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(1));
876
+ struct aws_http_manager_metrics out_metrics;
877
+ AWS_ZERO_STRUCT(out_metrics);
878
+
879
+ aws_http2_stream_manager_fetch_metrics(s_tester.stream_manager, &out_metrics);
880
+ /* Acquired 1 stream, and we hold one connection, the max streams per connection is 2. */
881
+ ASSERT_UINT_EQUALS(out_metrics.available_concurrency, 1);
882
+ ASSERT_UINT_EQUALS(out_metrics.pending_concurrency_acquires, 0);
883
+
884
+ ASSERT_SUCCESS(s_sm_stream_acquiring(1));
885
+
886
+ ASSERT_SUCCESS(s_wait_on_fake_connection_count(1));
887
+ s_drain_all_fake_connection_testing_channel();
888
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(2));
889
+ aws_http2_stream_manager_fetch_metrics(s_tester.stream_manager, &out_metrics);
890
+ ASSERT_UINT_EQUALS(out_metrics.available_concurrency, 0);
891
+ ASSERT_UINT_EQUALS(out_metrics.pending_concurrency_acquires, 0);
892
+
893
+ ASSERT_SUCCESS(s_sm_stream_acquiring(10));
894
+ ASSERT_SUCCESS(s_wait_on_fake_connection_count(5));
895
+ s_drain_all_fake_connection_testing_channel();
896
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(10));
897
+ aws_http2_stream_manager_fetch_metrics(s_tester.stream_manager, &out_metrics);
898
+ ASSERT_UINT_EQUALS(out_metrics.available_concurrency, 0);
899
+ ASSERT_UINT_EQUALS(out_metrics.pending_concurrency_acquires, 2);
900
+
901
+ ASSERT_SUCCESS(s_complete_all_fake_connection_streams());
902
+ /* Still have two more streams that have not been completed */
903
+ s_drain_all_fake_connection_testing_channel();
904
+ ASSERT_SUCCESS(s_complete_all_fake_connection_streams());
905
+
906
+ return s_tester_clean_up();
907
+ }
908
+
756
909
  /* Test that the stream completed will free the connection for more streams */
757
910
  TEST_CASE(h2_sm_mock_complete_stream) {
758
911
  (void)ctx;
@@ -768,7 +921,7 @@ TEST_CASE(h2_sm_mock_complete_stream) {
768
921
  /* waiting for one fake connection made */
769
922
  ASSERT_SUCCESS(s_wait_on_fake_connection_count(1));
770
923
  s_drain_all_fake_connection_testing_channel();
771
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(2));
924
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(2));
772
925
  ASSERT_INT_EQUALS(1, aws_array_list_length(&s_tester.fake_connections));
773
926
 
774
927
  /* Fake peer send settings that only allow 2 concurrent streams */
@@ -779,7 +932,7 @@ TEST_CASE(h2_sm_mock_complete_stream) {
779
932
  /* Acquire a new streams */
780
933
  ASSERT_SUCCESS(s_sm_stream_acquiring(1));
781
934
  s_drain_all_fake_connection_testing_channel();
782
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(2 + 1));
935
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(2 + 1));
783
936
  ASSERT_INT_EQUALS(0, s_tester.acquiring_stream_errors);
784
937
  /* No error happens */
785
938
  ASSERT_INT_EQUALS(0, s_tester.stream_complete_errors);
@@ -806,7 +959,7 @@ TEST_CASE(h2_sm_mock_ideal_num_streams) {
806
959
  /* We will create 5 connections instead of 3 */
807
960
  ASSERT_SUCCESS(s_wait_on_fake_connection_count(5));
808
961
  s_drain_all_fake_connection_testing_channel();
809
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(15));
962
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(15));
810
963
  ASSERT_INT_EQUALS(5, aws_array_list_length(&s_tester.fake_connections));
811
964
 
812
965
  s_drain_all_fake_connection_testing_channel();
@@ -820,7 +973,7 @@ TEST_CASE(h2_sm_mock_ideal_num_streams) {
820
973
  /* Acquire 15 more, we can only have 25 (5*5) in total */
821
974
  ASSERT_SUCCESS(s_sm_stream_acquiring(15));
822
975
  s_drain_all_fake_connection_testing_channel();
823
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(10));
976
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(10));
824
977
 
825
978
  s_drain_all_fake_connection_testing_channel();
826
979
  /* Check all the 5 fake connections received 5 streams each */
@@ -853,7 +1006,7 @@ TEST_CASE(h2_sm_mock_large_ideal_num_streams) {
853
1006
  /* We will create 3 connections instead of 2 */
854
1007
  ASSERT_SUCCESS(s_wait_on_fake_connection_count(3));
855
1008
  s_drain_all_fake_connection_testing_channel();
856
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(6));
1009
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(6));
857
1010
  ASSERT_INT_EQUALS(3, aws_array_list_length(&s_tester.fake_connections));
858
1011
 
859
1012
  s_drain_all_fake_connection_testing_channel();
@@ -866,7 +1019,7 @@ TEST_CASE(h2_sm_mock_large_ideal_num_streams) {
866
1019
  /* Acquire 15 more, we can only have 10 (2*5) in total. 21 acquisitions made */
867
1020
  ASSERT_SUCCESS(s_sm_stream_acquiring(15));
868
1021
  s_drain_all_fake_connection_testing_channel();
869
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(10 - 6));
1022
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(10 - 6));
870
1023
 
871
1024
  s_drain_all_fake_connection_testing_channel();
872
1025
  for (size_t i = 0; i < aws_array_list_length(&s_tester.fake_connections); ++i) {
@@ -903,7 +1056,7 @@ TEST_CASE(h2_sm_mock_goaway) {
903
1056
  /* waiting for one fake connection made */
904
1057
  ASSERT_SUCCESS(s_wait_on_fake_connection_count(1));
905
1058
  s_drain_all_fake_connection_testing_channel();
906
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(5));
1059
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(5));
907
1060
  ASSERT_INT_EQUALS(1, aws_array_list_length(&s_tester.fake_connections));
908
1061
  ASSERT_INT_EQUALS(0, s_tester.acquiring_stream_errors);
909
1062
 
@@ -928,7 +1081,7 @@ TEST_CASE(h2_sm_mock_goaway) {
928
1081
  /* waiting for one fake connection made */
929
1082
  ASSERT_SUCCESS(s_wait_on_fake_connection_count(2));
930
1083
  s_drain_all_fake_connection_testing_channel();
931
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(5 + 5));
1084
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(5 + 5));
932
1085
  ASSERT_INT_EQUALS(0, s_tester.acquiring_stream_errors);
933
1086
  /* No more stream completed with error */
934
1087
  ASSERT_INT_EQUALS(4, s_tester.stream_complete_errors);
@@ -942,6 +1095,74 @@ TEST_CASE(h2_sm_mock_goaway) {
942
1095
  return s_tester_clean_up();
943
1096
  }
944
1097
 
1098
+ /* Test that PING works as expected. */
1099
+ TEST_CASE(h2_sm_connection_ping) {
1100
+ (void)ctx;
1101
+ size_t connection_ping_timeout_ms = AWS_TIMESTAMP_MILLIS; /* 1 sec */
1102
+ struct sm_tester_options options = {
1103
+ .max_connections = 3,
1104
+ .alloc = allocator,
1105
+ .max_concurrent_streams_per_connection = 2,
1106
+ .connection_ping_period_ms = 2 * AWS_TIMESTAMP_MILLIS,
1107
+ .connection_ping_timeout_ms = connection_ping_timeout_ms,
1108
+ };
1109
+ ASSERT_SUCCESS(s_tester_init(&options));
1110
+ s_override_cm_connect_function(s_aws_http_connection_manager_create_connection_sync_mock);
1111
+ ASSERT_SUCCESS(s_sm_stream_acquiring(6));
1112
+ /* waiting for one fake connection made */
1113
+ ASSERT_SUCCESS(s_wait_on_fake_connection_count(3));
1114
+ s_drain_all_fake_connection_testing_channel();
1115
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(6));
1116
+ ASSERT_INT_EQUALS(0, s_tester.acquiring_stream_errors);
1117
+
1118
+ aws_thread_current_sleep(2 * AWS_TIMESTAMP_NANOS); /* Sleep 2 sec */
1119
+
1120
+ /* Check PING received for all the connections */
1121
+ struct sm_fake_connection *fake_connection_1 = s_get_fake_connection(0);
1122
+ struct sm_fake_connection *fake_connection_2 = s_get_fake_connection(1);
1123
+ struct sm_fake_connection *fake_connection_3 = s_get_fake_connection(2);
1124
+ testing_channel_drain_queued_tasks(&fake_connection_1->testing_channel);
1125
+ testing_channel_drain_queued_tasks(&fake_connection_2->testing_channel);
1126
+ testing_channel_drain_queued_tasks(&fake_connection_3->testing_channel);
1127
+ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&fake_connection_1->peer));
1128
+ struct h2_decoded_frame *ping_frame =
1129
+ h2_decode_tester_find_frame(&fake_connection_1->peer.decode, AWS_H2_FRAME_T_PING, 0, NULL);
1130
+ ASSERT_NOT_NULL(ping_frame);
1131
+
1132
+ /* Fake peer only send PINGACK to the first connection immediately */
1133
+ ASSERT_SUCCESS(h2_fake_peer_send_connection_preface_default_settings(&fake_connection_1->peer));
1134
+ struct aws_h2_frame *peer_frame = aws_h2_frame_new_ping(allocator, true /*ACK*/, ping_frame->ping_opaque_data);
1135
+ ASSERT_SUCCESS(h2_fake_peer_send_frame(&fake_connection_1->peer, peer_frame));
1136
+ testing_channel_drain_queued_tasks(&fake_connection_1->testing_channel);
1137
+ s_fake_connection_complete_streams(
1138
+ fake_connection_1, 0 /*all streams*/); /* Make sure the streams completed successfully */
1139
+
1140
+ /* Check fake connection 2 received PING */
1141
+ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&fake_connection_2->peer));
1142
+ ping_frame = h2_decode_tester_find_frame(&fake_connection_2->peer.decode, AWS_H2_FRAME_T_PING, 0, NULL);
1143
+ ASSERT_NOT_NULL(ping_frame);
1144
+ /* Check fake connection 3 received PING, but never send ping for connection 3 */
1145
+ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&fake_connection_3->peer));
1146
+ ping_frame = h2_decode_tester_find_frame(&fake_connection_3->peer.decode, AWS_H2_FRAME_T_PING, 0, NULL);
1147
+ ASSERT_NOT_NULL(ping_frame);
1148
+
1149
+ aws_thread_current_sleep(AWS_TIMESTAMP_NANOS); /* Sleep 1 sec */
1150
+ testing_channel_drain_queued_tasks(&fake_connection_2->testing_channel);
1151
+ testing_channel_drain_queued_tasks(&fake_connection_3->testing_channel);
1152
+
1153
+ /* Send PINGACK for connection 2 after timeout has happened */
1154
+ ASSERT_SUCCESS(h2_fake_peer_send_connection_preface_default_settings(&fake_connection_2->peer));
1155
+ peer_frame = aws_h2_frame_new_ping(allocator, true /*ACK*/, ping_frame->ping_opaque_data);
1156
+ ASSERT_SUCCESS(h2_fake_peer_send_frame(&fake_connection_2->peer, peer_frame));
1157
+ testing_channel_drain_queued_tasks(&fake_connection_2->testing_channel);
1158
+
1159
+ /* The streams on second and third connection should failed to complete */
1160
+ ASSERT_INT_EQUALS(4, s_tester.stream_complete_errors);
1161
+ ASSERT_INT_EQUALS(AWS_ERROR_HTTP_CONNECTION_CLOSED, s_tester.stream_completed_error_code);
1162
+
1163
+ return s_tester_clean_up();
1164
+ }
1165
+
945
1166
  /*******************************************************************************
946
1167
  * Net test, that makes real HTTP/2 connection and requests
947
1168
  ******************************************************************************/
@@ -954,11 +1175,11 @@ TEST_CASE(h2_sm_acquire_stream) {
954
1175
  .alloc = allocator,
955
1176
  };
956
1177
  ASSERT_SUCCESS(s_tester_init(&options));
957
- s_tester.real_connection = true;
958
1178
  int num_to_acquire = 5;
959
1179
  ASSERT_SUCCESS(s_sm_stream_acquiring(num_to_acquire));
960
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(num_to_acquire));
1180
+ ASSERT_SUCCESS(s_wait_on_streams_completed_count(num_to_acquire));
961
1181
  ASSERT_INT_EQUALS(0, s_tester.acquiring_stream_errors);
1182
+ ASSERT_INT_EQUALS(num_to_acquire, s_tester.stream_200_count);
962
1183
 
963
1184
  return s_tester_clean_up();
964
1185
  }
@@ -972,29 +1193,34 @@ TEST_CASE(h2_sm_acquire_stream_multiple_connections) {
972
1193
  .max_concurrent_streams_per_connection = 5,
973
1194
  };
974
1195
  ASSERT_SUCCESS(s_tester_init(&options));
975
- s_tester.real_connection = true;
1196
+
976
1197
  int num_to_acquire = 20;
977
1198
  ASSERT_SUCCESS(s_sm_stream_acquiring(num_to_acquire));
978
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(num_to_acquire));
1199
+ ASSERT_SUCCESS(s_wait_on_streams_completed_count(num_to_acquire));
979
1200
  ASSERT_INT_EQUALS(0, s_tester.acquiring_stream_errors);
1201
+ ASSERT_INT_EQUALS(num_to_acquire, s_tester.stream_200_count);
980
1202
 
981
1203
  return s_tester_clean_up();
982
1204
  }
983
1205
 
984
- /* Test that makes tons of real streams */
985
- TEST_CASE(h2_sm_acquire_stream_stress) {
1206
+ /* Test that makes tons of real streams against real world */
1207
+ TEST_CASE(h2_sm_close_connection_on_server_error) {
986
1208
  (void)ctx;
1209
+ /* server that will return 500 status code all the time. */
1210
+ struct aws_byte_cursor uri_cursor = aws_byte_cursor_from_c_str("https://httpbin.org/status/500");
987
1211
  struct sm_tester_options options = {
988
- .max_connections = 100,
989
- .max_concurrent_streams_per_connection = 100,
1212
+ .max_connections = 1,
1213
+ .max_concurrent_streams_per_connection = 10,
990
1214
  .alloc = allocator,
1215
+ .uri_cursor = &uri_cursor,
1216
+ .close_connection_on_server_error = true,
991
1217
  };
992
1218
  ASSERT_SUCCESS(s_tester_init(&options));
993
- s_tester.real_connection = true;
994
- int num_to_acquire = 100 * 100 * 2;
1219
+ int num_to_acquire = 50;
995
1220
  ASSERT_SUCCESS(s_sm_stream_acquiring(num_to_acquire));
996
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(num_to_acquire));
997
- ASSERT_INT_EQUALS(0, s_tester.acquiring_stream_errors);
1221
+ ASSERT_SUCCESS(s_wait_on_streams_completed_count(num_to_acquire));
1222
+ ASSERT_TRUE((int)s_tester.acquiring_stream_errors == 0);
1223
+ ASSERT_TRUE((int)s_tester.stream_200_count == 0);
998
1224
 
999
1225
  return s_tester_clean_up();
1000
1226
  }
@@ -1029,10 +1255,176 @@ TEST_CASE(h2_sm_closing_before_connection_acquired) {
1029
1255
  /* only acquire one as the connection create happens synced, the stream manager refcount will be released as the
1030
1256
  * first stream acquiring */
1031
1257
  ASSERT_SUCCESS(s_sm_stream_acquiring(1));
1032
- ASSERT_SUCCESS(s_wait_on_streams_reply_count(1));
1258
+ ASSERT_SUCCESS(s_wait_on_streams_acquired_count(1));
1033
1259
 
1034
1260
  /* all acquiring stream failed */
1035
1261
  ASSERT_INT_EQUALS(1, s_tester.acquiring_stream_errors);
1036
1262
  ASSERT_INT_EQUALS(AWS_ERROR_HTTP_STREAM_MANAGER_SHUTTING_DOWN, s_tester.error_code);
1037
1263
  return s_tester_clean_up();
1038
1264
  }
1265
+
1266
+ /* Test our http2 stream manager works with prior knowledge */
1267
+ TEST_CASE(localhost_integ_h2_sm_prior_knowledge) {
1268
+ (void)ctx;
1269
+ struct aws_byte_cursor uri_cursor = aws_byte_cursor_from_c_str("http://localhost:8080");
1270
+ struct sm_tester_options options = {
1271
+ .max_connections = 100,
1272
+ .max_concurrent_streams_per_connection = 100,
1273
+ .alloc = allocator,
1274
+ .uri_cursor = &uri_cursor,
1275
+ .prior_knowledge = true,
1276
+ };
1277
+ ASSERT_SUCCESS(s_tester_init(&options));
1278
+ int num_to_acquire = 2;
1279
+ ASSERT_SUCCESS(s_sm_stream_acquiring(num_to_acquire));
1280
+ ASSERT_SUCCESS(s_wait_on_streams_completed_count(num_to_acquire));
1281
+ ASSERT_TRUE((int)s_tester.acquiring_stream_errors == 0);
1282
+ ASSERT_TRUE((int)s_tester.stream_200_count == num_to_acquire);
1283
+
1284
+ return s_tester_clean_up();
1285
+ }
1286
+
1287
+ /* Test that makes tons of real streams against local host */
1288
+ TEST_CASE(localhost_integ_h2_sm_acquire_stream_stress) {
1289
+ (void)ctx;
1290
+ struct aws_byte_cursor uri_cursor = aws_byte_cursor_from_c_str("https://localhost:8443/echo");
1291
+ struct aws_http_connection_monitoring_options monitor_opt = {
1292
+ .allowable_throughput_failure_interval_seconds = 1,
1293
+ .minimum_throughput_bytes_per_second = 1000,
1294
+ };
1295
+ enum aws_log_level log_level = AWS_LOG_LEVEL_DEBUG;
1296
+ struct sm_tester_options options = {
1297
+ .max_connections = 100,
1298
+ .max_concurrent_streams_per_connection = 100,
1299
+ .connection_ping_period_ms = 100 * AWS_TIMESTAMP_MILLIS,
1300
+ .alloc = allocator,
1301
+ .uri_cursor = &uri_cursor,
1302
+ .monitor_opt = &monitor_opt,
1303
+ .log_level = &log_level,
1304
+ };
1305
+ ASSERT_SUCCESS(s_tester_init(&options));
1306
+ int num_to_acquire = 500 * 100;
1307
+ ASSERT_SUCCESS(s_sm_stream_acquiring(num_to_acquire));
1308
+ ASSERT_SUCCESS(s_wait_on_streams_completed_count(num_to_acquire));
1309
+ ASSERT_TRUE((int)s_tester.acquiring_stream_errors == 0);
1310
+ ASSERT_TRUE((int)s_tester.stream_200_count == num_to_acquire);
1311
+
1312
+ return s_tester_clean_up();
1313
+ }
1314
+
1315
+ static int s_tester_on_put_body(struct aws_http_stream *stream, const struct aws_byte_cursor *data, void *user_data) {
1316
+ (void)user_data;
1317
+ (void)stream;
1318
+ struct aws_string *content_length_header_str = aws_string_new_from_cursor(s_tester.allocator, data);
1319
+ size_t num_received = (uint32_t)atoi((const char *)content_length_header_str->bytes);
1320
+ AWS_FATAL_ASSERT(s_tester.length_sent == num_received);
1321
+ aws_string_destroy(content_length_header_str);
1322
+
1323
+ return AWS_OP_SUCCESS;
1324
+ }
1325
+
1326
+ static int s_sm_stream_acquiring_with_body(int num_streams) {
1327
+ char content_length_sprintf_buffer[128] = "";
1328
+ snprintf(content_length_sprintf_buffer, sizeof(content_length_sprintf_buffer), "%zu", s_tester.length_sent);
1329
+
1330
+ struct aws_http_header request_headers_src[] = {
1331
+ DEFINE_HEADER(":method", "PUT"),
1332
+ {
1333
+ .name = aws_byte_cursor_from_c_str(":scheme"),
1334
+ .value = *aws_uri_scheme(&s_tester.endpoint),
1335
+ },
1336
+ {
1337
+ .name = aws_byte_cursor_from_c_str(":path"),
1338
+ .value = *aws_uri_path(&s_tester.endpoint),
1339
+ },
1340
+ {
1341
+ .name = aws_byte_cursor_from_c_str(":authority"),
1342
+ .value = *aws_uri_host_name(&s_tester.endpoint),
1343
+ },
1344
+ {
1345
+ .name = aws_byte_cursor_from_c_str("content_length"),
1346
+ .value = aws_byte_cursor_from_c_str(content_length_sprintf_buffer),
1347
+ },
1348
+ };
1349
+ for (int i = 0; i < num_streams; ++i) {
1350
+ /* TODO: Test the callback will always be fired asynced, as now the CM cannot ensure the callback happens
1351
+ * asynchronously, we cannot ensure it as well. */
1352
+ struct aws_http_message *request = aws_http2_message_new_request(s_tester.allocator);
1353
+ aws_http_message_add_header_array(request, request_headers_src, AWS_ARRAY_SIZE(request_headers_src));
1354
+ struct aws_input_stream *body_stream =
1355
+ aws_input_stream_tester_upload_new(s_tester.allocator, s_tester.length_sent);
1356
+ aws_http_message_set_body_stream(request, body_stream);
1357
+ aws_input_stream_release(body_stream);
1358
+ struct aws_http_make_request_options request_options = {
1359
+ .self_size = sizeof(request_options),
1360
+ .request = request,
1361
+ .on_response_body = s_tester_on_put_body,
1362
+ .on_complete = s_sm_tester_on_stream_complete,
1363
+ };
1364
+
1365
+ struct aws_http2_stream_manager_acquire_stream_options acquire_stream_option = {
1366
+ .options = &request_options,
1367
+ .callback = s_sm_tester_on_stream_acquired,
1368
+ .user_data = &s_tester,
1369
+ };
1370
+ aws_http2_stream_manager_acquire_stream(s_tester.stream_manager, &acquire_stream_option);
1371
+ aws_http_message_release(request);
1372
+ }
1373
+ return AWS_OP_SUCCESS;
1374
+ }
1375
+
1376
+ /* Test that makes tons of real streams with body against local host */
1377
+ TEST_CASE(localhost_integ_h2_sm_acquire_stream_stress_with_body) {
1378
+ (void)ctx;
1379
+ struct aws_byte_cursor uri_cursor = aws_byte_cursor_from_c_str("https://localhost:8443/upload_test");
1380
+ struct sm_tester_options options = {
1381
+ .max_connections = 100,
1382
+ .max_concurrent_streams_per_connection = 100,
1383
+ .connection_ping_period_ms = 100 * AWS_TIMESTAMP_MILLIS,
1384
+ .alloc = allocator,
1385
+ .uri_cursor = &uri_cursor,
1386
+ };
1387
+ ASSERT_SUCCESS(s_tester_init(&options));
1388
+ s_tester.length_sent = 2000;
1389
+ int num_to_acquire = 500 * 100;
1390
+
1391
+ #ifdef AWS_OS_LINUX
1392
+ /* Using Python hyper h2 server frame work, met a weird upload performance issue on Linux. Our client against nginx
1393
+ * platform has not met the same issue. We assume it's because the server framework implementation. Use lower
1394
+ * number of linux
1395
+ */
1396
+ num_to_acquire = 500;
1397
+ #endif
1398
+
1399
+ ASSERT_SUCCESS(s_sm_stream_acquiring_with_body(num_to_acquire));
1400
+ ASSERT_SUCCESS(s_wait_on_streams_completed_count(num_to_acquire));
1401
+ ASSERT_TRUE((int)s_tester.acquiring_stream_errors == 0);
1402
+ ASSERT_TRUE((int)s_tester.stream_200_count == num_to_acquire);
1403
+
1404
+ return s_tester_clean_up();
1405
+ }
1406
+
1407
+ /* Test that connection monitor works properly with HTTP/2 stream manager */
1408
+ TEST_CASE(localhost_integ_h2_sm_connection_monitor_kill_slow_connection) {
1409
+ (void)ctx;
1410
+ struct aws_byte_cursor uri_cursor = aws_byte_cursor_from_c_str("https://localhost:8443/slowConnTest");
1411
+ struct aws_http_connection_monitoring_options monitor_opt = {
1412
+ .allowable_throughput_failure_interval_seconds = 1,
1413
+ .minimum_throughput_bytes_per_second = 1000,
1414
+ };
1415
+ struct sm_tester_options options = {
1416
+ .max_connections = 100,
1417
+ .max_concurrent_streams_per_connection = 100,
1418
+ .alloc = allocator,
1419
+ .uri_cursor = &uri_cursor,
1420
+ .monitor_opt = &monitor_opt,
1421
+ };
1422
+ ASSERT_SUCCESS(s_tester_init(&options));
1423
+
1424
+ ASSERT_SUCCESS(s_sm_stream_acquiring(1));
1425
+ ASSERT_SUCCESS(s_wait_on_streams_completed_count(1));
1426
+ /* Check the connection closed by connection monitor and the stream should completed with corresponding error */
1427
+ ASSERT_UINT_EQUALS(s_tester.stream_completed_error_code, AWS_ERROR_HTTP_CONNECTION_CLOSED);
1428
+
1429
+ return s_tester_clean_up();
1430
+ }