Skip to content

Conversation

@codemob-dev
Copy link
Contributor

Required for #2180

@codemob-dev codemob-dev moved this to High Priority in PRs to review Nov 11, 2025
@codemob-dev codemob-dev mentioned this pull request Nov 11, 2025
Copy link
Member

@IntegratedQuantum IntegratedQuantum left a comment

Choose a reason for hiding this comment

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

Please also replace existing IP+port parsing code (→Connection, STUN).

@IntegratedQuantum IntegratedQuantum moved this from High Priority to In review in PRs to review Nov 12, 2025
src/network.zig Outdated
}

fn resolve(allocator: NeverFailingAllocator, addr: []const u8, port: u16) !IpAddress {
const list = try std.net.getAddressList(allocator.allocator, addr, port);
Copy link
Member

Choose a reason for hiding this comment

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

Use the stackAllocator for local allocations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't work in tests

Copy link
Member

Choose a reason for hiding this comment

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

What is the error? It seems odd that it wouldn't work. Can't you test network code in Zig?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the error? It seems odd that it wouldn't work. Can't you test network code in Zig?

The stack allocator isn't available during tests.

Copy link
Member

Choose a reason for hiding this comment

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

Well, then please fix #1286 in a separate PR first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, then please fix #1286 in a separate PR first.

#2320

}
};

test "Parse address" {
Copy link
Member

Choose a reason for hiding this comment

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

Please also add a test for resolve

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would I do that? Domain names can change IPs, should I just test to make sure that the parsing functions match the resolve functions for IPs?

Copy link
Member

Choose a reason for hiding this comment

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

Not all of them. localhost is one such example

Copy link
Contributor Author

@codemob-dev codemob-dev Nov 18, 2025

Choose a reason for hiding this comment

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

localhost is one such example

Depending on the computer's config it might resolve differently.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I could edit it in /etc/hosts if I wanted to, but is that something we should worry about?

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 we should include some of those undead services, like www.google.com

If you are not connected to the internet, then any service apart from localhost is dead.

Yeah it would be great to test if Cubyz works w/o internet connection right?

But most of the time we care about name resolution in the context of working with an internet connection, so I am proposing positive test cases first.

Copy link
Member

Choose a reason for hiding this comment

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

You should be able to run all test cases without an internet connection.
That is a hard requirement for me, since it makes development more accessible (e.g. I can test code when I'm on the train, without having to figure out how to setup their free wifi).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Test cases should just mark themselves as skipped if they can't be runner in current environment. With your requirement you will never be able to test anything platform specific, as you can't be running both windows and Linux as host os at once. Test cases may not be ran every time, not all at once, but they have to be checked at least in CI. It's normal, it's everywhere, let's not reinvent the wheel.

Copy link
Member

Choose a reason for hiding this comment

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

That would be good, yes. But I would still rather avoid adding another dependency on a random service. We haven't used google for anything, so why add a dependency on it for some stupid test case?
The only online dependency we have is github at the moment, but to be honest I do not think we should increase or dependency on github for a stupid test case.
Furthermore the thing we are testing is probably something that should have been tested in the Zig repo, and not in our code. What we care about is that the hostname is forwarded to the right function, not that the function produces the right results for some arbitrary hostname. For that "localhost" is enough.

Copy link
Member

@IntegratedQuantum IntegratedQuantum Nov 20, 2025

Choose a reason for hiding this comment

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

Plus any online connection increases the chance sporadic CI failures.
We have already seen this for the existing online dependencies (see https://discord.com/channels/443805812390100992/485498631156138005/1433920016318988398)

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

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants