lambda-behave icon indicating copy to clipboard operation
lambda-behave copied to clipboard

Ease testing of async code/event sequences

Open RuedigerMoeller opened this issue 10 years ago • 2 comments

Existing test frameworks (afaik) are basically single threaded / require manual blocking and synchronization in order to test async code/libs.

What's needed is kind of matching event patterns like

subscribe(someStreamOrPublisher)
   .require( ev -> ev.type() == 'START' )
   .many( ev -> ev instanceof MktEvent || ev instanceof InstrAddedEvent )
   .require( ev -> ev = CLOSED )
   .await(); //blocker

(pseudo code, hope you get the idea). Ofc this only one of many concurrency/async patterns

Not that I have kind of a concept, however there is a gap in that area (async/mthreading) with most existing test frameworks.

Note: R. Kuhn has also investigated in that area, however it seems just a fragment https://github.com/rkuhn/asynctest

RuedigerMoeller avatar Jul 09 '15 22:07 RuedigerMoeller

It looks like a good idea, but without having a common type of stream or publisher its a bit hard to tell how useful it would be for people. Or did you have in mind just using RxJava to begin with?

RichardWarburton avatar Jul 09 '15 22:07 RichardWarburton

A generic threadsafe eventsink (like CLQ) to feed in events would be sufficient and could be fed from any async lib. Maybe like

EventSink sink = new EventSink() // <= test framework provided

// testcode feeds sink
... sink.event( .. );
... sink.error( throwable );
... sink.complete();

// definition of expected behaviour
sink.
    .require( ev -> ev.type() == 'START' )
   .many( ev -> ev instanceof MktEvent || ev instanceof InstrAddedEvent )
   .require( ev -> ev = CLOSED )
   .await(); //blocker

RuedigerMoeller avatar Jul 09 '15 22:07 RuedigerMoeller