Skip to content

Add ExprAbsorbedBlocks test #8062

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

Open
wants to merge 6 commits into
base: dev/feature
Choose a base branch
from

Conversation

F1r3w477
Copy link

Problem

The Skript project has low test coverage. The ExprAbsorbedBlocks expression, which relies on the SpongeAbsorbEvent, had no automated tests.

Solution

This PR introduces robust tests for ExprAbsorbedBlocks.

  • Tests are broken down into simple, single-block absorption scenarios for each cardinal direction.

  • Each test runs in an isolated location to prevent contamination during consecutive test runs.

  • A cleanup and teardown process is used in each test block to avoid contamination.

Testing Completed

skriptTest

Supporting Information

This test was particularly difficult to stabilize due to limitations in the test runner's parser and race conditions in the server's block update queue. The final script structure represents a robust pattern for handling asynchronous, physics-based events.


Completes: none
Related: #6158

@F1r3w477 F1r3w477 requested a review from a team as a code owner July 20, 2025 07:15
@F1r3w477 F1r3w477 requested review from cheeezburga and Burbulinis and removed request for a team July 20, 2025 07:15
@skriptlang-automation skriptlang-automation bot added the needs reviews A PR that needs additional reviews label Jul 20, 2025
@bluelhf
Copy link
Contributor

bluelhf commented Jul 20, 2025

Thanks for contributing to Skript's test coverage :) While this test is probably okay as–is, a timing-based approach is not the right solution to ensure cases don't collide.

IIRC blocks are metadata holders, so you could use a metadata tag to link a sponge block to a specific test case and check it in the event — this way the test also can't fail if an unrelated sponge happens to absorb blocks (though that is at best unlikely)

There's no need to check cardinal directions individually, just one test case that checks that the list of absorbed blocks is correct should be enough.

@F1r3w477
Copy link
Author

Thanks for the feedback and the suggestion to use metadata. It's definitely a more elegant approach in theory.

After extensive debugging, the current implementation (using physically isolated tests with timing) was the only way I could create a test that is 100% stable and correctly fails the build when an assertion is broken.

I agree it's not the most concise solution, but it provides full test coverage where none existed before. As the contributing guidelines mention, "Tests don't have to be good code - often, testing edge cases pretty much requires weird code." This seems to be one of those cases where a more direct method was needed to work around the test environment's quirks.

I'm happy to continue exploring other options if you have a specific syntax in mind that avoids the parsing errors, but for now, this version is fully functional and reliable.

@F1r3w477 F1r3w477 changed the title Add exprabsorbedblocks test Add ExprAbsorbedBlocks test Jul 20, 2025
Copy link
Contributor

@Absolutionism Absolutionism left a comment

Choose a reason for hiding this comment

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

Tests cannot have delays in them wait ... as the testing environment shouldn't be delayed:

Image

I'm also not sure about this approach for testing the event. Might need to be a JUnit test instead.

@F1r3w477
Copy link
Author

This test is unable to run without waiting. If we want there to be no waits, somewhere we will need to document that this is untestable.

@Absolutionism
Copy link
Contributor

This test is unable to run without waiting. If we want there to be no waits, somewhere we will need to document that this is untestable.

Well, in my posted screenshot, you can see the event is still being fired from the other tests as you have no delay between the start through cleaning up and setting block to water and block to sponge.
Your first test has a wait 1 second before clean up, which ends up making the rest of the code for that test not execute.

Granted, it seems that the event will be fired without having any delays. I'm not sure if using an event in a non-junit testing environment is something that should be done. Would like to see what other team members think though.

@F1r3w477
Copy link
Author

Granted, it seems that the event will be fired without having any delays. I'm not sure if using an event in a non-junit testing environment is something that should be done. Would like to see what other team members think though.

Sounds good, absorbed blocks is only accessible from within the event, so if others agree, then this is not testable in this context.

@Absolutionism Absolutionism added the enhancement Feature request, an issue about something that could be improved, or a PR improving something. label Jul 20, 2025
@sovdeeth
Copy link
Member

Why exactly are delays necessary here? I would expect the absorb event to be fired when the block is placed. Also, try to avoid changing blocks far from spawn, since it requires loading/generating new chunks and slows tests down.

@F1r3w477
Copy link
Author

F1r3w477 commented Jul 21, 2025

The assertion assert size of absorbed blocks is 1 with "Sponge should have absorbed 1 block" will intermittently read absorbed blocks as 2 if I remove waits.

My assumption is the test processes faster than the server processes the water physics changes. The test failure tends to be on consecutive test runs when using quickTest.

I can move the block setting closer to the test-location, I'll hold off on adjusting the test until we work through the concerns about waiting and using the event in the test.

Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

There doesn't need to be a test for each direction. Just picking one and using it will be fine (it's out scope for this syntax anyway). As mentioned above, waits are not possible in tests.

If you have just one test, setting some blocks to water and then setting a sponge (which will trigger the event) should be fine. I don't think a JUnit test is necessarily required (though it wouldn't require the world modification/cleanup)

@F1r3w477
Copy link
Author

The test works fine from one side if we don't wait. I updated the test to test from one side as @APickledWalrus suggested, and removed the waits.

If we need to test absorption from more than one side, I was unable to get it to work without making the test wait. As it sits now, there are no waits, we only absorb from one side, and the test takes place at test-location.

@F1r3w477 F1r3w477 requested a review from APickledWalrus July 24, 2025 20:14
@skriptlang-automation skriptlang-automation bot removed the needs reviews A PR that needs additional reviews label Jul 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants