1#!/usr/bin/env python3 2# Copyright 2022 The Pigweed Authors 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); you may not 5# use this file except in compliance with the License. You may obtain a copy of 6# the License at 7# 8# https://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13# License for the specific language governing permissions and limitations under 14# the License. 15"""Cross-language pw_transfer write tests that take tens of minutes to run. 16 17Usage: 18 19 bazel run pw_transfer/integration_test:cross_language_large_write_test 20 21Command-line arguments must be provided after a double-dash: 22 23 bazel run pw_transfer/integration_test:cross_language_large_write_test -- \ 24 --server-port 3304 25 26Which tests to run can be specified as command-line arguments: 27 28 bazel run pw_transfer/integration_test:cross_language_large_write_test -- \ 29 LargeWriteTransferIntegrationTest.test_1mb_write_dropped_data_1_java 30 31""" 32 33from parameterized import parameterized 34import random 35 36from google.protobuf import text_format 37 38import test_fixture 39from test_fixture import ( 40 TransferConfig, 41 TransferIntegrationTest, 42 TransferIntegrationTestHarness, 43) 44from pigweed.pw_transfer.integration_test import config_pb2 45 46_ALL_LANGUAGES = ("cpp", "java", "python") 47 48 49class LargeWriteTransferIntegrationTest(TransferIntegrationTest): 50 # Each set of transfer tests uses a different client/server port pair to 51 # allow tests to be run in parallel. 52 HARNESS_CONFIG = TransferIntegrationTestHarness.Config( 53 server_port=3310, client_port=3311 54 ) 55 56 @parameterized.expand(_ALL_LANGUAGES) 57 def test_1mb_write_dropped_data(self, client_type): 58 server_config = config_pb2.ServerConfig( 59 chunk_size_bytes=216, 60 pending_bytes=32 * 1024, 61 chunk_timeout_seconds=5, 62 transfer_service_retries=4, 63 extend_window_divisor=32, 64 ) 65 client_config = config_pb2.ClientConfig( 66 max_retries=5, 67 initial_chunk_timeout_ms=10000, 68 chunk_timeout_ms=4000, 69 ) 70 proxy_config = text_format.Parse( 71 """ 72 client_filter_stack: [ 73 { rate_limiter: {rate: 50000} }, 74 { hdlc_packetizer: {} }, 75 { data_dropper: {rate: 0.01, seed: 1649963713563718435} } 76 ] 77 78 server_filter_stack: [ 79 { rate_limiter: {rate: 50000} }, 80 { hdlc_packetizer: {} }, 81 { data_dropper: {rate: 0.01, seed: 1649963713563718436} } 82 ]""", 83 config_pb2.ProxyConfig(), 84 ) 85 86 payload = random.Random(1649963713563718437).randbytes(1 * 1024 * 1024) 87 resource_id = 12 88 config = TransferConfig(server_config, client_config, proxy_config) 89 self.do_single_write(client_type, config, resource_id, payload) 90 91 @parameterized.expand(_ALL_LANGUAGES) 92 def test_1mb_write_reordered_data(self, client_type): 93 server_config = config_pb2.ServerConfig( 94 chunk_size_bytes=216, 95 pending_bytes=32 * 1024, 96 chunk_timeout_seconds=5, 97 transfer_service_retries=4, 98 extend_window_divisor=32, 99 ) 100 client_config = config_pb2.ClientConfig( 101 max_retries=5, 102 initial_chunk_timeout_ms=10000, 103 chunk_timeout_ms=4000, 104 ) 105 proxy_config = text_format.Parse( 106 """ 107 client_filter_stack: [ 108 { rate_limiter: {rate: 50000} }, 109 { hdlc_packetizer: {} }, 110 { data_transposer: {rate: 0.005, timeout: 0.5, seed: 1649963713563718435} } 111 ] 112 113 server_filter_stack: [ 114 { rate_limiter: {rate: 50000} }, 115 { hdlc_packetizer: {} }, 116 { data_transposer: {rate: 0.005, timeout: 0.5, seed: 1649963713563718435} } 117 ]""", 118 config_pb2.ProxyConfig(), 119 ) 120 121 payload = random.Random(1649963713563718437).randbytes(1 * 1024 * 1024) 122 resource_id = 12 123 config = TransferConfig(server_config, client_config, proxy_config) 124 self.do_single_write(client_type, config, resource_id, payload) 125 126 127if __name__ == '__main__': 128 test_fixture.run_tests_for(LargeWriteTransferIntegrationTest) 129