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

test(TypeHandlerLibrary): RuntimeDelegatingTypeHandler test failure #3992

Merged
merged 19 commits into from Nov 7, 2021

Conversation

keturn
Copy link
Member

@keturn keturn commented May 25, 2020

When running tests under JDK 11, there's one engine test that fails.

o.t.persistence.typeHandling.coreTypes.RuntimeDelegatingTypeHandlerTest#testDeserializeSub

The other four test cases in RuntimeDelegatingTypeHandlerTest continue to be fine.

There were "warning: raw use of parameterized type" messages all over that test file, in trying to understand the tests, the first thing I did was clean those up.

I haven't fixed the test yet, but I did get one of the other four to fail!

The place I've ended up is here:

if (!(typeHandler instanceof ObjectFieldMapTypeHandler) &&
typeHandler.getClass().equals(delegateHandler.getClass())) {
// Both handlers are of same type and will do the same thing,
// use delegateHandler which might have more info
return delegateHandler;
}

that th.getClass().equals(dh.getClass()) is coming back true for the test's baseTypeHandler and subTypeHandler, so it uses the baseTypeHandler (as that was the one given to RuntimeDelegatingTypeHandler construction), but the test is written specifically to assert the subTypeHandler is used.

So, did I

  • uncover a bug in RuntimeDelegatingTypeHandler.serializeNonNull?
  • accidentally change (i.e. break) the semantics of the test when I changed things around to not use unparameterized types?
  • stumble on to some other type of distinction the test should be making? (e.g. does it need the subTypeHandler to be of a distinctly different class than the baseTypeHandler, not just a different instance with different type parameters).

and why were the test results different between javas 8 and 11?

I'll run some things under java 8 to see if I can find out about that, but I need input on the rest.

@keturn keturn added the Status: Needs Investigation Requires to be debugged or checked for feasibility, etc. label May 25, 2020
@keturn
Copy link
Member Author

keturn commented May 25, 2020

okay, now that test suite behaves the same way under JDK 8 and 11, which I appreciate.

The code under test looks like it was introduced in #3535, if that rings any bells.

<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="VarargParameter" enabled="false" level="INFORMATION" enabled_by_default="false" />
Copy link
Contributor

Choose a reason for hiding this comment

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

You sure?

Copy link
Member Author

Choose a reason for hiding this comment

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

Reports methods taking a variable number of arguments, also known as varargs methods. Such methods are not supported under Java 1.4 or earlier JVMs. The quickfix of this inspection replaces a variable argument parameter with the equivalent array parameter. Relevant arguments in calls to the method are wrapped in an array initializer expression.

We don't have to worry about compat with Java 1.4, so I think the only other reason to have it enabled is so that quickfix-action of replace-variable-argument-parameter-with-array shows up when you have the cursor on varargs.

we can keep it at default if that's useful, but so far I've found it to be an unhelpful suggestion.

@keturn keturn requested a review from eviltak September 20, 2020 18:41
@keturn
Copy link
Member Author

keturn commented Oct 3, 2020

EvilTak provided some comments about this today: https://discord.com/channels/270264625419911192/696830442065625118/762033934925561866

# Conflicts:
#	.idea/dictionaries/kevint.xml
#	engine-tests/build.gradle
#	subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/RuntimeDelegatingTypeHandlerTest.java
@keturn
Copy link
Member Author

keturn commented Mar 27, 2021

That was a big merge because it has been a while and all of the TypeHandlerLibrary code moved, but it seems to still apply.

# Conflicts:
#	.idea/dictionaries/kevint.xml
#	subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/RuntimeDelegatingTypeHandlerTest.java
@keturn
Copy link
Member Author

keturn commented Nov 6, 2021

@eviltak wrote:

If my hunch on how the JUnit Mockito extension works is right, then simply replacing the type of the test class constructor parameter @Mock TypeHandler<Sub> subTypeHandler with @Mock SubHandler subTypeHandler should do the trick.

No such luck. It just makes the test fail a little earlier, deserialize not returning a value at all.

Optional<Base> result = runtimeDelegatingTypeHandler.deserialize(persistedSub);
assertTrue(result.isPresent());

@keturn keturn marked this pull request as ready for review November 6, 2021 20:32
@keturn
Copy link
Member Author

keturn commented Nov 6, 2021

After stubbing out the SerializationSandbox so we're not relying on how this test case builds an instance of Reflections, and paying a bit more attention to whether we've stubbed the Type or Class<> variant of methods, I think we have tests that pass in both Java 8 and Java 11 builds. 😌

@keturn keturn added Blocker Issue reporting or PR addressing a critical problem that blocks other efforts Category: Test/QA Requests, Issues and Changes targeting tests and quality assurance and removed Status: Needs Investigation Requires to be debugged or checked for feasibility, etc. labels Nov 6, 2021
@keturn
Copy link
Member Author

keturn commented Nov 6, 2021

Java Version 11

Cervator
Cervator previously approved these changes Nov 7, 2021
Copy link
Member

@Cervator Cervator left a comment

Choose a reason for hiding this comment

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

Seems fine here, CI finally passes, huzzah! :-)

Discord chatter seemed pretty confident about this, I'm not at that level but can at least confirm I looked at it 👍

DarkWeird
DarkWeird previously approved these changes Nov 7, 2021
Copy link
Contributor

@DarkWeird DarkWeird left a comment

Choose a reason for hiding this comment

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

Looks right.
Works(i love tests)

# Conflicts:
#	subsystems/TypeHandlerLibrary/build.gradle.kts
@keturn keturn dismissed stale reviews from DarkWeird and Cervator via 913a1df November 7, 2021 15:46
@keturn
Copy link
Member Author

keturn commented Nov 7, 2021

I can't say I'm confident about this, relying as it does on mockito while involving type inspection. But it Works On My Machine, and on CI.

@keturn keturn changed the title RuntimeDelegatingTypeHandler test failure test(TypeHandlerLibrary): RuntimeDelegatingTypeHandler test failure Nov 7, 2021
@keturn keturn merged commit 4c89465 into develop Nov 7, 2021
@keturn keturn deleted the fix/java11-persists branch November 7, 2021 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker Issue reporting or PR addressing a critical problem that blocks other efforts Category: Test/QA Requests, Issues and Changes targeting tests and quality assurance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants