Skip to content

fix: UTP adapter tests failing on consoles#1372

Merged
andrews-unity merged 6 commits intodevelopfrom
fix/utp-adapter-console-tests
Nov 9, 2021
Merged

fix: UTP adapter tests failing on consoles#1372
andrews-unity merged 6 commits intodevelopfrom
fix/utp-adapter-console-tests

Conversation

@simon-lemay-unity
Copy link
Copy Markdown
Contributor

Note that this is only a tentative fix. But it's a definitive improvement to the adapter tests, so should help with the stability of the tests whether it actually fixes the console tests or not.

The issue was that a lot of tests were waiting on the Connect event on the server side as a proxy of the connection being fully established. But that's not correct. A Connect event on the server does not mean that the UTP ConnectionAccept message has been received and processed by the client. This potentially lead to some timing issues where we'd try to e.g. send data on the client side before the connection is fully established.

This PR tentatively fixes MTT-1551 and MTT-1552.

Changelog

com.unity.netcode.adapter.utp

N/A (Only changes are to tests.)

Testing and Documentation

  • Tests have been updated for increased stability.
  • No documentation changes or additions were necessary.

A lot of tests were waiting on the Connect event on the server side as a
proxy of the connection being fully established. But that's not correct.
A Connect event on the server does not mean that the UTP Connection
Accept message has been received and processed by the client.

This lead to some timing issues where we'd try to e.g. send data on the
client side before the connection is fully established.
}

// Check that all clients received the correct event.
Assert.True(m_ClientsEvents.All(evs => evs[0].Type == NetworkEvent.Connect));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Just a tip, you can use Assert.That and specify constraints. This will ensure that you get a relevant error message when the test fails, rather than just "Expected true, got false".

https://docs.nunit.org/articles/nunit/writing-tests/assertions/assertion-models/constraint.html

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't know about that. Thanks for pointing it out!

// Check that all clients got a Disconnect event.
Assert.True(m_ClientsEvents.All(evs => evs.Count == 2));
Assert.True(m_ClientsEvents.All(evs => evs[1].Type == NetworkEvent.Disconnect));
Assert.That(m_ClientsEvents.All(evs => evs.Count == 2));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, I should have been more precise with that comment. If you straight up replace True with That, it will behave exactly the same.

To get relevant error messages, you need to use it in the following way:
Assert.That(m_ClientEvents, Has.All.EqualTo(your constraint here);

That way, it will be able to mark which specific collection items are not matching your constraint, and should also display the actual value vs the expected value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Has.All.EqualTo, or any other Has.All method that you prefer

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah right, I see. In that case I'm not sure it's really worth it in that particular case. While the first check (events.All(evs => evs.Count == 2)) can be expressed in that style, it's immediately followed by another similar check that I'm not sure can be written using such constraints. I prefer the extra consistency here of having all similar assertions using a similar style.

@andrews-unity andrews-unity enabled auto-merge (squash) November 8, 2021 23:50
@andrews-unity andrews-unity merged commit 942a1cd into develop Nov 9, 2021
@andrews-unity andrews-unity deleted the fix/utp-adapter-console-tests branch November 9, 2021 00:16
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