Comments (13)
Looks good to me @bsideup, thanks!
from blockhound.
Luckily the workaround is simple enough (albeit ugly), I can just wait for 1.0.4.RELEASE.
Thanks again!
from blockhound.
Hi @wburns,
Thanks for reporting, I will look into it.
Meanwhile, could you please clarify why you need this?
When I set all threads to be dynamic
from blockhound.
Meanwhile, could you please clarify why you need this?
When I set all threads to be dynamic
That just simplifies the example. However the core problem is if the thread which installs BlockHound runs the test then it runs into this issue, from say IDEA.
from blockhound.
I understand that this is a simplification, but I wanted to know what are you trying to achieve, perhaps there is an easier way.
from blockhound.
The core of what I want to do is I am running testng and I may invoke some code that should be non blocking. However because this is invoked in the testng thread it can block for other reasons. I don't want to have to define all the exclusions for a test framework to test such things.
Now one way to fix this is to invoke the code I want to not block solely in a separate thread, but this makes the tests quite hard to write and maintain. And not to mention can run into other bugs as I have to change threads for an operation that wouldn't normally.
I saw you added dynamic test predicates in 1.0.3 and thought I could utilize that so I could mark specific blocks of code as it shouldn't block during it or even replace components with delegating wrappers to ensure the underlying method call doesn't block. But the calling code itself can still block as necessary.
For example this can be a way to define a given code, invoked in the same thread would be checked for non blocking
public static <V> V ensureNonBlocking(Supplier<V> supplier) {
isNonBlocking.set(Boolean.TRUE);
try {
return supplier.get();
} finally {
isNonBlocking.set(Boolean.FALSE);
}
}
The isNonBlocking
variable is a ThreadLocal which is checked by the non blocking thread predicate when the thread is dynamic.
I guess if you had some sort of static method in BlockHound to say ensure this code is non blocking similar to above, would work for me as well.
from blockhound.
So with a method like that I can write a delegate wrapper that allows me to make sure whenever this object is invoked that it doesn't block.
public abstract class EnsureNonBlockingStore<K, V> extends DelegatingNonBlockingStore<K, V> implements NonBlockingStore<K, V> {
protected abstract NonBlockingStore<K, V> delegate();
@Override
public CompletionStage<Void> start(InitializationContext ctx) {
return TestHelper.ensureNonBlocking(() -> delegate().start(ctx));
}
@Override
public CompletionStage<Void> stop() {
return TestHelper.ensureNonBlocking(() -> delegate().stop());
}
... ommitted rest of methods ...
}
The test code however could still be blocking, such as store.stop().toCompletableFuture().join()
.
from blockhound.
@wburns sorry, pressed wrong button 😅
Now one way to fix this is to invoke the code I want to not block solely in a separate thread, but this makes the tests quite hard to write and maintain
Since you can do it in TestHelper.ensureNonBlocking
, is it really that hard? That's the way I'd recommend.
That said, I kinda like the idea of dynamically changing the current thread's blocking status in tests, will try to fix it.
from blockhound.
Since you can do it in
TestHelper.ensureNonBlocking
, is it really that hard? That's the way I'd recommend.
Oh I am perfectly fine doing this. That isn't the problem. The problem is the dynamic predicate is evaluated with the default dynamic predicate which is false on the invoking thread because it loads a Class. The invoking thread can therefore never have dynamic predicates. Which is why I have to use the ugly workaround of spawning a thread for sole purpose of installing BlockHound.
I created #123 which should show how it could be resolved.
from blockhound.
@wburns I just submitted #124 that should solve it, please have a look
from blockhound.
@wburns thanks for having a look 💯
Once merged, it will be available as 1.0.4.BUILD-SNAPSHOT
.
Alternatively, you can use https://jitpack.io to grab it directly from the PR :)
from blockhound.
@wburns released 👍
from blockhound.
Thanks!
from blockhound.
Related Issues (20)
- BlockHound.install() fails with NPE on jdk17 if application is started as java module HOT 5
- `java.nio.channels.FileChannel` related operations are not detected as blocking
- BlockHoundIntegration.compareTo doesn't allow integrations loaded via SPI to control ordering based on initial position in stream. HOT 3
- build a skip or disable feature for individual tests HOT 2
- BlockHound does not support java 18
- Blockhound turn off and on for junit platform HOT 2
- Thread.sleep not detected HOT 2
- ClassCircularityError when using the agent with Tomcat HOT 7
- BlockHoundTestExecutionListener could not be instantiated (JDK 17) HOT 3
- unnamed module @45312be2 HOT 8
- Candidates to be included as default allowances
- Blockhound failing with new version of micrometer HOT 24
- Error using java 17 & infinispan starter HOT 4
- [Byte Buddy] ERROR reactor.core.publisher.ContextPropagation [jdk.internal.loader.ClassLoaders$AppClassLoader@266474c2, unnamed module @6c9f5c0d, Thread[mythread-1,5,main], loaded=false] HOT 5
- Bootstrap loading
- Using JDK 18 or greater makes the JVM log an issue while loading `Unsafe.park` HOT 1
- BlockHound does not flag Thread.sleep(long, int) since JDK 21 HOT 2
- Detect Synchronized Methods HOT 1
- IllegalMonitorStateException in ThreadPoolExecutor with Redisson Integration HOT 7
- Java 22 Support HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blockhound.