Skip to content

Print JSON format and allow disabling tests skipping#10

Open
akarasik wants to merge 10 commits into12932:masterfrom
akarasik:scripting_enhancments
Open

Print JSON format and allow disabling tests skipping#10
akarasik wants to merge 10 commits into12932:masterfrom
akarasik:scripting_enhancments

Conversation

@akarasik
Copy link
Copy Markdown
Contributor

In order to get a persistent output that can be used programmaticaly
this commit adds 2 new abilities:

  1. Print output in JSON format to be able to parse it
  2. Allow disabling the tests skipping. This will allow running all of
    the tests regardless of the patience attribute, which will result in
    a consistent output each time

Here are examples after this change:

~ ❯ cf-speedtest
Your IP:	1.2.3.4 (IL)
Server loc:	TLV (TLV) - (IL)

Latency:         9.58 ms
Jitter:          1.79 ms
Running speed tests...

Current speeds:          Down: 111.87 Mbit/sec	Up: 0.00 Mbit/sec
Current speeds:          Down: 111.87 Mbit/sec	Up: 36.36 Mbit/sec
Current speeds:          Down: 513.31 Mbit/sec	Up: 36.36 Mbit/sec
Current speeds:          Down: 513.31 Mbit/sec	Up: 36.36 Mbit/sec
Current speeds:          Down: 463.11 Mbit/sec	Up: 36.36 Mbit/sec
Current speeds:          Down: 463.11 Mbit/sec	Up: 32.00 Mbit/sec
Current speeds:          Down: 463.11 Mbit/sec	Up: 32.00 Mbit/sec
Current speeds:          Down: 456.29 Mbit/sec	Up: 32.00 Mbit/sec
Current speeds:          Down: 456.29 Mbit/sec	Up: 32.00 Mbit/sec
90th percentile results:   Down: 456.29 Mbit/sec	Up: 32.00 Mbit/sec
~ ❯ cf-speedtest --json
{
    "location": {
        "my_ip_addr": "1.2.3.4",
        "country": "IL",
        "server_city": "TLV",
        "colocation": "TLV",
        "server_country": "IL"
    },
    "latency": "7.66",
    "jitter": "25.28",
    "tests": {
        "100000": {
            "download": "124.06",
            "upload": "32.00"
        },
        "1000000": {
            "download": "124.06",
            "upload": "32.00"
        },
        "10000000": {
            "download": "110.53",
            "upload": "26.23"
        },
        "25000000": {
            "download": "110.53"
        }
    },
    "90_percentile": {
        "download": "110.53",
        "upload": "26.23"
    }
}
~ ❯ cf-speedtest --disableskipping
Your IP:	1.2.3.4 (IL)
Server loc:	TLV (TLV) - (IL)

Latency:         8.63 ms
Jitter:          7.67 ms
Running speed tests...

Current speeds:          Down: 108.17 Mbit/sec	Up: 0.00 Mbit/sec
Current speeds:          Down: 108.17 Mbit/sec	Up: 26.67 Mbit/sec
Current speeds:          Down: 381.72 Mbit/sec	Up: 26.67 Mbit/sec
Current speeds:          Down: 381.72 Mbit/sec	Up: 26.67 Mbit/sec
Current speeds:          Down: 373.20 Mbit/sec	Up: 26.67 Mbit/sec
Current speeds:          Down: 373.20 Mbit/sec	Up: 25.00 Mbit/sec
Current speeds:          Down: 373.20 Mbit/sec	Up: 25.00 Mbit/sec
Current speeds:          Down: 373.20 Mbit/sec	Up: 25.00 Mbit/sec
Current speeds:          Down: 348.27 Mbit/sec	Up: 25.00 Mbit/sec
Current speeds:          Down: 348.27 Mbit/sec	Up: 24.24 Mbit/sec
Current speeds:          Down: 348.27 Mbit/sec	Up: 24.24 Mbit/sec
Current speeds:          Down: 348.27 Mbit/sec	Up: 24.24 Mbit/sec
90th percentile results:   Down: 348.27 Mbit/sec	Up: 24.24 Mbit/sec
~ ❯ cf-speedtest --json --disableskipping
{
    "location": {
        "my_ip_addr": "1.2.3.4",
        "country": "IL",
        "server_city": "TLV",
        "colocation": "TLV",
        "server_country": "IL"
    },
    "latency": "9.65",
    "jitter": "5.50",
    "tests": {
        "100000": {
            "download": "105.21",
            "upload": "27.59"
        },
        "1000000": {
            "download": "435.88",
            "upload": "27.59"
        },
        "10000000": {
            "download": "426.05",
            "upload": "22.86"
        },
        "25000000": {
            "download": "426.05",
            "upload": "22.86"
        },
        "100000000": {
            "download": "424.71",
            "upload": "5.81"
        },
        "250000000": {
            "download": "424.71",
            "upload": "5.81"
        }
    },
    "90_percentile": {
        "download": "424.71",
        "upload": "5.81"
    }
}

akarasik and others added 9 commits June 26, 2024 12:09
Recently the Server-Timing header value changed to:
cfRequestDuration;dur=74.000120, cfL4;desc="?proto=TCP,{rest_of_description_here}"

Therefore the split(';') will result in the following string:
dur=74.000120, cfL4

When executing the next float(part.split('=')[1]) it will return
"74.000120, cfL4" which cannot be transformed to a float.

This commit will try to extract it that way (in case the headers will
change back), and if not - it will extract assuming the new format
BUGFIX: Update the duration extraction from the Server-Timing header
- Remove all_test.py and distribute its tests across new test files
- Add integration_test.py for end-to-end testing
- Implement unit tests for network operations, CLI options, and utility functions
- Enhance main function testing with various arguments
- Add tests for proxy functionality and CSV output
- Improve test coverage for edge cases in percentile calculation
- Set up test fixtures for mocking time and requests session
- Update requirements-dev.txt to include pytest

This commit significantly improves the test suite by breaking down monolithic
tests into more focused, modular test files. It adds both unit and integration
tests, covering various aspects of the cf_speedtest package including network
operations, command-line options, utility functions, and main program flow.
The new tests also cover edge cases and different configurations, enhancing
the overall robustness of the test suite.
Refactor tests and improve test coverage
In order to get a persistent output that can be used programmaticaly
this commit adds 2 new abilities:
1. Print output in JSON format to be able to parse it
2. Allow disabling the tests skipping. This will allow running all of
   the tests regardless of the patience attribute, which will result in
   a consistent output each time
@akarasik
Copy link
Copy Markdown
Contributor Author

tox is failing, working on resolving this

@akarasik
Copy link
Copy Markdown
Contributor Author

Fixed the tests 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants