Beispiel #1
0
def test_consumer_slave_lambda_handler():
    load = loader_main(load=myload,
                       rate=1,
                       baseline=0,
                       base_url='https://postman-echo.com',
                       filters={})

    from pprint import pprint
    pprint(load)

    event = {
        'delay_per_req': 0.01,
        'delay_random': True,
        'load': load,
        'rate': 1,
        'app': 'pytest',
        'identifier': 'qa',
        'parent_lambda': 'pytest',
        'child_lambda': 'sr-dev-consumer-slave',
        'headers': {
            'User-Agent': 'sr-dev-pytest'
        },
    }

    event = json.dumps(event)
    event = zipper.compress(data=event)
    event = {'payload': event}
    num_reqs_val = consumer_slave.lambda_handler(event, '')
    assert num_reqs_val == 1
Beispiel #2
0
def test_consumer_slave_lambda_handler():
    load = loader_main(
        load=myload, rate=1, baseline=0, base_url="https://postman-echo.com", filters={}
    )

    from pprint import pprint

    pprint(load)

    event = {
        "delay_per_req": 0.01,
        "delay_random": True,
        "load": load,
        "rate": 1,
        "app": "pytest",
        "identifier": "qa",
        "parent_lambda": "pytest",
        "child_lambda": "sr-dev-consumer-slave",
        "headers": {"User-Agent": "sr-dev-pytest"},
    }

    event = json.dumps(event)
    event = zipper.compress(data=event)
    event = {"payload": event}
    num_reqs_val = consumer_slave.lambda_handler(event, "")
    assert num_reqs_val == 1
Beispiel #3
0
def lambda_handler(event, context):
    """
    Example event passed from orchestrator-past Lambda
        consumer_event = {
        'app': app.name,
        'env_to_test': app.env_to_test,
        'cur_timestamp': app.cur_timestamp,
        'rate': app.rate,
        'parent_lambda': lambda_name,
        'child_lambda': consumer_master_past_lambda_name,
        'headers': headers,
    }
    """
    try:
        mytime, lambda_name, env_vars = init_lambda(context)
        stage = env_vars["stage"]

        app, identifier, cur_timestamp, rate, headers, filters, base_url, baseline = init_consumer_master(
            event)

        parsed_data_bucket = env_vars["parsed_data_bucket"]

        replay_mode = sr_plugins.load("replay_mode")
        kwargs = {
            "lambda_start_time": mytime,
            "app_name": app,
            "app_cur_timestamp": cur_timestamp,
        }
        s3_parsed_data_key = replay_mode.main(**kwargs)

        print(f"s3://{parsed_data_bucket}/{s3_parsed_data_key}")

        # Fetch from S3 the URLs to send for this load test
        load = s3.fetch_from_s3(key=s3_parsed_data_key,
                                bucket=parsed_data_bucket)

        num_reqs_pre_filter = len(load)

        # Transform the URLs based on the test params and filters
        load = loader_main(load=load,
                           rate=rate,
                           baseline=baseline,
                           base_url=base_url,
                           filters=filters)

        num_reqs_after_filter = len(load)

        # Init base metric dict
        base_metric = {
            "stage": stage,
            "lambda_name": lambda_name,
            "app": app,
            "identifier": identifier,
            "mytime": mytime,
        }

        emit_metrics(base_metric, num_reqs_pre_filter, num_reqs_after_filter)

        invoke_worker_lambdas(
            load=load,
            app=app,
            identifier=identifier,
            parent_lambda=lambda_name,
            headers=headers,
        )

    except Exception as e:
        trace = traceback.format_exc()
        raise Exception(trace)

    return app