The length of a stream can only be known after it is closed. As long as it is not closed it's always possible that another event will be added.
https://api.dartlang.org/stable/2.1.1/dart-async/Stream/length.html
length property
Future<int> length
The number of elements in this
stream.
Waits for all elements of this stream. When this stream ends, the
returned future is completed with the number of elements.
If this stream emits an error, the returned future is completed with
that error, and processing stops.
This operation listens to this stream, and a non-broadcast stream
cannot be reused after finding its length.
test('get stream length', ()async{
BehaviorSubject<int> subject = new BehaviorSubject(seedValue: 0);
var actFuture = await subject.stream.length;
await subject.close();
expect(actFuture, completion(equals(1));
});