def test_user_agent_generation_for_past(): mytime = MyTime(epoch=1520020741) stage = 'local' step = 1234 base_url = 'http://shadowreader.example.com' app = App( name='my-test-app', replay_start_time=mytime, loop_duration=60, base_url=base_url, rate=100, baseline=0 ) headers = Headers( shadowreader_type='past', stage=stage, app=app, step=step).headers user_agent = headers['x-request-id'] print(headers) assert user_agent == f'sr_local_past_{base_url}_my-test-app_03-02-2018-19-59_60m_20'
def test_user_agent_generation_for_past_w_identifier(): mytime = MyTime(epoch=1520020741) stage = "local" step = 1234 base_url = "http://shadowreader.example.com" app = App( name="my-test-app", replay_start_time=mytime, loop_duration=60, base_url=base_url, identifier="qa", rate=100, baseline=0, ) headers = Headers(shadowreader_type="past", stage=stage, app=app, step=step).headers user_agent = headers["x-request-id"] print(headers) assert user_agent == "sr_local_past_qa_my-test-app_03-02-2018-19-59_60m_20"
def lambda_handler(event, context): try: """ First gather the necessary test params, init App objects, filters and compute the current step After, then send (app, env_to_test, cur_timestamp, rate) to consumer-master consumer-master will then fetch data set (set of URLs) from S3, then pass it to multiple consumer-workers each consumer-worker will then send out requests to test environment (each worker handles up to 100 requests) """ mytime, lambda_name, env_vars = lambda_init.init_lambda(context) stage = env_vars["stage"] consumer_master_past_lambda = env_vars["consumer_master_past_name"] apps, test_params = init_apps_from_test_params(event) filters = init_filters() step = generate_step_from_mytime(mytime) print("step:", step) for app in apps: advance_app_timestamp(app, step) consumer_event = {} # Invoke the consumer-master lambda for each app in apps for app in apps: headers = Headers( shadowreader_type="past", stage=stage, app=app, step=step ).headers consumer_event = { "app": app.name, "identifier": app.identifier, "base_url": app.base_url, "cur_timestamp": app.cur_timestamp, "rate": app.rate, "baseline": app.baseline, "parent_lambda": lambda_name, "child_lambda": consumer_master_past_lambda, "headers": headers, "filters": filters, } invoke_func(consumer_event, func=consumer_master_past_lambda) if apps and consumer_event: print_to_logs(consumer_event, apps) # Collect metrics and put metrics into CW metrics = [] for app in apps: # This is the timestamp (in epoch time) that is being replayed # by the load test. metric = { "name": "replayed_timestamp", "stage": stage, "lambda_name": lambda_name, "app": app.name, "identifier": app.identifier, "mytime": mytime, "val": app.cur_timestamp, } metrics.append(metric) if sr_plugins.exists("metrics"): metric_emitter = sr_plugins.load("metrics") for metric in metrics: metric_emitter.main(metric) cur_params = {"apps": apps, "filters": filters, "test_params": test_params} if sr_plugins.exists("test_params_emitter"): params_emitter = sr_plugins.load("test_params_emitter") params_emitter.main( cur_params, lambda_name, mytime, stage, env_vars, sr_config, sr_plugins._sr_plugins, ) except Exception as e: trace = traceback.format_exc() raise Exception(trace) return json.dumps(cur_params, default=str), json.dumps(consumer_event, default=str)