Comments (12)
Fair enough. What if instead of making ExecutorService configurable Awaitility just provides an option to run everything in the same thread? That would be just a boolean flag in the API.
from awaitility.
Ok so I've now implemented support for this, for example:
given().pollInSameThread().await().atMost(1000, MILLISECONDS).until(() -> fakeRepository.getValue() == 1);
You can also specify a thread factory:
with().pollThread(Thread::new).await().atMost(1000, MILLISECONDS).until(() -> fakeRepository.getValue() == 1);
or an ExecutorService
:
given().pollExecutorService(executorService).await().atMost(1000, MILLISECONDS).until(() -> threadLocalRepo.getValue() == 1);
There are static configuration options as well such as:
Awaitility.pollInSameThread();
Please try it out and let me know what you think by depending on 3.0.0-rc2
:
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>3.0.0-rc2</version>
</dependency>
from awaitility.
@btrummer Thanks for your feedback
from awaitility.
Hmm I see your point but I'm not totally convinced. It could lead to more support issues that are due to the use of a custom ExecutorService. For example what if you supplied an instance of ScheduledThreadPoolExecutor
? That could potentially mess up the way Awaitility behaves. It's also a very slim use case so I'm doubtful whether this is worth the extra complexity and expand the API.
from awaitility.
I have a similar situation in my current project now. In the past we used awaitility together with rest-assured (embedded in lambdas) which works perfectly fine. In the current project we use serenity-rest-assured now, which in fact is "plain" rest-assured plus some extra magic so the requests/responses make it into the serenity test reports. This magic however is ThreadLocal based and therefore each request we make starts breaking with a NullPointerException as soon as it is embedded within an await().until(...).
My current workaround is to have a custom "single-threaded" implementation of the awaitility DSL, with an API stripped down to the bare minimum of what we really need (only .until(lambda), and a fixed atMost() and pollInterval()).
Long story short: I don't see the necessity to hook in custom ExecutorServices. In my case, I just would like to have the possibility to switch awaitility into an "in-same-thread" polling mode, either globally or just for single await().until(...) clauses by adding a ".and().pollInSameThread()" just before the .until(), or something like that...
Thanks.
from awaitility.
I'm thinking about removing the polling thread altogether and just make Awaitility use the same thread as the test. Would this solve your issues? I'm not 100% sure that this would work, but with my current understanding I can't see why not so I hope that I can at least give it a try.
from awaitility.
It might not solve all problems, there may be situations (with thread-local et al) that the state is not visible to awaitility unless you give it another thread. So maybe the thread (and maybe event a classloader in the long run?) could be made configurable but default to the same thread as the test?
from awaitility.
Would be great for me.
IMHO the only reason to do this is to be able to enforce the "atMost" timeout in case the called condition/lambda gets stuck or hung up in an endless loop.
However, at least the use cases I have wouldn't require awaitility to do this for me. If I would have brittle conditions I'd rather fix those ;-) and/or I'd add a forced test timeout to the maven surefire/failsafe plugin config to prevent a test run from getting stuck.
from awaitility.
Ok now I remember why Awaitility uses a thread to execute the condition "poll". This is because the the condition supplied to Awaitility can exceed the "at most" time limit and Awaitility detects this and terminates the poll thread. Otherwise there's a chance that a condition might block forever.
from awaitility.
Hmm but maybe it's possible to work around this. I need some time :)
from awaitility.
I'm going to close this issue, please tell me whether I should reopen or not.
from awaitility.
Sorry for the late response.
I tried 3.0.0-rc3 and can confirm that pollInSameThread() works fine.
Fun fact: there was a recent fix in serenity, which actually fixes the NPE I mentioned above. So whether or not I use pollInSameThread(), the NPE is gone now.
However, please leave pollInSameThread() in the awaitility code, because I think it's a useful feature anyway. :-)
from awaitility.
Related Issues (20)
- `atMost` not respected if blocking method used in `until` HOT 1
- Add code examples
- atLeast/during not enforced unless until is declared HOT 2
- Feature request: Inverse await assertion HOT 3
- Support for `kotlin.time.Duration` in Kotlin DSL HOT 2
- Await AtMost Until - Never Times Out HOT 1
- Feature Request: support assertions in failFast condition HOT 5
- Dynamic reason support for fail fast feature HOT 1
- Direct support for coroutines HOT 3
- fieldIn() used with field in super class generates internal error
- Assert that a method indeed blocks for a while
- Feature proposal: ConditionFactory::messageOnFailure method HOT 1
- Add "isCompleted()" to EvaluatedCondition
- Add Support for java.util.concurrent.CountDownLatch
- await().until(() -> true) fails because the default timeout is not dynamic HOT 1
- how to migrate from 3.x to 4.x HOT 1
- Can i replace ConditionTimeoutException with Assertion error?
- Add getter for Timeout/PollDelay/PollInterval
- Lambda classes can no longer be detected using $$Lambda$
- New Clojure wrapper for Awaitility HOT 2
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 awaitility.