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

tests: add test for item trace #735

Merged
merged 7 commits into from Apr 30, 2022
Merged

Conversation

midgleyc
Copy link
Member

@midgleyc midgleyc commented Apr 29, 2022

I changed it so you can trace any item, not just those currently in your inventory.

Item Trace had some interesting behaviour: cancelling a previous trace didn't take effect until garbage collection ran. I fixed this too.

Item Trace has some interesting behaviour: cancelling a previous trace
doesn't take effect until the audience is garbage collected. I left this
as there's no "unregisterListener" function already.
@midgleyc midgleyc requested a review from a team as a code owner April 29, 2022 19:04
@codecov
Copy link

codecov bot commented Apr 29, 2022

Codecov Report

Merging #735 (fd43727) into main (c705eac) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #735      +/-   ##
============================================
+ Coverage     23.43%   23.47%   +0.03%     
- Complexity    10439    10458      +19     
============================================
  Files          1010     1010              
  Lines        158018   158037      +19     
  Branches      34938    34941       +3     
============================================
+ Hits          37027    37092      +65     
+ Misses       114284   114236      -48     
- Partials       6707     6709       +2     
Impacted Files Coverage Δ
...eforge/kolmafia/listener/ItemListenerRegistry.java 90.00% <100.00%> (+50.00%) ⬆️
...ourceforge/kolmafia/listener/ListenerRegistry.java 56.91% <100.00%> (+3.40%) ⬆️
.../kolmafia/listener/PreferenceListenerRegistry.java 91.66% <100.00%> (+1.66%) ⬆️
...orge/kolmafia/textui/command/ItemTraceCommand.java 93.10% <100.00%> (+77.10%) ⬆️
...orge/kolmafia/textui/command/PrefTraceCommand.java 93.10% <100.00%> (+77.10%) ⬆️
...rceforge/kolmafia/persistence/HolidayDatabase.java 34.57% <0.00%> (ø)
src/net/sourceforge/kolmafia/KoLCharacter.java 45.97% <0.00%> (+0.04%) ⬆️
...sourceforge/kolmafia/session/EquipmentManager.java 23.57% <0.00%> (+0.08%) ⬆️
...t/sourceforge/kolmafia/persistence/ItemFinder.java 82.53% <0.00%> (+0.34%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c705eac...fd43727. Read the comment docs.

Veracity0
Veracity0 previously approved these changes Apr 30, 2022
Copy link
Contributor

@Veracity0 Veracity0 left a comment

Choose a reason for hiding this comment

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

I like this.

RequestLoggerOutput looks like a good simplification of the previous "custom stream" feature of RequestLogger, which I just discovered a few days ago.

And allowing Listeners to be unregistered is good new functionality. I looked at that when I wanted to created NamedListeners in my YouRobotManager test suite - for "(potions)" and "(avatar)" - and concluded I didn't need to clean them up since there was no harm if a freshly allocated Listener went out of scope and was cleaned up later - but I can easily envision a Cleanup that registers a NamedListener and unregisters it on close.

@midgleyc midgleyc merged commit b640aff into kolmafia:main Apr 30, 2022
@midgleyc midgleyc deleted the test-item-trace branch April 30, 2022 17:33
var text = RequestLoggerOutput.stopStream();
assertThat(text, containsString("ptrace: _VYKEACompanionType = couch"));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice that you are leaving the PreferenceListener active, rather than clearing it via execute("").
Intended?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was intended when I wrote it. The tests that clear it do so to test particular code paths.

But I think you're right, I should be clearing up the listeners. As it stands, whichever test runs last will leak its listeners into the remaining tests.


String output = execute("");
assertThat(output, containsString("Previously watched items have been cleared"));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This cleans up item listener at end of test.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is to cover the case where an item listener is unregistered without having been registered in the first place -- which happens if the item added has a negative id (i.e. is not a real item).

var text = RequestLoggerOutput.stopStream();
assertThat(text, containsString("itrace: hair spray = 1"));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not clean up item listener at end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants