fn validate_one_taskset(
    swanling_metrics: &SwanlingMetrics,
    mock_endpoints: &[MockRef],
    configuration: &SwanlingConfiguration,
    test_type: TestType,
) {
    // Confirm that we loaded the mock endpoints.
    assert!(mock_endpoints[INDEX_KEY].hits() > 0);
    assert!(mock_endpoints[ABOUT_KEY].hits() > 0);

    // Confirm that we loaded the index roughly three times as much as the about page.
    let one_third_index = mock_endpoints[INDEX_KEY].hits() / 3;
    let difference = mock_endpoints[ABOUT_KEY].hits() as i32 - one_third_index as i32;
    assert!(difference >= -2 && difference <= 2);

    // Get index and about out of swanling metrics.
    let index_metrics = swanling_metrics
        .requests
        .get(&format!("GET {}", INDEX_PATH))
        .unwrap();
    let about_metrics = swanling_metrics
        .requests
        .get(&format!("GET {}", ABOUT_PATH))
        .unwrap();

    // Confirm that the path and method are correct in the statistics.
    assert!(index_metrics.path == INDEX_PATH);
    assert!(index_metrics.method == SwanlingMethod::Get);
    assert!(about_metrics.path == ABOUT_PATH);
    assert!(about_metrics.method == SwanlingMethod::Get);

    let status_code: u16 = 200;
    match test_type {
        TestType::ResetMetrics => {
            // Statistics were reset after all users were started, so Swanling should report
            // fewer page loads than the server actually saw.
            println!(
                "raw_data.counter: {}, mock_endpoint_called: {}",
                index_metrics.raw_data.counter,
                mock_endpoints[INDEX_KEY].hits()
            );

            assert!(index_metrics.raw_data.counter < mock_endpoints[INDEX_KEY].hits());
            assert!(
                index_metrics.status_code_counts[&status_code] < mock_endpoints[INDEX_KEY].hits()
            );
            assert!(index_metrics.success_count < mock_endpoints[INDEX_KEY].hits());
            assert!(about_metrics.raw_data.counter < mock_endpoints[ABOUT_KEY].hits());
            assert!(
                about_metrics.status_code_counts[&status_code] < mock_endpoints[ABOUT_KEY].hits()
            );
            assert!(about_metrics.success_count < mock_endpoints[ABOUT_KEY].hits());
        }
        TestType::NoResetMetrics => {
            // Statistics were not reset, so Swanling should report the same number of page
            // loads as the server actually saw.
            mock_endpoints[INDEX_KEY].assert_hits(index_metrics.raw_data.counter);
            mock_endpoints[INDEX_KEY].assert_hits(index_metrics.status_code_counts[&status_code]);
            mock_endpoints[INDEX_KEY].assert_hits(index_metrics.success_count);
            mock_endpoints[ABOUT_KEY].assert_hits(about_metrics.raw_data.counter);
            mock_endpoints[ABOUT_KEY].assert_hits(about_metrics.status_code_counts[&status_code]);
            mock_endpoints[ABOUT_KEY].assert_hits(about_metrics.success_count);
        }
    }

    // There should not have been any failures during this test.
    assert!(index_metrics.fail_count == 0);
    assert!(about_metrics.fail_count == 0);

    // Verify that Swanling started the correct number of users.
    assert!(swanling_metrics.users == configuration.users.unwrap());
}
// Helper to confirm all variations generate appropriate results.
Helper to confirm all variations generate appropriate results.
Helper to confirm all variations generate appropriate results .
fn validate_one_taskset(
    swanling_metrics: &SwanlingMetrics,
    mock_endpoints: &[MockRef],
    configuration: &SwanlingConfiguration,
    test_type: TestType,
) {
    // Confirm that we loaded the mock endpoints.
    assert!(mock_endpoints[INDEX_KEY].hits() > 0);
    assert!(mock_endpoints[ABOUT_KEY].hits() > 0);
    // Confirm that we loaded the index roughly three times as much as the about page.
    let one_third_index = mock_endpoints[INDEX_KEY].hits() / 3;
    let difference = mock_endpoints[ABOUT_KEY].hits() as i32 - one_third_index as i32;
    assert!(difference >= -2 && difference <= 2);
    // Get index and about out of swanling metrics.
    let index_metrics = swanling_metrics
        .requests
        .get(&format!("GET {}", INDEX_PATH))
        .unwrap();
    let about_metrics = swanling_metrics
        .requests
        .get(&format!("GET {}", ABOUT_PATH))
        .unwrap();
    // Confirm that the path and method are correct in the statistics.
    assert!(index_metrics.path == INDEX_PATH);
    assert!(index_metrics.method == SwanlingMethod::Get);
    assert!(about_metrics.path == ABOUT_PATH);
    assert!(about_metrics.method == SwanlingMethod::Get);
    let status_code: u16 = 200;
    match test_type {
        TestType::ResetMetrics => {
            // Statistics were reset after all users were started, so Swanling should report
            // fewer page loads than the server actually saw.
            println!(
                "raw_data.counter: {}, mock_endpoint_called: {}",
                index_metrics.raw_data.counter,
                mock_endpoints[INDEX_KEY].hits()
            );
            assert!(index_metrics.raw_data.counter < mock_endpoints[INDEX_KEY].hits());
            assert!(
                index_metrics.status_code_counts[&status_code] < mock_endpoints[INDEX_KEY].hits()
            );
            assert!(index_metrics.success_count < mock_endpoints[INDEX_KEY].hits());
            assert!(about_metrics.raw_data.counter < mock_endpoints[ABOUT_KEY].hits());
            assert!(
                about_metrics.status_code_counts[&status_code] < mock_endpoints[ABOUT_KEY].hits()
            );
            assert!(about_metrics.success_count < mock_endpoints[ABOUT_KEY].hits());
        }
        TestType::NoResetMetrics => {
            // Statistics were not reset, so Swanling should report the same number of page
            // loads as the server actually saw.
            mock_endpoints[INDEX_KEY].assert_hits(index_metrics.raw_data.counter);
            mock_endpoints[INDEX_KEY].assert_hits(index_metrics.status_code_counts[&status_code]);
            mock_endpoints[INDEX_KEY].assert_hits(index_metrics.success_count);
            mock_endpoints[ABOUT_KEY].assert_hits(about_metrics.raw_data.counter);
            mock_endpoints[ABOUT_KEY].assert_hits(about_metrics.status_code_counts[&status_code]);
            mock_endpoints[ABOUT_KEY].assert_hits(about_metrics.success_count);
        }
    }
    // There should not have been any failures during this test.
    assert!(index_metrics.fail_count == 0);
    assert!(about_metrics.fail_count == 0);
    // Verify that Swanling started the correct number of users.
    assert!(swanling_metrics.users == configuration.users.unwrap());
}
fn validate_one_taskset ( swanling_metrics : & SwanlingMetrics , mock_endpoints : & [ MockRef ] , configuration : & SwanlingConfiguration , test_type : TestType , ) { // Confirm that we loaded the mock endpoints. assert ! ( mock_endpoints [ INDEX_KEY ] hits ( ) 0 ) ; assert ! ( mock_endpoints [ ABOUT_KEY ] hits ( ) 0 ) ; // Confirm that we loaded the index roughly three times as much as the about page. let one_third_index = mock_endpoints [ INDEX_KEY ] . hits ( ) / 3 ; let difference = mock_endpoints [ ABOUT_KEY ] . hits ( ) as i32 - one_third_index as i32 ; assert ! ( difference 2 difference 2 ) ; // Get index and about out of swanling metrics. let index_metrics = swanling_metrics . requests . get ( & format ! ( " " INDEX_PATH ) ) . unwrap ( ) ; let about_metrics = swanling_metrics . requests . get ( & format ! ( " " ABOUT_PATH ) ) . unwrap ( ) ; // Confirm that the path and method are correct in the statistics. assert ! ( index_metrics path INDEX_PATH ) ; assert ! ( index_metrics method SwanlingMethod Get ) ; assert ! ( about_metrics path ABOUT_PATH ) ; assert ! ( about_metrics method SwanlingMethod Get ) ; let status_code : u16 = 200 ; match test_type { TestType :: ResetMetrics => { // Statistics were reset after all users were started, so Swanling should report // fewer page loads than the server actually saw. println ! ( " " index_metrics raw_data counter mock_endpoints [ INDEX_KEY ] hits ( ) ) ; assert ! ( index_metrics raw_data counter mock_endpoints [ INDEX_KEY ] hits ( ) ) ; assert ! ( index_metrics status_code_counts [ status_code ] mock_endpoints [ INDEX_KEY ] hits ( ) ) ; assert ! ( index_metrics success_count mock_endpoints [ INDEX_KEY ] hits ( ) ) ; assert ! ( about_metrics raw_data counter mock_endpoints [ ABOUT_KEY ] hits ( ) ) ; assert ! ( about_metrics status_code_counts [ status_code ] mock_endpoints [ ABOUT_KEY ] hits ( ) ) ; assert ! ( about_metrics success_count mock_endpoints [ ABOUT_KEY ] hits ( ) ) ; } TestType :: NoResetMetrics => { // Statistics were not reset, so Swanling should report the same number of page // loads as the server actually saw. mock_endpoints [ INDEX_KEY ] . assert_hits ( index_metrics . raw_data . counter ) ; mock_endpoints [ INDEX_KEY ] . assert_hits ( index_metrics . status_code_counts [ & status_code ] ) ; mock_endpoints [ INDEX_KEY ] . assert_hits ( index_metrics . success_count ) ; mock_endpoints [ ABOUT_KEY ] . assert_hits ( about_metrics . raw_data . counter ) ; mock_endpoints [ ABOUT_KEY ] . assert_hits ( about_metrics . status_code_counts [ & status_code ] ) ; mock_endpoints [ ABOUT_KEY ] . assert_hits ( about_metrics . success_count ) ; } } // There should not have been any failures during this test. assert ! ( index_metrics fail_count 0 ) ; assert ! ( about_metrics fail_count 0 ) ; // Verify that Swanling started the correct number of users. assert ! ( swanling_metrics users configuration users unwrap ( ) ) ; }
Helper to confirm all variations generate appropriate results.
Helper to confirm all variations generate appropriate results .
swanling_metrics
&SwanlingMetrics
mock_endpoints
&[MockRef]
configuration
&SwanlingConfiguration
test_type
TestType