Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add general_merge tests and a test data generator module #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jurraca
Copy link
Contributor

@jurraca jurraca commented Nov 4, 2024

Initial approach to tests, starting with the merge process. The generate_data module has functions to create IP networks and addrs and create AS files as we would get from RPKI or RIR.

the generate_data module has functions to create IP networks and addrs and
create AS files as we would get from RPKI or RIR.
Copy link
Collaborator

@fjahr fjahr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few comments. I think adding such a test with generated data is always interesting but it's not where I would have started :) So something I would still like to have is very basic test vectors with static data, primarily because these are very easy to reason about and after we have set it up once it becomes trivial to add all kinds of edge cases we will stumble over. We could have them in CSV file like this one from BIP340: https://github.com/bitcoin/bips/blob/master/bip-0340/test-vectors.csv But let's add this here first since it's already in pretty good shape.

from random import randint


def generate_ip(ip_type="v4", subnet_size="16"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The generate_data.py file could be moved into a util or shared folder. But can be done as a follow-up when more tests are added.

def generate_asns(count):
asns = []
while count > 0:
asn = randint(1, 100000)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use our own max asn value for the end of the range here, i.e. max_encode. Can also use the default for now since we are pretty married to it currently with the assumptions in the core code: 33521664.

return network


def generate_ip_networks(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, the ip networks (and to some degree asns too) generate methods don't have guarantees that the generated result is a set without overlap, right? While the chance seems low, there could be overlapping results which means the test outcomes are not deterministic. I think it would be neat if these functions could always generate a set. This would then allow us to make stricter testing. I.e. we could be sure that merging two sets of 10 with overlap of 1 have a result of 19 entries.

"""
extra_new = []
for extra in extra_items:
included = 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could use boolean here

Comment on lines +10 to +11
end_ip = int(ipaddress.IPv4Address("255.255.255.255"))
subnet_mask = end_ip << (32 - subnet_size)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is cleaner:

subnet_mask = ipaddress.IPv4Network(f"0.0.0.0/{subnet_size}", strict=False).netmask

Comment on lines +10 to +11

TEST_FILE_PATHS = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the files are not cleaned up after each test run yet, right? should do that to avoid test polution.

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.

2 participants