Skip to content

test: add NetworkObject and NetworkBehaviour EditorTests #607

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

Merged
merged 14 commits into from
Mar 29, 2021

Conversation

TwoTenPvP
Copy link
Contributor

No description provided.

@TwoTenPvP TwoTenPvP force-pushed the tests/network-object-behaviour-tests branch from 2b0dce8 to edf1696 Compare March 12, 2021 14:18
@TwoTenPvP TwoTenPvP changed the title tests: Added NetworkObject and NetworkBehaviour tests test: Added NetworkObject and NetworkBehaviour tests Mar 12, 2021
@TwoTenPvP TwoTenPvP marked this pull request as ready for review March 12, 2021 18:28
@TwoTenPvP
Copy link
Contributor Author

Expect this to fail until release/0.1.0 has been merged into develop.

@0xFA11
Copy link
Contributor

0xFA11 commented Mar 23, 2021

we recently merged release/0.1.0 back into develop — so it should no longer fail on tests :)

var networkObject = gameObject.AddComponent<NetworkObject>();

// TODO: Maybe not hardcode message?
LogAssert.Expect(LogType.Error, $"[MLAPI] Behaviour index was out of bounds. Did you mess up the order of your {nameof(NetworkBehaviour)}s?");
Copy link
Contributor

Choose a reason for hiding this comment

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

Like you, I'm not crazy about this relying on the error message in NetworkObject.cs lines up exactly with this hard-coded string. Since we already check for null below, is this just making sure we log an error message?

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 is actually not a check, but it's just saying "dont fail the test just because this error message comes through".

By default the test runner will fail if a error log is sent.

Copy link
Contributor

Choose a reason for hiding this comment

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

does the test fail due to logs here without this trick currently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

Copy link
Contributor

Choose a reason for hiding this comment

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

@TwoTenPvP now that I know the truth, I feel no better :)

var networkBehaviour = gameObject.AddComponent<EmptyNetworkBehaviour>();

// TODO: Maybe not hardcode message?
LogAssert.Expect(LogType.Error, $"[MLAPI] Behaviour index was out of bounds. Did you mess up the order of your {nameof(NetworkBehaviour)}s?");
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above


Object.DestroyImmediate(networkObject);

Assert.That(networkBehaviour.HasNetworkObject, Is.False);
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't NetworkBehaviour instance also be destroyed as part of NetworkObject/GameObject we created above after we DestroyImmediate()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No? We just remove the NetworkObject component.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh I see, then we should also destroy the main GameObject either within this test method or on [TearDown] :)

Comment on lines +33 to +38
// TODO: Do we really want to throw here?
// Future API change: return null
Assert.Throws<NullReferenceException>(() =>
{
var x = networkBehaviour.NetworkObject;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, we should probably not throw but return null there instead but obviously not in this PR

Copy link
Contributor

@mattwalsh-unity mattwalsh-unity Mar 29, 2021

Choose a reason for hiding this comment

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

I created a quick JIRA ticket so as to not rely on our tribal knowledge & likelihood we'll scan for TODOs someday

Comment on lines +46 to +51
// TODO: Do we really want to throw here?
// Future API change: return null
Assert.Throws<NullReferenceException>(() =>
{
var x = networkBehaviour.NetworkObject;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

similar to above, I wonder how safe it is to operate on a NetworkBehaviour instance after DestroyImmediate()ing the main GameObject that holds it...

Copy link
Contributor Author

@TwoTenPvP TwoTenPvP Mar 29, 2021

Choose a reason for hiding this comment

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

We don't destroy the GameObject, only the NetworkObject component.

[Test]
public void GetBehaviourIndexNone()
{
var gameObject = new GameObject(nameof(GetBehaviourIndexNone));
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we should destroy this gameObject since its scope looks super local and specific to this test.

[Test]
public void GetBehaviourIndexOne()
{
var gameObject = new GameObject(nameof(GetBehaviourIndexOne));
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto my gameobject destruction comment above.

@0xFA11 0xFA11 changed the title test: Added NetworkObject and NetworkBehaviour tests test: add NetworkObject and NetworkBehaviour EditorTests Mar 29, 2021
Copy link
Contributor

@0xFA11 0xFA11 left a comment

Choose a reason for hiding this comment

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

I'm mainly concerned about the GameObject lifecycle in these test method implementations. We should probably cleanup after tests, either within the test method with DestroyImmediate() or on [TearDown].

Also please summarize the PR in the PR description next time so that it'd guide reviewers to quickly get into the context.

@TwoTenPvP
Copy link
Contributor Author

I'm mainly concerned about the GameObject lifecycle in these test method implementations. We should probably cleanup after tests, either within the test method with DestroyImmediate() or on [TearDown].

Also please summarize the PR in the PR description next time so that I'd guide reviewers to quickly get into the context.

The test runner automatically cleans all of this up!

@0xFA11
Copy link
Contributor

0xFA11 commented Mar 29, 2021

@TwoTenPvP

The test runner automatically cleans all of this up!

my point is, cleaning-up would prevent any unexpected side-effects caused by objects left around until the editor cleans everything up for us.
looks like it wouldn't cause any side-effect here but we'd never know what happens in the future, let's make it a standard practice to clean up things ASAP after or within tests.

@TwoTenPvP
Copy link
Contributor Author

Tests now cleans up itself

@TwoTenPvP TwoTenPvP requested a review from 0xFA11 March 29, 2021 16:14
Copy link
Contributor

@0xFA11 0xFA11 left a comment

Choose a reason for hiding this comment

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

🚀

@TwoTenPvP TwoTenPvP enabled auto-merge (squash) March 29, 2021 18:03
@TwoTenPvP TwoTenPvP merged commit 350b9a2 into develop Mar 29, 2021
@TwoTenPvP TwoTenPvP deleted the tests/network-object-behaviour-tests branch March 29, 2021 21:09
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