Skip to content

Comments

[feat][ci] Enable assertions when running tests in CI#19653

Closed
michaeljmarshall wants to merge 1 commit intoapache:masterfrom
michaeljmarshall:enable-assertions
Closed

[feat][ci] Enable assertions when running tests in CI#19653
michaeljmarshall wants to merge 1 commit intoapache:masterfrom
michaeljmarshall:enable-assertions

Conversation

@michaeljmarshall
Copy link
Member

Motivation

I noticed recently that Netty uses asserts to ensure that certain methods are run on the correct thread. This seems like a reasonable usage to me given that this kind of thing is hard to verify with a test and easy to verify at runtime. Here are some Netty usage references:

https://github.com/netty/netty/blob/d34212439068091bcec29a8fad4df82f0a82c638/transport/src/main/java/io/netty/channel/PendingWriteQueue.java#L68

https://github.com/netty/netty/blob/c18fc2bc68c08805b2553336a3bf02f0c8c50972/common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java#L210

https://github.com/netty/netty/blob/00905d64c817b87aa37dee1c2bc3292b874b47a6/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2LocalFlowController.java#L179

And many more that might change over time.

As such, I recently committed some assertions to the Pulsar code base:

assert ctx.executor().inEventLoop();
assert authRefreshTask == null;

If we want to use these assertions, I think we must enable them in our CI pipeline to ensure the assertions are actually verified.

Modifications

  • Update CI maven options MAVEN_OPTS to include the flag that will enable assertions for all org.apache.pulsar sub packages.

Verifying this change

I am not exactly sure how to verify this with a test, so I'll need to figure that out.

Documentation

  • doc-not-needed

I don't think we need docs yet, but if we want to make an official stance on when to use assert, maybe we should document it.

Matching PR in forked repository

This should not break tests.

Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

MAVEN_OPTS isn't used for forked test processes. The maven-surefire-plugin will run tests in a separate process.
There's no need to separately enable assertions since maven-surefire-plugin enables all assertions by default (doc).
We can close this PR since it's not needed.

@lhotari lhotari closed this Feb 28, 2023
@michaeljmarshall
Copy link
Member Author

@lhotari - great, thanks for sharing those docs.

@michaeljmarshall michaeljmarshall deleted the enable-assertions branch February 28, 2023 05:44
michaeljmarshall added a commit that referenced this pull request Mar 20, 2023
…9670)

### Motivation

The `DirectProxyHandler` and the `ProxyConnection` are run in the same event loop to prevent context switching. As such, we do not need to schedule an event onto an event loop that is in fact the same event loop. Further, scheduling on that event loop could have resulted in uncaught failures because the method was run without any error handling.

Additionally, we can use `assert` to verify that we are in the event loop. Netty makes extensive use of this paradigm, as described in this PR #19653. The primary benefit here is that we skip some unnecessary volatile reads when running the code in production.

### Modifications

* Replace `checkState` with `assert` in `ProxyConnection` class
* Remove unnecessary event execution in callback when starting up the `DirectProxyHandler`.

### Verifying this change

This change is covered by the assertions that are added.

### Does this pull request potentially affect one of the following parts:

This is a minor improvement that should not break anything.

### Documentation

- [x] `doc-not-needed`

### Matching PR in forked repository

PR in forked repository: michaeljmarshall#33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants