    @Test
    @SuppressWarnings("unchecked")
    public void streamCanceledShouldCloseOnce() throws Exception {

        initChunkedStream(smallBuff, ofAll(10), ofAll(10));

        Subscriber sub = mock(Subscriber.class);

        doAnswer(inv -> {
            Subscription s = inv.getArgument(0);
            s.request(1);
            s.cancel();
            return null;
        }).when(sub).onSubscribe(any());
        doThrow(DELIBERATE_EXCEPTION).when(sub).onNext(any());

        toSource(pub).subscribe(sub);

        verify(sub, never()).onComplete();
        verify(sub).onError(DELIBERATE_EXCEPTION);
        verify(inputStream).close();
    }