Skip to content

refactor: InternalMessageHandler is no longer static#706

Merged
TwoTenPvP merged 11 commits intodevelopfrom
singleton-removal-message-handler
Apr 16, 2021
Merged

refactor: InternalMessageHandler is no longer static#706
TwoTenPvP merged 11 commits intodevelopfrom
singleton-removal-message-handler

Conversation

@TwoTenPvP
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Member

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

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

Other than instantiating the InternalMessageHandler within the Init method of the NetworkManager, it all looks good to me.

Copy link
Copy Markdown
Member

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

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

LGTM!

@mattwalsh-unity
Copy link
Copy Markdown
Contributor

Beyond keeping NetworkingManager slimmer, is there a purpose for having InternalMessageHandler as its own class? Perhaps later @TwoTenPvP you were thinking one could swap in another message handler? Because it's a little odd...we have a sizable class with no state that's dependent heavily on another class that does have state...hence it's full of NetworkManager.singleton references. If this code was just folded into NetworkManager then those .singleton references would just vanish and I think it would be overall much easier to reason about.

Copy link
Copy Markdown
Contributor

@mattwalsh-unity mattwalsh-unity left a comment

Choose a reason for hiding this comment

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

Seems to me this would be cleaner if we folded this into NetworkManager per my comment in the conversation tab.

@TwoTenPvP TwoTenPvP requested a review from JesseOlmer April 8, 2021 21:08

// Should cause log (server only)
LogAssert.Expect(LogType.Log, nameof(MessageHandlerReceivedMessageServerClient) + " " + nameof(DummyMessageHandler.HandleConnectionRequest));
using (var messageStream = MessagePacker.WrapMessage(NetworkConstants.CONNECTION_REQUEST, inputBuffer))
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.

I'd encourage each one of these to be a separate test case. Throwing them all into one test means that if one fails, none of the following ones even get tested. Also makes it harder to maintain the test coverage.


// Should cause log (server only)
LogAssert.Expect(LogType.Log, nameof(MessageHandlerReceivedMessageServerClient) + " " + nameof(DummyMessageHandler.HandleNetworkLog));
using (var messageStream = MessagePacker.WrapMessage(NetworkConstants.SERVER_LOG, inputBuffer))
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.

This is another case where there are other conditionals we'd probably want to verify functionality for eventually (not necessarily in this PR)... if (IsServer && NetworkConfig.EnableNetworkLogs) provides at least 2 cases to consider testing.


// Should cause log (server and client)
LogAssert.Expect(LogType.Log, nameof(MessageHandlerReceivedMessageServerClient) + " " + nameof(DummyMessageHandler.HandleNetworkVariableDelta));
using (var messageStream = MessagePacker.WrapMessage(NetworkConstants.NETWORK_VARIABLE_DELTA, inputBuffer))
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.

You don't need to implement comprehensive coverage in this PR (we have other time scheduled for test debt), but consider how you validate some of the extra functionality that some of these methods have and what it might do to test case organization.
e.g. this one has a prebufferpreset - may be worth thinking about all the permutations of that which we'd want to verify functionality on. Would we want to somehow throw the permutations into this one monolith test case, or would separate test cases with separate setup stages be helpful?

public class InternalMessageHandlerTests
{
[Test]
public void MessageHandlerReceivedMessageServerClient()
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.

This is valuable and it's always nice to see test coverage added! I don't think you need to block the PR on this, but I'd encourage you to do some reading about AAA (arrange-act-assert) pattern testing and try to apply it going forward.

It takes some time to see what's being verified in this test, and how. Part of that is because it's so large (testing multiple things), but part of it is because the "assert" is happening inside of the "act".

@TwoTenPvP TwoTenPvP enabled auto-merge (squash) April 9, 2021 18:14
@TwoTenPvP TwoTenPvP disabled auto-merge April 12, 2021 08:20
}
}

internal class DummyMessageHandler : IInternalMessageHandler
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

love this addition!

@TwoTenPvP TwoTenPvP enabled auto-merge (squash) April 16, 2021 07:51
@TwoTenPvP TwoTenPvP merged commit 54a4593 into develop Apr 16, 2021
@TwoTenPvP TwoTenPvP deleted the singleton-removal-message-handler branch April 16, 2021 07:54
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.

4 participants