You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are two tests in SubscriberBlackboxVerification that verify conformance to Rule 2.3:
Subscriber.onComplete() and Subscriber.onError(Throwable t) MUST NOT call any methods on the Subscription or the Publisher.
I can see that this is done by examining the call stack, looking for the specific methods' names:
finalSubscriptionsubs = newSubscription() {
@Overridepublicvoidrequest(longn) {
Throwablethr = newThrowable();
for (StackTraceElementstackElem : thr.getStackTrace()) {
if (stackElem.getMethodName().equals("onError")) {
env.flop(String.format("Subscription::request MUST NOT be called from Subscriber::onError (Rule 2.3)! (Caller: %s::%s line %d)",
stackElem.getClassName(), stackElem.getMethodName(), stackElem.getLineNumber()));
}
}
}
@Overridepublicvoidcancel() {
Throwablethr = newThrowable();
for (StackTraceElementstackElem : thr.getStackTrace()) {
if (stackElem.getMethodName().equals("onError")) {
env.flop(String.format("Subscription::cancel MUST NOT be called from Subscriber::onError (Rule 2.3)! (Caller: %s::%s line %d)",
stackElem.getClassName(), stackElem.getMethodName(), stackElem.getLineNumber()));
}
}
}
};
It seems to do the job, however, the approach might be brittle. The reason is that approach is not specific enough. It might produce false positives as it disregards the objects on which onError and onComplete are called. A method can be similarly named, but otherwise unrelated. Or the method can be called on a different Subscriber (i.e. calling subscription1.cancel() from subscriber2.onComplete()).
Could a ThreadLocal<Boolean> flag solution be any better? Before calling onError on onComplete on Subscriber the test sets that flag. Upon exit from those methods the flag is cleared. Inside Subscription's cancel and request(long) the flag is being checked.
The text was updated successfully, but these errors were encountered:
There are two tests in
SubscriberBlackboxVerification
that verify conformance to Rule 2.3:I can see that this is done by examining the call stack, looking for the specific methods' names:
It seems to do the job, however, the approach might be brittle. The reason is that approach is not specific enough. It might produce false positives as it disregards the objects on which
onError
andonComplete
are called. A method can be similarly named, but otherwise unrelated. Or the method can be called on a differentSubscriber
(i.e. callingsubscription1.cancel()
fromsubscriber2.onComplete()
).Could a
ThreadLocal<Boolean>
flag solution be any better? Before callingonError
ononComplete
onSubscriber
the test sets that flag. Upon exit from those methods the flag is cleared. InsideSubscription
'scancel
andrequest(long)
the flag is being checked.The text was updated successfully, but these errors were encountered: